Results 1 to 4 of 4

Thread: scaling image

  1. #1
    OmerHalit is offline Member
    Join Date
    Mar 2010
    Posts
    41
    Rep Power
    0

    Default scaling image

    hi,

    i need to print a page which contains a picture. Well, everything working correct but i am missing one thing.

    I am scaling an image that will fit an A4 size paper. and the next line, i am bringing up the print dialog screen. but the problem is, when the dialog screen appears, it causes the scaling process stop, and when i say print, the picture doesnt appear.

    but when i do the scale image with another button(just to test) and wait around 2-3 seconds, and then when i print the page, it's ok.

    i need to check the status of the scaling process before i bring up the print dialog but i couldnt manage it..

    here is my code

    Java Code:
    Map4Print = ScaleImage(findPath.bufferResim, 500,500); //the picture that i want to print.
    
            PrinterJob job = PrinterJob.getPrinterJob();
    
            job.setPrintable(new newprintjob());
            boolean doPrint = job.printDialog();
            if (doPrint) {
                try {
                    job.print();
                    ShowDialogBox("Print","Printing is in proccess. Please wait for a while.",JOptionPane.INFORMATION_MESSAGE);
                } catch (PrinterException e) {
                    ShowDialogBox("Print Error",e.getMessage(),JOptionPane.WARNING_MESSAGE);
                }
            }
    is there a way that i can check the status of "scaling" process. i was thinking maybe when i say
    Java Code:
    Image original = resim;
              bufferResim = original.getScaledInstance(targetComponent.getWidth(), targetComponent.getHeight(), Image.SCALE_FAST);
    System.out.println(bufferResim);
    it would give me null coz it's not scaled yet, but it does give me the address.. :o

    thanks :)

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    Quote Originally Posted by OmerHalit View Post
    hi,

    give me the address.. :o

    thanks :)
    You mean direction? :rolleyes:

    Well you can simply redraw your image with new params ...

    Java Code:
    public void paintComponent(Graphics g){
    g.drawImage(...,new_width,new_height,...);
    }
    And not to miss its scale use some coefficient value like a

    Java Code:
    int new_width=width+(width*100/coeff);
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  3. #3
    OmerHalit is offline Member
    Join Date
    Mar 2010
    Posts
    41
    Rep Power
    0

    Default

    thanks for the reply..

    well, you know if we don't initialize any variable, it would return "null". So i was thinking that my image variable could return null too if the scale proccess doesnt end. so i could make a check like

    while the variable is null, wait for it to be assigned value... something like that. but it doesnt, so never mind it..

    it's just i need to wait between two lines for my scale proccess to be completed. but while waiting, the app should be scaling the image instead of just waiting..
    Last edited by OmerHalit; 05-07-2010 at 01:47 AM.

  4. #4
    OmerHalit is offline Member
    Join Date
    Mar 2010
    Posts
    41
    Rep Power
    0

    Default

    well, i got my answer with my trials :)

    let me share with you too..

    i have noticed that if the image is not scaled yet, the getheight method would being -1.

    so, i made i check like this
    Java Code:
    Image original = resim;
            PrintableMap = original.getScaledInstance(450, 450, Image.SCALE_SMOOTH);
            int i = -1;
            do{
                System.out.println(++i);
                System.out.println(PrintableMap.getHeight(this));
            }
            while(PrintableMap.getHeight(this) == -1);
    the value of variable i will change. i got 65 for the first click and 19 for the third click.. it worked well.. (so far :D )

Similar Threads

  1. Replies: 16
    Last Post: 01-04-2010, 07:34 PM
  2. Scaling a JPEG
    By ScottVal in forum Advanced Java
    Replies: 5
    Last Post: 03-21-2009, 09:47 PM
  3. Scaling-ache and mouse dragging
    By willemjav in forum Java Applets
    Replies: 19
    Last Post: 07-19-2008, 01:17 AM
  4. scaling images
    By willemjav in forum Java Applets
    Replies: 7
    Last Post: 06-19-2008, 10:54 AM
  5. Replies: 0
    Last Post: 01-08-2008, 06:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •