对不起我的英语。我试图在拖动后裁剪图像。它可以工作,但我的问题是,黑色粗体边框出现在裁剪后的图像上。我不知道怎么解决它。
这是我的代码:
using (Bitmap sourceBitmap = new Bitmap(fullSizeImage)) { Rectangle cropRect = new Rectangle(0, 0, sourceWidth, sourceHeight); using (Bitmap newBitMap = new Bitmap(cropRect.Width, cropRect.Height)) { using (Graphics g = Graphics.FromImage(newBitMap)) { g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; g.CompositingMode = CompositingMode.SourceCopy; g.DrawImage(sourceBitmap, new Rectangle(0, pp, sourceWidth, sourceHeight), cropRect, GraphicsUnit.Pixel); g.InterpolationMode = InterpolationMode.HighQualityBicubic; ImageCodecInfo codec = ImageCodecInfo.GetImageEncoders()[4]; EncoderParameters parameters = new EncoderParameters(1); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); newBitMap.Save(filePath); } } }
下面是裁剪后的图像:
您的目标图像具有相同的物理尺寸,因为您使用相同的物理尺寸来创建它:
Rectangle cropRect = new Rectangle(0, 0, sourceWidth, sourceHeight);
当您将原始图像绘制到此新位图中时,您将使用偏移量进行绘制 pp ,但仍然具有相同的高度和宽度(因此您只裁剪底部和右侧)。这个偏移只从y坐标向下“着色”新位图的内存,因此有黑色边框。
pp