Results 1 to 10 of 10
  1. #1
    faraa is offline Member
    Join Date
    Mar 2013
    Posts
    70
    Rep Power
    0

    Default image to bufferedImage

    Hi
    How can I convert Image to Bufferdimage
    I want to split Image and get it in arrey.
    or Is there any way to split an Image and putting it in arrey without using bufferedImage?
    Thank's in advance...


    Java Code:
     Image img = getImage(getDocumentBase(), "img1.jpg");

  2. #2
    angstrem is offline Member
    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0

    Default Re: image to bufferedImage

    You can create a new BufferedImage and simply draw the existing Image onto it.

  3. #3
    faraa is offline Member
    Join Date
    Mar 2013
    Posts
    70
    Rep Power
    0

    Default Re: image to bufferedImage

    Thank you so much.
    I do that.But it doesn't display on screen
    Why?
    Thank you again...

    This is my code:
    public BufferedImage[] split (BufferedImage imgs , int n){
    BufferedImage bimg[] = new BufferedImage[n*n] ;

    int w = imgs.getHeight()/n;
    int h = imgs.getWidth()/n;
    int num = 0;

    for(int y = 0; y < n; y++) {
    for(int x = 0; x < n; x++) {
    bimg[num] = new BufferedImage(w, h, imgs.getType());
    // Tell the graphics to draw only one block of the image
    Graphics2D g = bimg[num].createGraphics();
    g.drawImage(img, 0, 0, w, h, w*x, h*y, w*x+w, h*y+h, null);
    g.dispose();
    num++;
    }
    }
    return bimg;
    }

  4. #4
    angstrem is offline Member
    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0

    Default Re: image to bufferedImage

    Please, post your code, which is intended to draw that array onto screen.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: image to bufferedImage

    You can use ImageIO#read(URL) which directly returns a BufferedImage. For splitting an image, there's getSubimage(...). Note what it says in the API for that method.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    faraa is offline Member
    Join Date
    Mar 2013
    Posts
    70
    Rep Power
    0

    Default Re: image to bufferedImage

    Quote Originally Posted by DarrylBurke View Post
    You can use ImageIO#read(URL) which directly returns a BufferedImage. For splitting an image, there's getSubimage(...). Note what it says in the API for that method.

    db
    I used it too but I had many problem.beacause It was just one of the methods in my program and I had problem for calling that after " adding throws clause for java.io.IOEXCEPTION"
    and if I use of that ,Can I put splitted pictures in one arrey ?

  7. #7
    faraa is offline Member
    Join Date
    Mar 2013
    Posts
    70
    Rep Power
    0

    Default Re: image to bufferedImage

    Quote Originally Posted by angstrem View Post
    Please, post your code, which is intended to draw that array onto screen.
    Thank you for your helping but my code is very long and I can't put it here
    Thank you again...

  8. #8
    angstrem is offline Member
    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0

    Default Re: image to bufferedImage

    You can show me it via PM, if you want, I'll have a look. Just describe precisely, what's it intended to do and wrap it into <code=java></code> (replace triangle brackets to square ones) in order for it to be readable.

  9. #9
    faraa is offline Member
    Join Date
    Mar 2013
    Posts
    70
    Rep Power
    0

    Default Re: image to bufferedImage

    Quote Originally Posted by angstrem View Post
    You can show me it via PM, if you want, I'll have a look. Just describe precisely, what's it intended to do and wrap it into <code=java></code> (replace triangle brackets to square ones) in order for it to be readable.

    Thank you
    please check your Inbox

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: image to bufferedImage

    Quote Originally Posted by angstrem View Post
    You can show me it via PM
    That's against the spirit and purpose of a forum, which is to share problems and their possible solutions. Please don't make this kind of offer again.

    @faraa: Almost any problem can be reproduced in the form of a SSCCE (Short, Self Contained, Correct (Compilable), Example), and posting a SSCCE pretty much guarantees a solution wil be in the offing.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. GrayFilter on BufferedImage and image questions
    By Pojahn_M in forum New To Java
    Replies: 1
    Last Post: 11-16-2011, 11:48 PM
  2. Conversion from BufferedImage to SWT Image
    By Jonah Bron in forum New To Java
    Replies: 1
    Last Post: 06-27-2011, 02:40 AM
  3. Replies: 4
    Last Post: 03-23-2010, 03:46 PM
  4. read image without bufferedimage
    By mr_empty in forum Java 2D
    Replies: 5
    Last Post: 12-23-2009, 03:59 AM
  5. Replies: 0
    Last Post: 07-02-2008, 08:06 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
  •