Results 1 to 5 of 5
  1. #1
    Aboogesnickle is offline Member
    Join Date
    Jun 2014
    Posts
    12
    Rep Power
    0

    Default BufferedImage or pixel arrays

    I am making a 2d game engine and i was wonder is it better to use BufferedImages and subImages to store/render sprites from sprite sheets or use BufferedImages and store it in a pixel array and then manipulate the pixel array to do what you want.

    Basically is loading in BufferedImage and getting the tile of the sprite sheet with subImages better than loading in a BufferedImage and then putting the data in a pixel array and making a new array with the part of the BufferedImage you want.

    I do not know if there is much of a difference but from what i have been told the BufferedImage and subImage use more of the graphics card and the pixel array method uses more of the processor.

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,804
    Rep Power
    5

    Default Re: BufferedImage or pixel arrays

    BufferedImages are stored in a writable raster which is basically a collection of pixels in an array or buffer of some type. I don't know how you would be doing it differently. I have never had a performance problem with my image processing using buffered images. Also, it looks like you are talking about loading the images initially which should be trivial. So out of curiosity, where did you "learn" about the processor vs graphics card phenomena and if we told you something differently, who would believe and why?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Aboogesnickle is offline Member
    Join Date
    Jun 2014
    Posts
    12
    Rep Power
    0

    Default Re: BufferedImage or pixel arrays

    Quote Originally Posted by jim829 View Post
    BufferedImages are stored in a writable raster which is basically a collection of pixels in an array or buffer of some type. I don't know how you would be doing it differently. I have never had a performance problem with my image processing using buffered images. Also, it looks like you are talking about loading the images initially which should be trivial. So out of curiosity, where did you "learn" about the processor vs graphics card phenomena and if we told you something differently, who would believe and why?

    Regards,
    Jim
    The first method loads a BufferedImage then uses

    private int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();

    to set it to a pixel array and then change the pixel array however you need it. You set everything to pixels arrays and add them to the first pixel array.

    the other method uses multiple BufferedImages and renders them to the screen as you need them.

    basically is it better to have many BufferedImages or many pixel arrays.

    The thing about graphics card and processor cards was told to me by a classmate, and he is one of those guys that will tell you something just to look intelligent instead of actually being right.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default Re: BufferedImage or pixel arrays

    The Raster underlying the BufferedImage holds a DataBuffer (as jim says) of the relevant type based on the type of image (see the BufferedImage static values). So the buffer would be of ints, bytes, floats, whatever.
    Now, in order to get your code to work in the same sort of way without losing any information about the image you would need to do the same thing, otherwise your code would invariably be less capable than the code supplied with the JDK.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,149
    Rep Power
    6

    Default Re: BufferedImage or pixel arrays

    I just want to note one thing: as soon as you directly address the raster of an image Java2D will never ever again optimize it (keep it in video memory), it will always be tanked from regular CPU memory to video memory to draw it.

    That may or may not be something to take care with. If you do it with thousands of sprites it may not be a good idea.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Display pixel value
    By xperia2995 in forum New To Java
    Replies: 1
    Last Post: 06-10-2013, 03:45 PM
  2. Scanning Image Pixel by Pixel
    By the_transltr in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2012, 05:01 PM
  3. Replies: 10
    Last Post: 07-08-2011, 09:21 AM
  4. Pixel Data..
    By programmer_007 in forum Java 2D
    Replies: 3
    Last Post: 03-03-2010, 11:39 PM
  5. compare two images pixel by pixel
    By java_bond in forum Advanced Java
    Replies: 6
    Last Post: 03-02-2010, 12:27 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
  •