[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Direct text rendering to an image

Found the solution to the problem. Here is the conversion from SWT Image to Swing BufferedImage from org/eclipse/swt/internal/image/PngEncoder.java (EPL):

int[] lineData = new int[SIZE];
for (int y = 0; y < SIZE; y++) {
	imageData.getPixels(0, y, SIZE, lineData, 0);
	// Analyze each pixel value in the line
	for (int x = 0; x < lineData.length; x++) {
		// Extract the red, green and blue component
		int pixelValue = lineData[x];
		int alpha = imageData.getAlpha(x, y);
		int r = pixelValue & redMask;
		r = (redShift < 0) ? r >>> -redShift : r << redShift;
		int g = pixelValue & greenMask;
		g = (greenShift < 0) ? g >>> -greenShift : g << greenShift;
		int b = pixelValue & blueMask;
		b = (blueShift < 0) ? b >>> -blueShift : b << blueShift;

		bi.setRGB(x, y, alpha << 24 | r << 16 | g << 8 | b);
	}
}