Question

I am trying to understand why after cropping an image in .NET i end up with an image 3 times the size of 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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top