调整大小并上传图片 [英] resize and upload image

查看:83
本文介绍了调整大小并上传图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个调整大小和上传图像的功能.它工作正常,但问题是它增加了图像的KB.例如,如果在调整大小之前图像的大小为17 KB,那么在调整大小之后,图像大小将超过150 KB.

任何人都可以告诉我我犯了什么错误.我的代码就是这样.

Hi all,

I have a function to resize and upload image. It works fine but the problem is it increase the KBs of the image. For example if the size of image is 17 KB before resizing then after resizing it will become more than 150 KB.

Any 1 can tell me what mistake I have made. My code is like this.

Private Function ResizeImage(ByVal OrgBitmap As Bitmap, ByVal ResizeBy As String, ByVal NewValue As Integer) As Bitmap

        Dim OrgHt As Decimal = OrgBitmap.Height
        Dim OrgWd As Decimal = OrgBitmap.Width
        Dim sngRatio As Decimal
        Dim NewWd As Integer
        Dim NewHt_Temp As Decimal
        Dim Newwd_Temp As Decimal
        Dim NewHt As Decimal

        If UCase(ResizeBy) = "W" Then
            sngRatio = OrgWd / OrgHt
            NewWd = NewValue
            NewHt_Temp = NewWd / sngRatio
            NewHt = Convert.ToInt16(NewHt_Temp)
        Else
            sngRatio = OrgHt / OrgWd
            NewHt = NewValue
            Newwd_Temp = NewHt / sngRatio
            NewWd = Convert.ToInt16(Newwd_Temp)
        End If

        Dim NewBitmap As New Bitmap(OrgBitmap, NewWd, NewHt)

        Dim oGraphics As Graphics = Graphics.FromImage(NewBitmap)
        oGraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality


        Return NewBitmap



    End Function

推荐答案

问题不在此代码中.问题在于您如何保存图像.不同的图像格式具有不同的大小,尤其是有损的jpeg,可以根据保存它的代码将其保存为截然不同的文件大小.

内存中的图像大小是恒定的,除非您另存为BMP,否则它的大小将比文件大小大很多.因此,此代码无关紧要.选择文件格式时,您将决定文件的大小.
The issue is not in this code. The issue is in how you save the image. Different image formats are different sizes, and a jpeg in particular, being lossy, can save to wildly different file sizes depending on the code that saves it.

Your image size in memory is constant, and unless you save as BMP, is a lot bigger than your file size. Therefore, this code is irrelevant. It''s when you choose a file format that you decide what the file size will be.


这篇关于调整大小并上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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