图像出现在圆形边框外

问题描述 投票:0回答:0

我在圆形图片框内有一张图片。在表格上没问题。当我保存图像时,显示圆形图片框“外部”的部分。 问题:如何让圆形图片框外的区域在保存时“不”显示图片??这是表格上的图片.

这里是保存的图片

VB.Net PicCropImageRound 是我的图片框的名称。

保存功能
    '保存当前照片
            将 strCurDir 调暗为字符串 = Path.GetDirectoryName(LblOrigPath.Text)
            将 strNewName 变暗为字符串 = Path.GetFileNameWithoutExtension(LblOrigPath.Text)

            Dim x As Integer = PicCropImageRound.Width
            Dim y As Integer = PicCropImageRound.Height
            将 bm 调暗为新位图 (x, y)

            PicCropImageRound.DrawToBitmap(bm, 新矩形(0, 0, x, y))

            PicCropImageRound.Image = bm
            PicCropImageRound.Invalidate() 方法

            '查找图像类型
            将 img1 调暗为图像 = System.Drawing.Image.FromStream(New MemoryStream(File.ReadAllBytes(LblOrigPath.Text)),True)

            将 imageType 调暗为 String = String.Empty

            如果 ImageFormat.Jpeg.Equals(img1.RawFormat) 那么
                imageType = "JPEG 图片"
            ElseIf ImageFormat.Bmp.Equals(img1.RawFormat) 那么
                imageType = "BMP 图片"
            ElseIf ImageFormat.Gif.Equals(img1.RawFormat) 那么
                imageType = "GIF 图片"
            ElseIf ImageFormat.Tiff.Equals(img1.RawFormat) 那么
                imageType = "TIFF 图像"
            ElseIf ImageFormat.Png.Equals(img1.RawFormat) 那么
                imageType = "PNG 图片"
            别的
                imageType = "未知图像类型"
            万一

            如果 imageType = "JPEG 图像" 那么

                '将图片保存在PictureBox中
                SaveImage(strCurDir & "\" & strNewName & ".jpg", PicCropImageRound.Image)
            End If
任何指针将不胜感激。

编辑: 在搜索并找到让我接近预期效果的代码示例之后。 作物

Dim x As Integer = PicCropImageRound.ClientSize.Width
                将 y 调暗为整数 =
                PicCropImageRound.ClientSize.Height
                将 bm 调暗为新位图 (x, y)

                PicCropImageRound.DrawToBitmap(bm, 新矩形(0,
                0, x, y))
                PicCropImageRound.Image = bm
                PicCropImageRound.Invalidate() 方法
                '新代码
                '获取原始图像。
                 Dim originalImage = PicCropImageRound.Image
                  '创建一个新的空白图像
                   方面。
                将 croppedImage 调暗为新位图(originalImage.Width,
                原始图像.高度)
 
                '准备绘制新图像。
                 使用 g = Graphics.FromImage(croppedImage)
                     昏暗路径作为新的 GraphicsPath
 
                     '创建一个椭圆来填充图像
                     方向。
                     path.AddEllipse(0, 0, croppedImage.Width,
                     croppedImage.Height)
 
                     Dim reg 作为新区域(路径)
 
                     '仅在指定的椭圆内绘制。
                     g.Clip = reg
                     g.DrawImage(originalImage, Point.Empty)
                 结束使用
 
                 '显示新图像。
                 PicCropImageRound.Image = croppedImage

如图所示,外面不是透明的?? 会就那部分寻求建议吗??

新代码生成此图像。

vb.net picturebox
© www.soinside.com 2019 - 2024. All rights reserved.