开发者

Cropping images with no loss using .NET

开发者 https://www.devze.com 2022-12-25 08:30 出处:网络
I am trying to understand why after cropping an image in .NET i end up with an image 3 times the size 开发者_如何学JAVAof the original image.

I am trying to understand why after cropping an image in .NET i end up with an image 3 times the size 开发者_如何学JAVAof the original image. Listed below is the code i am using to crop the image

  Private Shared Function CropImage(ByVal img As Image, ByVal cropArea As Rectangle) As Image
      Dim bmpImage As Bitmap = New Bitmap(img)
      Dim bmpCrop As Bitmap = bmpImage.Clone(cropArea, img.PixelFormat)
      Return CType(bmpCrop, Image)
   End Function

where img is the original image loaded from file into an image object.

How can i achieve a loss less cropping of my image?


Take a look at the second answer to this question:

High Quality Image Scaling Library

That code should help. The problem is that the .NET image handling library defaults the System.Drawing.Imaging.Encoder.Quality setting to 100%, which is literally three times the size of 90%, which has no visible difference in quality. Use the code in that question to save your image at lower quality settings and you should see a big difference in the size of your file.

0

精彩评论

暂无评论...
验证码 换一张
取 消