0

Possible Duplicate:
Resize an image in Java - Any Open Source Library?

I wish I could resize the image just before recording! I tried several times but without success. Could you tell me the procedure. I would like to use imgscarlr or better. thank you

private static void getImages(String src,String Name) throws IOException {

    String folder = null;

    //Exctract the name of the image from the src attribute
    int indexname = src.lastIndexOf("/");


    if (indexname == src.length()) {
        src = src.substring(1, indexname);
    }

    indexname = src.lastIndexOf("/");
    String name = src.substring(indexname, src.length());

    System.out.println(name);

    //Open a URL Stream
    URL url = new URL(src);
    InputStream in = url.openStream();

    OutputStream out = new BufferedOutputStream(new FileOutputStream( folderPath+ name));

    for (int b; (b = in.read()) != -1;) {

        out.write(b);
    }


  BufferedImage originalImage = ImageIO.read(new File(folderPath+name));
    BufferedImage scaledImage = Scalr.resize(originalImage, 200);
    ImageIO.write(scaledImage, "jpg", new File(folderPath+name));
    }
    }

I'ts ok but according to the pictures, I have a problem with sampling the gray part !!!

Community
  • 1
  • 1
Rosebud
  • 3
  • 1
  • 5
  • 1
    Could you please post only the code that deals with the image? All the file handling is not important. –  Jul 24 '12 at 09:13
  • BTW - DYM [imgscalr](http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/) (only one 'r')? – Andrew Thompson Jul 24 '12 at 09:59
  • error-->Exception in thread "main" java.lang.ExceptionInInitializerError at DownloadImages.getImages(DownloadImages.java:145) at DownloadImages.main(DownloadImages.java:83) Caused by: java.lang.IllegalArgumentException: Can't load standard profile: GRAY.pf at java.awt.color.ICC_Profile$2.run(ICC_Profile.java:931) at java.security.AccessController.doPrivileged(Native Method) at java.awt.color.ICC_Profile.getStandardProfile(ICC_Profile.java:924) at java.awt.color.ICC_Profile.getDeferredInstance(ICC_Profile.java:1071) – Rosebud Jul 24 '12 at 13:31

2 Answers2

2

You'd need to "load" the image first, take a look at ImageIO API for more details, after that, depending on your needs, it's relatively simple to scale the image

UPDATE

Reading image from URL

Image scaling API

Multi-step, hi-quality scaling

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • 1
    *"it's relatively simple to scale the image"* Not really 'easy' for an animated GIF. – Andrew Thompson Jul 24 '12 at 09:25
  • thank you for your reply, could you give me an example of my code for me to understand the process – Rosebud Jul 24 '12 at 09:26
  • @AndrewThompson everything is relative ;), what you and I find relatively simple, others would find relatively hard...besides, you uses animated GIFs these days ;P (everybodies a critic today +1 for keeping me on my toes) – MadProgrammer Jul 24 '12 at 09:53
  • I was about to add a wink to my first comment, but resisted. ;) (..OK, I feel better now.) – Andrew Thompson Jul 24 '12 at 09:56
0

I had forget out.close(); now it's work

Rosebud
  • 3
  • 1
  • 5