在高分辨率图像上,矩形移动非常缓慢 [英] Rectangle movement is very slow on high resolution image

查看:40
本文介绍了在高分辨率图像上,矩形移动非常缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其中在imagebox中加载了图像.然后创建一个小矩形并将其移动以选择和缩放所选区域.但是当我移动矩形时,它对高分辨率图像(1000 ppi)的响应非常慢.

任何建议都值得欢迎和赞赏.

I have an application inwhich an image is loaded in imagebox. Then an small rectangle is created and moved to select and zoom selected area. But when I move the rectangle it is responding very slow for high resolution image (1000 ppi).

Any suggestion is welcome and appreciated.

推荐答案

这种延迟不应发生.我遇到了这个问题,并确保无论是什么图像,细节丰富的图形之上的任何图像渲染都是恒定的.

首先,让我告诉您解决方案是PPI与该问题无关.真正重要的是图像的一部分在屏幕上渲染的时间是多少.当您将矩形移动到图像上方时,图像的某些部分被遮盖,而某些部分则显示出来.您需要使图像的一部分无效,这会触发绘画事件,并且需要花费尽可能多的时间.以下内容应有所帮助:

1)请勿在图像盒上绘画.在某些控件上绘画.您可以实现平移/缩放等.在需要无效的顶部更改任何内容时,将Control.Invalidate与参数(区域或矩形)一起使用以最小化无效区域.

2)将您的操作分为快慢两种,并介绍兑现的图像.它应该只兑现您当前在屏幕上显示的内容.如果您的图像更大,请多花2-3倍的钱(在每个方向上),以快速滚动到相邻位置.在慢速"操作上,例如滚动,重新写现金和从源重新渲染.对于快速"操作(例如矩形运动),仅从现金进行渲染.介绍现金无效的操作.

3)此建议是替代的:切换到WPF.您的许多问题都已得到解决,如果正确使用它们,性能通常会更好.

—SA
This delay should not happen. I had this problem and made sure that any image rendering on top of you detail-rich graphics is constant, no matter what the image is.

First of all, let me tell you the resolution is PPI has nothing to do with the problem. What really matter is the part of the image is rendered on screen how much time your rendering takes. When you move you rectangle over you image, some part of your image is masked, some is showing up. You need to invalidate part of the image which trigger the paint event and takes as much time as it does. The following should help:

1) Do not paint on image box. Paint on some control. You can implements pan/zoom, etc. When changing anything on top which require invalidation, use Control.Invalidate with a parameter (region or rectangle) to minimize invalidated area.

2) Classify your operations into faster and slower and introduce cashed image. It should cash only what is currently shown on your screen at the time. If your image is much bigger, cash 2-3 time more (in each direction) to make scrolling in neighbor position fast. On "slow" operation, such as scrolling away, re-write cash and re-render from source. For "fast" operations, such as your rectangle motion, render from cash only. Introduce the operation of cash invalidation.

3) This advice is alternative: switch to WPF. Many your problems are already resolved, and performance is generally much better if you use things correctly.

—SA


为使您的应用程序即使对于大图像也始终响应,建议您降低显示给用户的图像的分辨率(并保留原始分辨率).在记忆中).例如:
http://www.dreamincode.net/code/snippet1986.htm [
To make your application always responsive even for big images, I suggest you reduce the resolution of the image displayed to the user (and keep the original one in memory). For example:
http://www.dreamincode.net/code/snippet1986.htm[^]

Modify that code to never exceed a maximum size.


我建​​议在mouse.move事件中增加增量步长,或者在达到当前分辨率的函数中对其参数化...



I suggest to increase step of increment in mouse.move event, or parametrize it in function of current resolution reached ...

i.e.

private void mouseMove(object sender, MouseEventArgs e)
{
   static int lastx,lasty;
   int delta = 100;
   if (abs(lastx-e.X)>delta || abs(lasty-e.y)>delta)>
     {
        lastx=e.X;
        lasty=e.Y;
        ...
        "your zoom box code"
        ...
     }

}


这篇关于在高分辨率图像上,矩形移动非常缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆