Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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 1000 times)
0 Members and 1 Guest are viewing this topic.
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Posted 2005-02-25 12: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?

Kommi
Offline Malohkan

Senior Member




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


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

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

Careful though you might need:
1  
 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
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #2 - Posted 2005-02-25 13: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?


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

Junior Member




*sigh*


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

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

Junior Member




All opinions will be lined up and shot!


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

Ok back to the image question:

I created a 4 pixel image

R B
G G

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.

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

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

Offline Kommi

Junior Member




All opinions will be lined up and shot!


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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
File f = new File("image\\pixels.jpg");
            BufferedImage src = javax.imageio.ImageIO.read(f);
     
           
           
            byte[] data=((DataBufferByte)src.getRaster().getDataBuffer()).getData() ;
           
           
            for (int i = 0; i < data.length; i++)
            {
                  System.out.print(data[i] + " ");
            }
           

Kommi
Offline tom
« Reply #7 - Posted 2005-03-07 23: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (18 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!