Results 1 to 11 of 11
  1. #1
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default Fastest and most CPU efficient way to grab pixel information from a BufferedImage

    The current method i'm using right now is getting the Raster from my BufferedImage, then using loops to grab and store pixel information. Problem is, myRaster.getPixel(...) is too slow (it takes 200-300ms to grab/store a 500x300 BufferedImage) Is there any other known way that is faster then this method? Thanks! =D.

    P.S: i won't settle with 200-300ms load time, don't ask why! =D

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    What about one of the getRGB() methods?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    I am aware of that method, but i dont want return values that look like -10384729, but preferably like (3,55,55)

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    Quote Originally Posted by crikey View Post
    I am aware of that method, but i dont want return values that look like -10384729, but preferably like (3,55,55)
    Well then, why don't you just do the conversion?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    oh yeah duh! But how much faster is this method?

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    Quote Originally Posted by crikey View Post
    oh yeah duh! But how much faster is this method?
    Not sure, but it shouldn't take too long for you to throw something together and tell us. :p
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    it is 5ms less :)
    Is that the only method to make it faster, because 5ms less isn't a whole lot.

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    Quote Originally Posted by crikey View Post
    it is 5ms less :)
    Is that the only method to make it faster, because 5ms less isn't a whole lot.
    I'm not sure. But you might want to ask yourself, do you really need it to be that much faster? Maybe you could do something like doing the work on a different Thread, or using a SwingWorker, or even just a displaying a JProgressBar.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    How much of a performance hit will creating a new Thread create?
    That is, if it scans the image constantly (I will also be embedding OCR)
    Last edited by crikey; 07-07-2011 at 07:29 PM.

  10. #10
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    Quote Originally Posted by crikey View Post
    How much of a performance hit will creating a new Thread create?
    That is, if it scans the image constantly (I will also be embedding OCR)
    You aren't really asking a question I can answer. I have no idea what you're actually doing, so I have no idea what kind of an impact it will have, or what kinds of impacts you care about or are even talking about. It's almost definitely better for you to just try it out, and let us know how it goes.

    That being said, one basic mistake people make pretty often is to do work on the EDT, which freezes up the GUI. Don't do that.

    If you want further help, you should provide an SSCCE that demonstrates what you're actually doing- in as few lines as possible, so boil it down to the bare essentials.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    it is 5ms less :)
    Just checking... but you did try the version of getRGB() that avoids the loop, right?

    The int values returned in the array contain all the pixel information that you might use for further calculation. A formatted version like (3,55,55) would only be an advantage for a human reader (who isn't really going to care if it takes 300ms or 30ms to appear).

Similar Threads

  1. Scanning Image Pixel by Pixel
    By the_transltr in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2012, 04:01 PM
  2. Replies: 8
    Last Post: 06-08-2011, 02:36 PM
  3. BufferedImage - greyscale - color information
    By AndreB in forum Advanced Java
    Replies: 8
    Last Post: 03-04-2010, 10:09 AM
  4. compare two images pixel by pixel
    By java_bond in forum Advanced Java
    Replies: 6
    Last Post: 03-02-2010, 11:27 AM
  5. grab the textfile
    By Sticks_ll in forum New To Java
    Replies: 3
    Last Post: 03-31-2009, 01:23 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
  •