From: Andy L. <do...@ya...> - 2003-06-02 14:43:41
|
Here is a method I am using that I found in the Soya 3D engine (was used in the Arkanae game, I have been using it and modifying it to keep it up to date): /** * Converts an awt.image to an array of byte, with 3 color components for each pixel. * @param i the awt image * @return the image data */ protected static byte[] dataFromImageRGB(java.awt.Image i) throws InterruptedException { int width = i.getWidth (null); int height = i.getHeight(null); PixelGrabber pg = new PixelGrabber(i, 0, 0, width, height, true); pg.startGrabbing(); pg.grabPixels(); Object o = pg.getPixels(); if(o instanceof int[]) { byte[] data = new byte[width * height * 3]; int[] p = (int[]) o; int j = 0; for(int k = 0; k < width * height; k++) { data[j++] = getRed (p[k]); data[j++] = getGreen(p[k]); data[j++] = getBlue (p[k]); } return data; } return (byte[]) o; } I hope that's something you were looking for. Andy Lubbers --- Peter Ashford <kaf...@xt...> wrote: > Could anyone tell me how (or point me to code > that shows how) to create > an opengl texture using gl4java from a image.io > source (that is, an > image using the buffered image / raster > classes). > > My problem in particular is how to bridge > between what I can get from > the Raster.getPixels method (an int array) and > data that the openGL > texture creation functions are happy with. > (I'm used to doing this in > C, and dealing with the image data as an array > of unsigned bytes) > > Thanks in advance! > > > > ------------------------------------------------------- > This SF.net email is sponsored by: eBay > Get office equipment for less on eBay! > http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 > _______________________________________________ > gl4java-usergroup mailing list > gl4...@li... > https://lists.sourceforge.net/lists/listinfo/gl4java-usergroup __________________________________ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com |