0
我正在SWT中创建图像操纵器框架。其中一部分是选择图像的特定部分并以某种方式操纵它。由于我使用第三方软件,因此我只能操作整个图像,并希望复制选区的像素。将一个图像的像素复制到另一个
功能如下:
public Image doMagic(Image input, Selection selection) {
Image manipulatedImage = manipulateImage(input);
int width = manipulatedImage.getBounds().width;
int height = manipulatedImage.getBounds().height;
GC gc = new GC(manipulatedImage);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (!selection.containsPixel(x, y)) {
// we should not have transformed this pixel
//-> we set it back to the original one
gc.drawImage(input, x, y, 1, 1, x, y, 1, 1);
}
}
}
gc.dispose();
return manipulatedImage;
}
现在这个工作,但速度很慢。可能是因为整个图片都是用来绘制单个像素的。
第二种可能性是:
ImageData inputData = input.getImageData();
ImageData manipulatedImageData = manipulatedImage.getImageData();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (!selection.containsPixel(x, y)) {
manipulatedImageData.setPixel(x, y, inputData.getPixel(x,y));
}
}
}
return new Image(image.getDevice(), manipulatedImageData);
但是,这并不在所有的工作,我猜是因为调色板,而操纵改变。在我的情况下,灰度创建一个黄色的灰度图像。
那么我还有另一种可能吗?在图像之间传输像素的推荐方式是什么?