}
public static ImageData createImageData( RenderedImage image, boolean transparent ) {
AWTSWTImageUtils.checkAccess();
ImageData swtdata = null;
int width = image.getWidth();
int height = image.getHeight();
PaletteData palette;
int depth;
depth = 24;
palette = new PaletteData(0xFF, 0xFF00, 0xFF0000);
swtdata = new ImageData(width, height, depth, palette);
Raster raster = image.getData();
int numbands = raster.getNumBands();
int[] awtdata = raster.getPixels(0, 0, width, height, new int[width * height * numbands]);
int step = swtdata.depth / 8;
byte[] data = swtdata.data;
swtdata.transparentPixel = -1;
int baseindex = 0;
for( int y = 0; y < height; y++ ) {
int idx = ((0 + y) * swtdata.bytesPerLine) + (0 * step);
for( int x = 0; x < width; x++ ) {
int pixel = (x + (y * width));
baseindex = pixel * numbands;
data[idx++] = (byte) awtdata[baseindex + 2];
data[idx++] = (byte) awtdata[baseindex + 1];
data[idx++] = (byte) awtdata[baseindex];
if (numbands == 4 && transparent) {
swtdata.setAlpha(x, y, awtdata[baseindex + 3]);
}
}
}
return swtdata;
}