【发布时间】:2016-10-08 00:24:54
【问题描述】:
我正在显示像素列表中的图像,如下所示(可行):
private Image GetImage()
{
PaletteData palette=new PaletteData(0xff0000,0x00ff00,0x0000ff);
ImageData imageData = new ImageData(bmpHW, bmpHW,32,palette);
currentImagePixelVec = getPixelsFromBMP(0, 0, graphicsMemory);
int pixelVecLoc=0;
for (int h = 0; h<bmpHW; h++)
{
for (int w = 0; w<bmpHW; w++)
{
int p = 0;
Pixel pixel = currentImagePixelVec.get(pixelVecLoc);
p = (pixel.Alpha<<24) | (pixel.Red<<16) | (pixel.Green<<8) | pixel.Blue;
imageData.setPixel(w, h, p);
pixelVecLoc++;
}
}
imageData = imageData.scaledTo(700, 700);
Image image = ImageDescriptor.createFromImageData(imageData).createImage();
return image;
}
我让用户按如下方式选择图像的一个矩形(这可行):
if(drag)
{
GC gc1 = e.gc;
//gc.setBackground(top.getDefault().getSystemColor(SWT.COLOR_BLACK));
gc1.setAlpha(128);
int minX = Math.min(startX, endX);
int minY = Math.min(startY, endY);
int maxX = Math.max(startX, endX);
int maxY = Math.max(startY, endY);
int width = maxX - minX;
int height = maxY - minY;
gc1.fillRectangle(minX, minY, width, height);
}
我想从矩形选择中创建一个新图像:
private Image GetZoomedImage()
{
int minX = Math.min(startX, endX);
int minY = Math.min(startY, endY);
int maxX = Math.max(startX, endX);
int maxY = Math.max(startY, endY);
int width = maxX - minX;
int height = maxY - minY;
PaletteData palette=new PaletteData(0xff0000,0x00ff00,0x0000ff);
ImageData imageData = new ImageData(1300, 1300,32,palette);
int newHeight = 0;
int newWidth = 0;
for (int h = minX; h<maxX; h++)
{
for (int w = minY; w<maxY; w++)
{
int p = 0;
//Pixel pixel = currentImagePixelVec.get((h * w)-1);
int actualPix = imageDisplayed.getImageData().getPixel(h, w);
//p = (pixel.Alpha<<24) | (pixel.Red<<16) | (pixel.Green<<8) | pixel.Blue;
System.out.println("Pixel: " + Integer.toString(actualPix));
//imageData.setPixel(newWidth,newHeight, p);
imageData.setPixel(newWidth,newHeight, actualPix);
newWidth++;
}
newHeight++;
}
imageData = imageData.scaledTo(700, 700);
Image image = ImageDescriptor.createFromImageData(imageData).createImage();
return image;
}
我在这件事上走对了吗?
【问题讨论】:
标签: java image image-processing swt pixel