Java Question: Reading pixels from a buffer
-
- DCEmu Nutter
- Posts: 964
- https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
- Joined: Sun Aug 11, 2002 5:07 pm
- Has thanked: 0
- Been thanked: 0
Java Question: Reading pixels from a buffer
Is there a way that I can get the RGB value of a pixel on a Graphics or Image buffer? I have read that the BufferedImage data type allows for this with the getRGB method, but I don't know how to load an image (gif, jpeg) with that data type.
I am trying to create a game with sprites. Blankspaces in the gif will be represented by white. I want to check for {255,255,255} white pixels. I will replace these pixels with the respective pixels from a background gif.
I am trying to create a game with sprites. Blankspaces in the gif will be represented by white. I want to check for {255,255,255} white pixels. I will replace these pixels with the respective pixels from a background gif.
-
- DCEmu Nutter
- Posts: 964
- Joined: Sun Aug 11, 2002 5:07 pm
- Has thanked: 0
- Been thanked: 0
- Ender
- DCEmu Super Poster
- Posts: 1314
- Joined: Mon Dec 10, 2001 4:01 pm
- Location: Canada, first igloo on your left.
- Has thanked: 0
- Been thanked: 0
- Contact:
okee doke. sorry bout that. have you tried getRGB?
<nevermind, I really should read...>
BufferedImage(int width, int height, int imageType) seems fairly basic to load a gif or a jpeg to me...
Looking through the java docs, I can't see anything in Image or Graphics that would allow you to do the same, though who knows, you may be able to cast the object somehow....
found this if you're interested in trying BufferedImage http://forum.java.sun.com/thread.jspa?t ... ID=1053770
<nevermind, I really should read...>
BufferedImage(int width, int height, int imageType) seems fairly basic to load a gif or a jpeg to me...
Looking through the java docs, I can't see anything in Image or Graphics that would allow you to do the same, though who knows, you may be able to cast the object somehow....
found this if you're interested in trying BufferedImage http://forum.java.sun.com/thread.jspa?t ... ID=1053770
-
- DCEmu Nutter
- Posts: 964
- Joined: Sun Aug 11, 2002 5:07 pm
- Has thanked: 0
- Been thanked: 0
I might try that, thanks.
Well its not just loading the image, the BufferedImage type can't use any of Images methods. It doesn't make sense, it is a subclass of image.
I think you also have to use a Graphics2d object for BufferedImage, so i am hoping there is another way.
EDIT: I just noticed this is for swing, I am using awt. I know swing as far as GUI stuff/textbox. I might have to make the transition to swing.
EDIT: Maybe I could draw the gif pixel by pixel? There might be a method to get a color of a specified pixel from a gif file (rather than loading to an image buffer first). I could check it, if it is not white it will be drawn to a Graphics object.
Well its not just loading the image, the BufferedImage type can't use any of Images methods. It doesn't make sense, it is a subclass of image.
I think you also have to use a Graphics2d object for BufferedImage, so i am hoping there is another way.
EDIT: I just noticed this is for swing, I am using awt. I know swing as far as GUI stuff/textbox. I might have to make the transition to swing.
EDIT: Maybe I could draw the gif pixel by pixel? There might be a method to get a color of a specified pixel from a gif file (rather than loading to an image buffer first). I could check it, if it is not white it will be drawn to a Graphics object.
-
- DCEmu Nutter
- Posts: 964
- Joined: Sun Aug 11, 2002 5:07 pm
- Has thanked: 0
- Been thanked: 0
-
- DCGen Creator
- Posts: 66
- Joined: Sat Jan 19, 2002 12:54 am
- Location: Near Yosemite, CA
- Has thanked: 0
- Been thanked: 0
- Contact:
Try this snippet of code... I have not tried it myself but it looks like what you are needing:Pyrosurfer wrote:I feel like an idiot.
I didn't know you could put transparent pixels in a gif. That'll save a bit of code. Now I just need to learn how to make my image transparent.
http://www.rgagnon.com/javadetails/java-0265.html
-
- DCEmu Nutter
- Posts: 964
- Joined: Sun Aug 11, 2002 5:07 pm
- Has thanked: 0
- Been thanked: 0
-
- DCEmu Nutter
- Posts: 964
- Joined: Sun Aug 11, 2002 5:07 pm
- Has thanked: 0
- Been thanked: 0