Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  displaying from a ByteBuffer  (Read 904 times)
0 Members and 1 Guest are viewing this topic.
Offline deepthought

Full Member
**

Posts: 212
Medals: 1



« on: 2011-11-27 12:32:17 »

i have some native code, which produces a bytebuffer with a raw 24 bit image.
what steps should i take to display this image?

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline ra4king

JGO Kernel
*****

Posts: 3153
Medals: 196


I'm the King!


« Reply #1 on: 2011-11-27 16:18:54 »

Create a BufferedImage and manually set each pixel.

Online CaptainJester

JGO Neuromancer
****

Posts: 1138
Medals: 8


Make it work; make it better.


« Reply #2 on: 2011-11-28 06:26:50 »

1  
2  
BufferedImage img = new BufferedImage(800, 600, BufferedImage.TYPE_3BYTE_BGR);
img.getRaster().setDataElements(0, 0, 800, 600, imageData);

Games published by our own members! Go get 'em!
Offline counterp

Full Member
**

Posts: 235
Medals: 11



« Reply #3 on: 2011-11-28 07:27:05 »

I don't think you can pass a ByteBuffer along as an argument there (someone correct me?)

What I would do is use array() to get the backing buffer and work from there
Offline Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5866
Medals: 255


Hand over your head.


« Reply #4 on: 2011-11-28 08:22:58 »

I don't think you can pass a ByteBuffer along as an argument there (someone correct me?)

What I would do is use array() to get the backing buffer and work from there
deepthought said he got the ByteBuffer from native code, so it's a direct ByteBuffer. .array() won't work there.

You have to copy the contents of the ByteBuffer into an array manually, using byteBuffer.get(byte[])

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline ra4king

JGO Kernel
*****

Posts: 3153
Medals: 196


I'm the King!


« Reply #5 on: 2011-11-28 11:55:52 »

The argument is of type Object. The JavaDocs say that it should be an array of the type returned by Raster.getTransferType().

Offline deepthought

Full Member
**

Posts: 212
Medals: 1



« Reply #6 on: 2011-11-28 15:28:18 »

Quote
BufferedImage img = new BufferedImage(800, 600, BufferedImage.TYPE_3BYTE_BGR);
img.getRaster().setDataElements(0, 0, 800, 600, imageData);

that works. and there i was arsing around with MemoryImageSources

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline ra4king

JGO Kernel
*****

Posts: 3153
Medals: 196


I'm the King!


« Reply #7 on: 2011-11-28 20:05:19 »

What type is your imageData?

Offline deepthought

Full Member
**

Posts: 212
Medals: 1



« Reply #8 on: 2011-11-29 08:22:39 »

3 byte RGB. the native code could just be rewritten to use BGR.
just wondering, is there any way to make a 3 byte RGB colormodel?

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline ra4king

JGO Kernel
*****

Posts: 3153
Medals: 196


I'm the King!


« Reply #9 on: 2011-11-29 17:45:58 »

I meant what type of array?

Games published by our own members! Go get 'em!
Offline deepthought

Full Member
**

Posts: 212
Medals: 1



« Reply #10 on: 2011-11-30 11:02:45 »

byte

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.38 seconds with 20 queries.