Tag: 缩放

C#已resize的图像具有黑色边框

我在.NET中有图像缩放的问题。 我使用标准的Graphics类型来调整图像大小,如下例所示: public static Image Scale(Image sourceImage, int destWidth, int destHeight) { Bitmap toReturn = new Bitmap(sourceImage, destWidth, destHeight); toReturn.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution); using (Graphics graphics = Graphics.FromImage(toReturn)) { graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.DrawImage(sourceImage, 0, 0, destWidth, destHeight); } return toReturn; } 但是我对resize的图像有一个很大的问题:它们有灰色和黑色边框,制作没有它们的图像非常重要。 它们为什么出现以及我能做些什么让它们消失? 样本输出:

如何在C#窗体中绘制Zoomable图像

所以我正在实施一个项目,可以读取图像平移,缩放和做其他东西……一切顺利,直到我尝试用鼠标右键实现绘图。 问题是,当我画一条线时,图像上出现的线与我在屏幕上绘制的线不对应,这意味着它被移动了我知道它因为图像的重新resize和缩放,但是当我绘制时图像上的线条与其原始大小(图像)和平移也; 我没有问题。 这是代码。 首先,我点击浏览并选择图像时如何加载图像 Myimage = new Bitmap(ImagePath); resized = myImage.Size; imageResize(); pictureBox.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox_Paint); pictureBox.Invalidate(); imageResize函数执行以下操作: void imageResize() { //calculated the size to fit the control i will draw the image on resized.Height = someMath; resized.Width = someMath; } 然后在pictureBox_Paint事件的事件处理程序中我写道: private void pictureBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { // Create a local version […]

根据当前鼠标位置缩放图形

我正在尝试根据鼠标的当前位置缩放绘图。 现在我的onMouseWheel方法看起来像这样(基于这个StackOverflow答案 ): private void onMouseWheel(object sender, MouseEventArgs e) { if (e.Delta > 0) { _scale *= 1.25f; _translateY = eY – 1.25f * (eY – _translateY); _translateX = eX – 1.25f * (eX – _translateX); } else { _scale /= 1.25f; _translateY = eY – 0.8f * (eY – _translateY); _translateX = eX – […]