保存时Vb.net位图模糊 [英] Vb.net bitmap blurred when saved

查看:83
本文介绍了保存时Vb.net位图模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再次问好!



有人可以告诉我怎样才能保存我在其上绘制(绘制)的图像,其图像质量与原始图像相同?



我正在使用此代码保存图片:



hello once again !

could someone tell me how could i save an image that i drew (painted) on it with the same image quality as the original image ?

i'm using this code to save the image :

Using Bmp As New Bitmap(PictureBox4.Image, defaultWidth, defaultHeight)

            Using G As Graphics = Graphics.FromImage(Bmp)

                G.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
                G.PixelOffsetMode = Drawing2D.PixelOffsetMode.Half

                G.DrawImage(Bmp, 0, 0, defaultWidth, defaultHeight)

                Bmp.Save(str1 & "\" & str2, Imaging.ImageFormat.Jpeg)
                Dim myCallback As New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
                Dim myBitmap As New Bitmap(Drawbitmap)
                Dim myThumbnail As Image = myBitmap.GetThumbnailImage(100, 60, myCallback, IntPtr.Zero)
                myThumbnail.Save(str1.Replace("Saved", "Thumbnails") & "\" & str2)
                Bmp.Dispose()

            End Using
        End Using





事情是原始图像有1920x1080,当我将图像加载到图片框中时我使用波纹管代码来缩放位图以适合图片框:





the thing is the original image has 1920x1080 ,when i load the image into a picturebox i use the bellow code to scale the bitmap to fit the picturebox :

Dim PicBoxHeight As Integer
        Dim PicBoxWidth As Integer
        Dim ImageHeight As Integer
        Dim ImageWidth As Integer
        Dim TempImage As Image
        Dim scale_factor As Single
        PictureBox4.SizeMode = PictureBoxSizeMode.Normal
        ' Get control size
        PicBoxHeight = PictureBox4.Height
        PicBoxWidth = PictureBox4.Width
        ' Load the image. Change Image.FromFile() to match your code
        TempImage = Image.FromFile(str)
        defaultWidth = TempImage.Width
        defaultHeight = TempImage.Height
        ' Get image size
        ImageHeight = TempImage.Height
        ImageWidth = TempImage.Width
        ' Calculate scale_factor
        scale_factor = 1.0 ' No scaling by default i.e. image fits in the Box
        ' 1) Height
        If ImageHeight > PicBoxHeight Then
            ' Reduce height first
            scale_factor = CSng(PicBoxHeight / ImageHeight)
        End If
        ' 2) Width. Notice, we do know now how much we have to scale down the height
        ' and the scale_factor affects width too
        If (ImageWidth * scale_factor) > PicBoxWidth Then
            ' Scaled width exceeds Box's width, recalculate scale_factor
            scale_factor = CSng(PicBoxWidth / ImageWidth)
        End If
        ' Move image to control for resizing
        PictureBox4.Image = TempImage
        ' Get the source bitmap.
        Dim bm_source As New Bitmap(PictureBox4.Image)
        ' Make a bitmap for the result.
        Dim bm_dest As New Bitmap( _
            CInt(bm_source.Width * scale_factor), _
            CInt(bm_source.Height * scale_factor))

        ' Make a Graphics object for the result Bitmap.
        Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)
        ' Copy the source image into the destination bitmap.
        gr_dest.DrawImage(bm_source, 0, 0, _
            bm_dest.Width + 1, _
            bm_dest.Height + 1)
        ' Display the result.
        PictureBox4.Image = bm_dest





正如你所看到的那样,它可以缩放到更低的分辨率当我完成绘制并单击保存按钮时,它会将位图重新调整为原始图像



As you can see the image it's scaled to a lower resolution and when i finish drawing on it and click the save button , it re-sizes the bitmap to the original's image

Using Bmp As New Bitmap(PictureBox4.Image, defaultWidth, defaultHeight)



分辨率并保存图像。但图像保存时会模糊不清,每次重新保存图像时,图像都会增加模糊效果。我怎么能防止模糊应用于保存的图像。谢谢!


resolution and saves the image . But the image is saved with a blur over it and each time i re-save that image it keeps adding more blur to it. How could i prevent the blur from applying on the saved image.Thank you !

推荐答案

从这里开始:

Start here:
Bmp.Save(str1 & "\" & str2, Imaging.ImageFormat.Jpeg)



不要使用Imaging.ImageFormat.Jpeg - 这是一个有损压缩技术,这意味着它丢弃信息离子顺序,以节省每次保存空间。机会是,这是你模糊的来源。



试一试:加载BMP,保存为JPG。

加载JPG,再次保存。

重复几次,你得到一个非常小的文件,看起来很像原版,不需要对它进行任何更改 - 并且没有chnace无论你在CSI上看到什么,都能获得清晰度......


Don't use Imaging.ImageFormat.Jpeg - it's a lossy compression technique and that means that it "throws away" information ion order to save space every single time you save it. The chance are, this is the source of your "blurriness".

Try it: load a BMP, save it as JPG.
Load the JPG, save it again.
Repeat a few times and you end up with a remarkably small file, that looks very little like the original without needing to make any changes to it - and with no chnace whatsoever of getting the sharpness back, despite what you see on CSI...


除了解决方案1:在渲染过程中也会出现一些模糊,可以通过使用最佳插值模式和其他渲染选项。



但这不是你最大的问题。整段代码完全没有意义。看看你在做什么:使用 PictureBox4.Image 初始化 bmp 。但为什么不使用 PictureBox4.Image 本身?这是一项多余的操作。



现在,看看你接下来要做什么。在新的位图 bmp 上绘制... 保存非常位图!可能会有质量下降!一个多余的操作!



我不确定你知道你在做什么以及你想做什么。



-SA
In addition to Solution 1: some of the blur can also occur during rendering, which can be cured by using the best-quiality interpolation mode and other rendering options.

But this is not your biggest problem. The whole piece of code is totally pointless. Look what you are doing: you initialize bmp using PictureBox4.Image. But why not using PictureBox4.Image itself? This is a redundant operations.

Now, look what you do next. On the new bitmap bmp you draw… the save very bitmap! with possible loss of quality! one more redundant operation!

I'm not sure you have any idea what you are doing and what do you want to do.

—SA


谢谢OriginalGriff,我已经尝试过你的方式而没有我在谷歌上看到的这个模糊的结果由于位图调整大小而出现。
Thank you OriginalGriff , i have tried your way and with no result from what i have read on google this blur appears due to the bitmap resize .


这篇关于保存时Vb.net位图模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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