DrawImage problem (not retaining the pixel configuration)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello Guys,

Iam working on a zoom in and out tool and here is the code iam using for it
//Method for zooming in

Bitmap bmpSource=new Bitmap(ImgBox.Image);
Bitmap bmpZoomed=new
Bitmap(bmpSource.Width*ZoomInFactor,bmpSource.Height*ZoomInFactor);

Graphics grZoom=Graphics.FromImage(bmpZoomed);
grZoom.InterpolationMode=InterpolationMode.HighQualityBilinear;
grZoom.DrawImage(bmpSource,0,0,bmpZoomed.Width+1,bmpZoomed.Height+1);
ImgBox.Image=bmpZoomed;

//Method for zooming Out

Bitmap bmpSource=new Bitmap(ImgBox.Image);
Bitmap bmpZoomed=new
Bitmap(bmpSource.Width/ZoomInFactor,bmpSource.Height/ZoomInFactor);

Graphics grZoom=Graphics.FromImage(bmpZoomed);
grZoom.InterpolationMode=InterpolationMode.HighQualityBilinear;
grZoom.DrawImage(bmpSource,0,0,bmpZoomed.Width+1,bmpZoomed.Height+1);
ImgBox.Image=bmpZoomed;

It is working fine but the picture resulution is lost if we do symultaneous
multiple zoomin and zoom out..Specially if you zoomout first and then zoom
in...
Any ideas on how to retain the pixel configuration ....
Any valuable thought should help

Cheerz,
Ajay
 
The problem is that you are altering an image and storing in in an
ImageBox object and then using the same image to zoom out from.

Therefore these scaling operations are effecting the output image
quality which is then used as input.

It would be better to store a copy of the original bitmap somewhere in
your code and base the scaling operation on that copied image. I.e.
instead of

Bitmap bmpSource=new Bitmap(ImgBox.Image)

use the original copy

Bitmap bmpSource=this.mysavedcopy;

Andrew Murray
 
Back
Top