TImage 和 TScrollBox 的问题
我正在与德尔福合作。
我有一个滚动框,在其中放置 TImage 控件。现在我想缩放渲染到 TImage 控件中的图像。所以,我使用TCanvas的stretchDraw方法。我的代码是 -
if sbZoom.Down then begin
rct := imgmain.Picture.Bitmap.Canvas.ClipRect;
rct := Rect(rct.Left * 2,rct.Top * 2,rct.Right * 2,rct.Bottom * 2);
imgmain.Picture.Bitmap.Canvas.StretchDraw(rct,imgmain.Picture.Bitmap);
imgmain.Repaint;
end;
它正确缩放图像,我的问题是我希望滚动框的大小也应该随着图像的缩放而改变。还解释一下 Canvas.StretchDraw 方法的参数。我对此有点困惑。
谢谢。
I am working with delphi.
I have one scroll box in which I am putting TImage control. Now I wanted to zoom the image rendered into TImage control. So, I am using stretchDraw method of TCanvas. My code is -
if sbZoom.Down then begin
rct := imgmain.Picture.Bitmap.Canvas.ClipRect;
rct := Rect(rct.Left * 2,rct.Top * 2,rct.Right * 2,rct.Bottom * 2);
imgmain.Picture.Bitmap.Canvas.StretchDraw(rct,imgmain.Picture.Bitmap);
imgmain.Repaint;
end;
It is correctly zooming the image, my problem is I want the size of scroll box also should be changed with zooming of image.Also explain me parameters of Canvas.StretchDraw method. I am little confused with it.
Thank You.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以很容易地做到这一点,而无需调用 StretchDraw:
AutoSize := true 确保 TImage 与内部图片的大小相同。在缩放过程中,我们关闭 AutoSize 并打开 Stretch,因此图片大小会调整为 TImage 大小(此处仍然相同)。然后我们将TImage的大小放大一倍来制作缩放效果。由于 TImage 现在更大,滚动框可以正常工作。
You can do this quite easily without calling StretchDraw:
AutoSize := true assures that the TImage is the same size as the picture inside. During zoom we switch AutoSize off and Stretch on, so the picture is resized to the TImage size (which is still the same here). Then we double the size of the TImage to make the zoom effect. As the TImage is now larger, the scrollbox can work properly.
Uwe Raabe 为您提供了正确的方法。这就是您的方法不起作用的原因:滚动框将显示滚动条并帮助您查看整个控件。在您的情况下,当 TImage 对象变得大于 Scrollbox 时,它只会显示滚动条。 Scrollbox 不可能知道 TImage 的内部结构,因此它不关心 TImage.Picture,它只关心控件。 AutoSize = False 的 TImage 并不关心它的图片,它的大小始终保持不变。
您的代码将基本位图重新绘制到其自身上。问题是,位图具有固定的宽度和高度:如果您在位图区域之外进行绘制,那么您基本上会被默默地忽略。当您通过 StretchDrawing 位图“缩放”到其自身上时(我很惊讶它一开始就起作用了!),您并没有使位图变大,并且不适合的内容会被默默地剪掉。如果您确实希望内部位图更改大小,那么您首先需要创建一个新的、更大的位图,将放大的图像绘制到新位图,然后将该位图分配给您的 TImage。如果这样做,请确保 TImage.AutoSize = True。
Uwe Raabe is giving you the right way to do it. Here's why your way doesn't work: A scroll box will show scrollbars and help you see whole controls. In your case, it will only show scrollbars when the TImage object grows larger then the Scrollbox. The Scrollbox can't possibly know the internals of TImage so it doesn't care about TImage.Picture, it only cares about the control. And a TImage that has AutoSize = False doesn't care about it's Picture, it's size stays the same at all times.
Your code repaints the base bitmap onto itself. The problem is, the bitmap has fixed Width and Height: if you paint outside the bitmap's area you're basically silently ignored. When you're "zooming" by StretchDrawing the bitmap onto itself (and I'm surprised it worked to start with!) you're not making the bitmap larger and the stuff that doesn't fit gets silently clipped away. If you do want the internal bitmap to change size then you'll first need to create a new, larger bitmap, draw your enlarged image to the new bitmap and then assign the bitmap to your TImage. If you do this, make sure TImage.AutoSize = True.
您应该将图像控件的大小设置为位图的大小。
You should set the size of the image control to the size of the bitmap.