2013-07-17 2 views
0

일부 이미지 (.jpg)와 소스 파일의 텍스트를 읽고 단일 PDF로 어셈블하는 프로그램에서 작업하고 있습니다. 프로세싱을하는 것이 아마도 최선의 언어는 아니지만 처리 방법을 알고있는 유일한 방법입니다. 어쨌든 처리 과정에서 두 번 호출되는 문제가 있습니다. 이 문제는 size()가 셋업의 첫 번째 라인 일 때 해결되는 것을 보았습니다.하지만 모든 데이터를 읽고 저장해야하며, 가장 넓은 이미지의 너비를 찾은 다음 그럴 수 없습니다. 창문이 얼마나 넓고 높이가 나는지 결정하기 전에 텍스트가 하나 이상인 이미지를 두 개 이상 넣을 수있을 정도로 키가 큰 지 확인하십시오. 두 번 설정을 호출하지 않고 모든 정보를 얻을 수 있도록 코드를 구조화 할 수있는 방법에 대한 제안을 찾고 있는데, 이는 내 PDF에 모든 데이터의 두 복사본이 포함되어 있기 때문입니다. 누군가에게 도움이된다면 설치 프로그램을 포함 시켰습니다. 감사!void setup()을 두 번 호출하고 처리해야합니다.

void setup(){ 
    font = loadFont("TimesNewRomanPSMT-20.vlw"); 
    File clientsFolder = new File("C:/Users/[my name]/Documents/Processing/ExerciseProgram/Clients"); 
    clients = clientsFolder.listFiles(); 
    for(File x : clients){ 
    println(x.getName()); 
    } 
    //test files to see if they end in .txt, and have a matching .pdf extension that is newer 
    String nextClient = needPdf(); 

    File nextClientData = new File("C:/Users/[my name]/Documents/Processing/ExerciseProgram/Clients/" + nextClient); 
    //println(nextClientData.getName()); 

    //open the file for reading 
    //setup can't throw the exception, and it needs it, so this should take care of it 
    try{ 
    Scanner scan = new Scanner(nextClientData); 

    while(scan.hasNextLine()){ 
     exercises.add(scan.nextLine()); 
    } 
    //println(exercises.toString()); 
    printedData = new Exercise[exercises.size()]; 
    println(exercises.size()); 
    for(int i = 0; i < exercises.size(); i++){ 
     printedData[i] = new Exercise((String)exercises.get(i)); 
    } 

    //count the width and height 
    int w = 0, h = 0; 
    for(Exercise e: printedData){ 
     if(e.getWidest() > w){ 
     w = e.getWidest(); 
     } 
     if(e.getTallest() > h){ 
     h = e.getHeight(); 
     } 
    } 

    //and finally we can create the freaking window 
    //           this cuts the .txt off 
    size(w, h, PDF, "C:/Users/[my name]/Desktop/" + nextClient.substring(0, nextClient.length() - 4) + ".pdf"); 

    }catch (FileNotFoundException e){ 
    println("Unknown error in PApplet.setup(). Exiting."); 
    println(e.getMessage()); 
    exit(); 
    } 
} 
+0

사용중인 언어로 질문에 태그를 답장하십시오. – Chris

+0

나는 그 태그를 처리했다. – user2309865

답변

1

아마도 계산이 완료된 후에 창 크기를 조정할 수 있습니까? 내가 크기 조정이 어떻게 작동하는지 보려면이 스케치를 만든 후에는 ... 그것은 당신을 도울 수 있는지, 이미지 파일을 기대하고있다

모든 기능을 이동에 대한 설치하기 전에 수행하는 방법
//no error handling for non image files! 

PImage img; 
int newCanvasWidth = MIN_WINDOW_WIDTH; // made global to use in draw 
int newCanvasHeight = MIN_WINDOW_HEIGHT; 


java.awt.Insets insets; //"An Insets object is a representation of the borders of a container" 
         //from http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Insets.html 

void setup() 
{ 
    size(200, 200); // always first line 
    frame.pack();   insets = frame.getInsets(); 
    frame.setResizable(true); 

     /// for debuging, system depende`nt, at least screen is... 
    print("MIN_WINDOW_WIDTH = " + MIN_WINDOW_WIDTH); 
    print(" MIN_WINDOW_HEIGHT = " + MIN_WINDOW_HEIGHT); 
    print(" screenWidth = " + displayWidth); 
    println(" screenHeight = " + displayHeight); 
} 


void draw() 
{ 
    if (img != null) 
    { 

    image(img, 0, 0, newCanvasWidth, newCanvasHeight); 
    } 
} 

void getImageAndResize(File selected) 
{ 
    String path = selected.getAbsolutePath(); 

    if (path == null) 
    { 
    println ("nono :-|"); 
    } 
    else 
    { 

    img = loadImage(path); 

     // a temp variable for readability 
    int widthInsets =insets.left + insets.right; 
    int heightInsets =insets.top + insets.bottom; 

     // constrain values between screen size and minimum window size 
    int newFrameWidth = constrain(img.width + widthInsets, MIN_WINDOW_WIDTH, displayWidth); 
    int newFrameHeight = constrain(img.height + heightInsets, MIN_WINDOW_HEIGHT, displayHeight -20); 

     // Canvas should consider insets for constraining? I think so... 
    newCanvasWidth = constrain(img.width, MIN_WINDOW_WIDTH - widthInsets, displayWidth - widthInsets); 
    newCanvasHeight = constrain(img.height, MIN_WINDOW_HEIGHT - heightInsets, displayHeight -20 - heightInsets); 


     // set canvas size to img size WITHOUT INSETS 
    setSize(newCanvasWidth, newCanvasHeight); 

     // set frame size to image + Insets size 
    frame.setSize(newFrameWidth, newFrameHeight); 


     //// for debuging 
    println(path); 
    println(" "); 
    print("imgW  = " + img.width); 
    println(" imgH  = " + img.height); 
    print("width+ins = " + widthInsets); 
    println("  height+ins = " + heightInsets); 
    print("nFrameW = " + newFrameWidth); 
    println(" nFrameH = " + newFrameHeight); 
    print("nCanvasw = " + newCanvasWidth); 
    println(" nCanvsH = " + newCanvasHeight); 
    println(" ------ "); 
    } 

} 


void mouseClicked() 
{ 
    img = null; 

    selectInput("select an image", "getImageAndResize"); 
} 
3

()?

int i = beforeSetup(); 
int szX,szY; 

int beforeSetup() { 
    println("look! I am happening before setup()!!"); 
    szX = 800; 
    szY = 600; 
    return 0; 
} 
void setup() { 
    size(szX,szY); 
    println("awww"); 
} 

당신은 본질적으로 모든 실행하는 해킹으로 내가하는 int 채우기 위해 함수를 호출 : 처리가 보통은 "정적 및 활성 모드를 혼합"하는 불평하지만,이 해킹 처리 2.0.1에서 작동하는 것 같다 원하는 기능을 수행해야하기 때문에 창 크기를 설정하기 전에 원하는 것을 계산해야합니다.

+0

큰 해킹! 이 기능은 IDE 외부에서 작동합니까? –