Mega Code Archive

 
Categories / Delphi / Graphic
 

A good method to zoom a picture

Title: A good method to zoom a picture. Question: How to stretch/zoom a picture using Windows API without much disturbance, and give you a fine result. Answer: There is a good way to zoom into a picture with a fine result, the Bitmap routines of windows API give us a good way to stretch Bitmaps,The following code represent the zoom operations, gives you a smooth zoom. Var OrignBitmap: TBitmap;//To Save the original bitmap ... procedure TForm1.OnCreate(Sender: TObject); begin OrignBitmap := TBitmap.Create; //Create the original OrignBitmap.LoadFromFile('C:\Windows\Gone Fishing.bmp')//load the bitmap end; Procedure TForm1.Button1Click(Sender: TObject); Var TempBitmap: TBitmap; //Temporary picture handler for process Begin TempBitmap := TBitmap.Create; Try TempBitmap.Height := OrignBitmap.Height + ScrollBar1.Position; //hint: Scrollbar start from 0 TempBitmap.Width := OrignBitmap.Width + ScrollBar1.Position; SetStretchBltMode(TempBitmap.Canvas.Handle,STRETCH_HALFTONE); //set stretch parameters SetBrushOrgEx((TempBitmap.Canvas.Handle,0,0,nil); //Rearrange the Brush property for safety reason //start to stretch the bitmap StretchBlt( TempBitmap.Canvas.Handle, //stretch Destination bitmap 0,0,TempBitmap.Width,TempBitmap.Height,//stretch Destination Rectangular OrignBitmap.Canvas.Handle,//source Rectangular 0,0,OrignBitmap.Width,OrignBitmap.Height, ,//stretch Destination Rectangular SRCCOPY//stretch parameter ); //assign the Destination bitmap to the form image Image1.Picture.Bitmap.Assign(TempBitmap); //view the image Image1.Refresh; Finally TempBitmap.Free; //Free the Temporary image End; End; procedure TForm1.OnClose(Sender: TObject); begin OrignBitmap.Free //free the bitmap end;