Pannable Image不使用滚动条 [英] Pannable Image Without using the scrollbars

查看:85
本文介绍了Pannable Image不使用滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我试图实现Zoomable和panable图像但是在< winforms> 没有滚动条值的情况下

缩放一切正常,

问题是

但是当我尝试计算x和y进行平移时一切都出错了,图像就会消失边界和行为奇怪,





继承我的代码与滚动条值,这里工作正常:

mousemove事件

Hello,
I trying to implement a Zoomable and panable image But in <winforms>without the scrollbars value proprety,
with the zooming everything fine,
the problem is
but when I try to calculate the x and y for panning everything goes wrong ,image goes off borders and acts strangely ,


heres my code with the scroll bar values and here it working fine :
mousemove event

if (m_drawing && CurrentZoomRate >1)
 {
          int DeltaX = (m_StartingPoint.X - e.X);
          int DeltaY = (m_StartingPoint.Y - e.Y);
          this.pbImage.x = DeltaX;
          this.pbImage.y = DeltaY;
          pbimage.AutoScrollPosition= new System.Drawing.Point(Math.Abs(DeltaX - AutoScrollPosition.X), Math.Abs(DeltaY - AutoScrollPosition.Y));





这里当我试图在没有滚动条的情况下做到这一点(我的目标没有它们)

,一切都出错



and here when i trying to do it without out the scroll bars(that my goal without them)
and everything goes wrong

int DeltaX = (m_StartingPoint.X - e.X);
int DeltaY = (m_StartingPoint.Y - e.Y);
this.pbImage.x = DeltaX;
this.pbImage.y = DeltaY;
this.pbImage.Refresh();





这是我的痛苦事件(取自bobpowell.net)



and here is my paintevent (taken from bobpowell.net)

Matrix mx = new Matrix(_zoom, 0, 0, _zoom, 0, 0);
       //now translate the matrix into position for the scrollbars
       mx.Translate(this.x / _zoom, this.y / _zoom);
       //use the transform
       e.Graphics.Transform = mx;
       //and the desired interpolation mode
       e.Graphics.InterpolationMode = _interpolationMode;
       //Draw the image ignoring the images resolution settings.
       e.Graphics.DrawImage(_image, new Rectangle(0, 0, this._image.Width, this._image.Height), 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel);
       base.OnPaint(e);





任何人都可以知道如何进行此计算吗?



我也试图使隐形,但计算这个



can anyone have idea how to preform this calculations ?

I also trying to make the invisible but the ccalculation of this
"

this.AutoScrollMinSize=new Size(
         (int)(this._image.Width*_zoom+0.5f),
         (int)(this._image.Height*_zoom+0.5f)





总是将不可见变成true,试图在paint事件中设置它jst得到我无休止的闪烁。



always turn the invisible to true , trying to set it of in the paint event jst get my endless flickering .

推荐答案

嗯...也许你包含了PictureBox计算中的原始x和y坐标可能会有所帮助吗?



从调试器开始:在线上放置一个断点:

Well...perhaps if you included the PictureBox original x and y coordinates in teh calculation it might help?

Start with the debugger: put a breakpoint on the line:
int DeltaX = (m_StartingPoint.X - e.X);

并逐步执行代码 - 查看值和工作他们应该是什么,并将它与它们的比较。

那么你可以弄清楚你究竟在做什么错误 - 我们无法向您提供准确的说明,因为我们无法运行您的代码并确切了解您是如何做的!

and step through your code - look at the values and work out what they should be, and compare that to what they are.
Then you can work out what exactly you are doing wrong - we can't give you exact instructions because we can't run your code and see exactly how you are doing everything!


这篇关于Pannable Image不使用滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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