Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to decrease width of image without losing its quality and without cropping it. When i am trying to decrease the width the image it becomes blurred. How can i resolve this? This is what i have tried so far.

What I have tried:

Dim barcode As Barcode128

barcode = BarcodeFactory.GetBarcode(Symbology.Code128)

barcode.Number = TextBox1.Text.ToUpper

barcode.Height = 120 Dim bitmap As Bitmap = barcode.Render()

Dim Cr As New Rectangle(5, 55, 130, 80) 'upperleft(x),upperleft(-y),right(-x),bottom(y)

Dim OrignalImage As Bitmap

OrignalImage = bitmap

Dim CropImage = New Bitmap(CropRect.Width, CropRect.Height

Using grp = Graphics.FromImage(CropImage)

grp.CompositingQuality = Drawing2D.CompositingQuality.HighQuality

grp.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic

grp.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

grp.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality

grp.DrawImage(OrignalImage,New Rectangle(7,5,Cr.Width,Cr.Height),Cr, GraphicsUnit.Pixel)

PicBarCode.Image = CropImage

CropImage.Save("D:\bc.jpeg")

grp.Dispose()
End Using
Posted
Updated 9-Nov-20 23:44pm
Comments
[no name] 10-Nov-20 5:28am    
You can't resize just one dimension and expect to maintain "aspect ratio".
Richard Deeming 10-Nov-20 5:30am    
Saying you want to decrease the width of the image without losing quality and without cropping is like saying you want all of your shopping to be in one bag, but you don't want that bag to be heavy.

If you make the image dimensions smaller, you will inevitably lose some information.
Sandeep Mewara 10-Nov-20 5:52am    
:laugh: :thumbsup:

1 solution

Tell me this: if I have a cubic box of tomatoes and I sit on it - lowering it's height by half - are the tomatoes inside still all round and perfect?

Of course not: I have reduced the volume of the box significantly, and squashed the fruits inside.

That's what happens when you reduce the width of an image without changing any other dimension: the pixels get "squashed together" and that means information has to be discarded in order to fit them in. This causes the "Blurring" you have noticed, and is fundamental to all images.

You cannot reduce width alone without throwing away pixels: either by "squashing them togther", or clipping them out of the image completely.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900