gpt4 book ai didi

Java swt 图像插值

转载 作者:行者123 更新时间:2023-11-30 06:27:42 26 4
gpt4 key购买 nike

我使用的java程序不是我自己编写的,但我有所有的源代码。该程序由控制相机和显示图像的 SWT 小部件组成(它要复杂得多,但这是相关部分)。到目前为止,一切都运行良好,但是从几个月前开始,当我们升级到 maven(可能还有我不知道的其他一些升级)时,它开始在放大时插入图像像素。这非常烦人,因为整个应用程序是取决于看到的各个像素。升级之前,当增加像素大小超过原始屏幕分辨率时,它会显示大的单色方 block ,这正是我想要的。现在它只是模糊了一切。

所以我的问题是:如何关闭图像插值?

干杯,安德烈亚斯

编辑以澄清:有一个滚动条控制执行以下代码的显示图像的大小。

void zoomScaleEvent(Event event, boolean centreOnMouse){
setScale(selToScale(infoPanel.swtZoomScale.getSelection())); //force scale in range
int newScaleSel = infoPanel.swtZoomScale.getSelection();

Point dOrigin = swtImgScrollComp.getOrigin(); //display units
Rectangle clientArea = swtImgScrollComp.getClientArea();

// position in display coords of point to zoom in on
int dispZX, dispZY;
if(centreOnMouse){
dispZX = event.x;
dispZY = event.y;
}else{
dispZX = clientArea.width / 2;
dispZY = clientArea.height / 2;
}

//position in image of that point (caled using the old scale)
double lastScale = selToScale(lastScaleSel);
double imgZX = (dispZX + dOrigin.x) / lastScale;
double imgZY = (dispZY + dOrigin.y) / lastScale;

//origin of swtScrollComp of that point required to holding that point in the /same place/.
double newScale = selToScale(newScaleSel);
double newDispOX = imgZX * newScale - dispZX;
double newDispOY = imgZY * newScale - dispZY;

swtImgScrollComp.setOrigin((int)newDispOX, (int)newDispOY);


Img img = getSelectedImageFromConnectedSource();
if(img != null){
double scale[] = getScale();
swtImageCanvas.setSize(
(int)(img.getWidth()*scale[0]),
(int)(img.getHeight()*scale[1]));
}
lastScaleSel = newScaleSel;
swtImageCanvas.redraw();

}

编辑2:我认为这是实际的绘图例程:

private void canvasPaintEvent(PaintEvent event){
Rectangle clientArea = swtImageCanvas.getClientArea();
Img image = getSelectedImageFromConnectedSource();

if(image != null && swtCurImage != null){
double scale[] = getScale();
int imgX0 = (int)((double)event.x / scale[0]);
int imgY0 = (int)((double)event.y / scale[1]);
int imgW = (int)((double)event.width / scale[0]) + 2;
int imgH = (int)((double)event.height / scale[1]) + 2;
if((imgX0 + imgW) >= image.getWidth()){
imgW = image.getWidth() - imgX0;
}
if((imgY0 + imgH) >= image.getHeight()){
imgH = image.getHeight() - imgY0;
}
try{
event.gc.drawImage(swtCurImage, imgX0, imgY0, imgW, imgH,
(int)(imgX0*scale[0]),
(int)(imgY0*scale[1]),
(int)(imgW*scale[0]),
(int)(imgH*scale[1]));
}catch(IllegalArgumentException e){
System.out.println("DRAW FAILED: " + scale + "\t" + imgX0 +", "+ imgY0+", "+ imgW+", "+ imgH +"\t-->\t" +
event.x+", "+ event.y+", "+ event.width+", "+ event.height);
}
event.gc.setForeground(swtImageCanvas.getDisplay().getSystemColor(SWT.COLOR_BLACK));
if(selectStartTime >= 0){
event.gc.drawRectangle(
(int)(selX0 * scale[0]), (int)(selY0 * scale[1]),
(int)(selW * scale[0]), (int)(selH * scale[1]));
}else{
event.gc.drawLine(0, (int)(posY * scale[1]), clientArea.width, (int)(posY * scale[1]));
event.gc.drawLine((int)(posX * scale[0]), 0, (int)(posX * scale[0]), clientArea.height);
}

for(ImagePipeController sinkController : sinkControllers.values())
if(sinkController instanceof SWTControllerInfoDraw)
((SWTControllerInfoDraw)sinkController).drawOnImage(event.gc, scale, image.getWidth(), image.getHeight(), false);

if(sourceControl != null && sourceControl instanceof SWTControllerInfoDraw){
((SWTControllerInfoDraw)sourceControl).drawOnImage(event.gc, scale, image.getWidth(), image.getHeight(), true);
}

}else{
event.gc.fillRectangle(clientArea);
if(image == null){
event.gc.drawText("null image", 0, 0);
}else if(image.isDestroyed()){
event.gc.drawText("Image Destroyed", 0, 0);
}else{
event.gc.drawText("Image OK but no swtCurImage!?!", 0, 0);
}

}

}

最佳答案

通话

event.gc.setInterpolation(SWT.NONE);

event.gc.drawImage之前关闭图像插值。

关于Java swt 图像插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46785349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com