Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (755)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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  
  ByteBuffer into BufferedImage  (Read 5176 times)
0 Members and 1 Guest are viewing this topic.
Offline cborders

Junior Devvie





« Posted 2006-03-02 21:11:31 »

I am reading a binary file and I need to take the data and put it into a BufferedImage so I can display it.  It seems like I should know how to do this, but I can't think of it!  Anyone able to help?
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #1 - Posted 2006-03-02 21:32:59 »

Well, there are many ways to do something like that. You can use MemoryImageSource, or BufferedImage's setRaster or setRGB methods.

You can find usable snippets in this thread:
http://www.java-gaming.org/forums/index.php?topic=12484.0

弾幕 ☆ @mahonnaiseblog
Offline cborders

Junior Devvie





« Reply #2 - Posted 2006-03-03 17:51:15 »

Ok, I am having a heck of a time with this!  What I have are gray scale images that have either 16bpp or 32bpp.  When I wrtie them out to a file, Photoshop can read them as raw images, but I still can't figure out how to get them into a buffered image.  The setRGB() takes an integer array as an argument, so I can't figure out how to use the 16bpp images there and when I use the 32bpp images they show up as just black!  Here is the code that I am using:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
// Write RAW image format
rasterData.rewind();
while(rasterData.hasRemaining())
{
    output.write(rasterData.get());
}
output.close();
           
// Create BufferedImage
BufferedImage image = null;
if(!bit16)
{
    int[] rasterArray = new int[rasterData.capacity()/4];
    count = 0;
    while(rasterData.hasRemaining())
    {
        rasterArray[count] = rasterData.getInt();
    }
    image = new BufferedImage(cols, rows, BufferedImage.TYPE_USHORT_565_RGB);
    image.setRGB(0, 0, cols, rows, rasterArray, 0, cols);
}
           
JFrame previewFrame = new JFrame("Image Preview");
previewFrame.setSize(cols, rows);
previewFrame.setVisible(true);
previewFrame.getContentPane().getGraphics().drawImage(image, 0, 0, null);


and I have attached one of the 16bpp images and one of the 32bpp images in a rar file.  I had to rename it as .txt so just change it back to .rar

-=EDIT=-
I uploaded the wrong file initially.  It's fixed now.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2006-03-04 02:53:26 »

The first question you need to ask is, what is the format the data is in?

You say "raw" but what does that really mean?  I assume it has somethign other then pixel data in it so that you know things like width and height.

What is actual format of the pixels?  Is it a simple grid or isit compressed or otherwise organzized?

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
  ignore  |  Print  
 
 

 
DesertCoockie (36 views)
2018-05-13 18:23:11

nelsongames (82 views)
2018-04-24 18:15:36

nelsongames (74 views)
2018-04-24 18:14:32

ivj94 (755 views)
2018-03-24 14:47:39

ivj94 (85 views)
2018-03-24 14:46:31

ivj94 (626 views)
2018-03-24 14:43:53

Solater (101 views)
2018-03-17 05:04:08

nelsongames (182 views)
2018-03-05 17:56:34

Gornova (408 views)
2018-03-02 22:15:33

buddyBro (1068 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!