在用户进行选择的PictureBox中缩放图像 [英] Zoom Image in the PictureBox where user make selection

查看:86
本文介绍了在用户进行选择的PictureBox中缩放图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大师,

我有一个c#windows表单应用程序。 Panel中有一个PictureBox。图像加载到PictureBox中。我希望图像缩放用户选择的区域。用户将使用鼠标左键拖动进行选择。我所做的是鼠标
down事件,将x / y保存在变量中并在鼠标移动事件中绘制矩形 加上我在另一个变量中记录当前位置的x / y。在鼠标向上事件中,创建一个选择大小的矩形。并使用矩形的宽度和高度创建一个位图
。然后我使用创建的位图创建了一个图形对象。然后使用DrawImage函数将图像绘制到创建并分配给PictureBox的位图。但它始终需要0,0的x / y坐标。

I have a c# windows form application. There is a PictureBox within a Panel. An image is loaded in the PictureBox. I want the image to be zoomed the area user selects. The user will select by dragging using the left mouse button. What I did is on the mouse down event, saved the x/y in a variable and in mouse move event am drawing the rectangle plus am recording the x/y of the current position in another variable. And in mouse up event, create a rectangle of the size of the selection made. And create a bitmap using the rectangle's width and height. Then I created a graphics object using the created bitmap. Then use the DrawImage function to draw the image to the bitmap created and assigned to the PictureBox. But it always takes the x/y coordinates from 0,0.

请帮助

Vinu

推荐答案

DrawImage有很多版本。 你想要的是DrawImage(Image,int,int,Rectangle,GraphicsUnit)。 两个整数指定目标图像中开始绘制的位置。  Rectangle表示要复制的
源图像的哪一部分。
There are a number of versions of DrawImage.  The one you want is DrawImage( Image, int, int, Rectangle, GraphicsUnit ).  The two integers specify where in the destination image to start drawing.  The Rectangle says which section of the source image you want copied.


这篇关于在用户进行选择的PictureBox中缩放图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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