Hi !
Featured games (87)
games approved by the League of Dukes
Games in Showcase (669)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (727)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  access to the way image is storeded?  (Read 1479 times)
0 Members and 1 Guest are viewing this topic.
Offline Kommi

Junior Devvie

All opinions will be lined up and shot!

« Posted 2005-02-25 11:55:02 »

Ok I know that the topic is a bit vague,  but bear with me. I was wondering how can I get access to the raw data that an image is stored in on the hard drive. I am guessing that it is stored as a long list of hex values, but am prob wrong. Does anyone know exactly how the images is stored, and what the best way to access the raw data?

Offline Malohkan

Senior Devvie

while (true) System.out.println("WOO!!!!");

« Reply #1 - Posted 2005-02-25 12:10:40 »

If you have a BufferedImage image:
 byte[] data=((DataBufferByte)tex.getRaster().getDataBuffer()).getData() 

Careful though you might need:
 int[] data=((DataBufferInt)tex.getRaster().getDataBuffer()).getData() 

or you'll get a ClassCastException.  Try one, if you get the exception, try the other Grin

That'll give you the pixel data in int's or byte's directly tied to the Image's raster.

Admin and Game Developer at
Play Rimscape!    |    Play Conquer!
Offline Kommi

Junior Devvie

All opinions will be lined up and shot!

« Reply #2 - Posted 2005-02-25 12:44:37 »

great thanks.

Ok So I  dont start a new thread, a quick question on dif topic:

If I write 1 byte of data to a file, it is stored as a 4kb file in Windows. I realize this is becasue of windows file structure, and am guessing that windows cannot have a file less than 4kb. Is this correct? can I store 1 byte into a file that takes up less than 4k on my windows machine?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Valodim

Junior Devvie


« Reply #3 - Posted 2005-02-25 12:55:08 »

deends on the cluster size of your filesystem, but default is 4kb, yes.
Offline Kommi

Junior Devvie

All opinions will be lined up and shot!

« Reply #4 - Posted 2005-03-07 16:06:09 »

Ok back to the image question:

I created a 4 pixel image


when I get the byte array and display it I get the following
R  0 0 -2
B -4 0 1
G -1 0 3
G 3 -2 3

can anyone explain what this means? I was hoping to get values I can turn into binaries.

Offline tom
« Reply #5 - Posted 2005-03-07 18:03:41 »

Can you post the code, so we know what you are doing.

Offline Kommi

Junior Devvie

All opinions will be lined up and shot!

« Reply #6 - Posted 2005-03-07 19:35:54 »

File f = new File("image\\pixels.jpg");
            BufferedImage src =;
            byte[] data=((DataBufferByte)src.getRaster().getDataBuffer()).getData() ;
            for (int i = 0; i < data.length; i++)
                  System.out.print(data[i] + " ");

Offline tom
« Reply #7 - Posted 2005-03-07 22:21:29 »

You don't want to use "getRaster().getDataBuffer()).getData()" on images that are loaded from file. Atleast not if you are a newbie. The problem is that the image can be stored in so many different ways. Finding how it is stored and how to interprit it can be a hassle. It is mostly used on images that you create your self that you need speedy access too, like a software backbuffer. Since you create the image yourself, you know how the data is stored.

Use int[] BufferedImage.getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) instead. It creates a copy of the image, and it the data is always stored as argb (alphe, red, green, blue). Then you have to shift and mask to get what you want.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

IanParcs (34 views)
2016-04-18 14:18:53

KaiHH (34 views)
2016-04-18 08:35:41

KaiHH (66 views)
2016-04-15 12:43:58

theagentd (64 views)
2016-04-14 02:16:17

theagentd (72 views)
2016-04-14 02:15:43

IanParcs (66 views)
2016-04-12 03:51:16

IanParcs (35 views)
2016-04-12 03:50:03

IanParcs (32 views)
2016-04-12 03:49:54

IanParcs (27 views)
2016-04-12 03:49:52

IanParcs (36 views)
2016-04-12 03:49:52
List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!