将较大的图像放入较小的画布中
我的问题:我在 Eclipse RCP 应用程序中创建并填充了一个 Canvas,如下所示:
Canvas myCanvas = new Canvas(comImageViewer, SWT.H_SCROLL | SWT.V_SCROLL);
myCanvas.setLocation(0, 0);
myCanvas.setSize(583, 432);
myCanvas.setLayout(new FormLayout());
myCanvas.addPaintListener( new PaintListener() {
public void paintControl(PaintEvent e) {
GC gc = e.gc;
gc.drawImage( image,10,10); // Draw the moon
}
});
根据定义,该画布具有 V_Scroll 和 H_Scroll 条,但它们不会滚动运行时显示的图像。 现在,我的要求是:
图像对于小尺寸的画布来说太大了。那么,我怎样才能使加载的图像:
- 要么适合画布。
- 或者使画布的滚动条(我已添加或任何)这样使用,以便它们可以在运行时上下滚动画布中显示的图像。
My question : I have created and filled a Canvas in Eclipse RCP application as follows :
Canvas myCanvas = new Canvas(comImageViewer, SWT.H_SCROLL | SWT.V_SCROLL);
myCanvas.setLocation(0, 0);
myCanvas.setSize(583, 432);
myCanvas.setLayout(new FormLayout());
myCanvas.addPaintListener( new PaintListener() {
public void paintControl(PaintEvent e) {
GC gc = e.gc;
gc.drawImage( image,10,10); // Draw the moon
}
});
and by definition, this canvas has V_Scroll and H_Scroll bars, but they do not scroll the image displayed at run time.
Now, My Requirements are:
The Image is too big for small sized Canvas. So, How can I make the loaded image :
- either fit into the canvas.
- Or make the Canvas's Scroll bars(which I have added or any) such employed that they can scroll up-down the image displayed in canvas at runtime.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个 snippet 解释了如何在 SWT Canvas 上滚动图像。
Take a look at this snippet which explains how to scroll an Image on SWT Canvas.