Home » Category » Microsoft Visual Basic

Microsoft Visual Basic: zoom in zoomout in vb6.0

206| Wed, 02 Jan 2008 22:45:00 GMT| kumar_ps| Comments (5)
i am using a picturebox in my application when i will scan a image it will comes to pictuebox. my poblem is how to zoom in zoom out that image or picturebox

Keywords & Tags: zoom, zoomout, vb6.0, microsoft, visual basic

URL: http://www.programmerbase.com/visual-basic/560748/
 
«« Prev - Next »» 5 helpful answers below.
Hi Kumar,

below is a sample code on howto zoom-in and zoom-out.. hope it's useful to you.. good luck my fren.. :)

Code: ( text )
  1. There may be a way to this with a stretched image control, but this
  2. seems to work OK. New project, 2 picture boxes, 2 command buttons:
  3. Option Explicit
  4. Private Const HALFTONE As Long = 4
  5. Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, _
  6. ByVal x As Long, _
  7. ByVal y As Long, _
  8. ByVal nWidth As Long, _
  9. ByVal nHeight As Long, _
  10. ByVal hSrcDC As Long, _
  11. ByVal xSrc As Long, _
  12. ByVal ySrc As Long, _
  13. ByVal nSrcWidth As Long, _
  14. ByVal nSrcHeight As Long, _
  15. ByVal dwRop As Long) As Long
  16. Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, _
  17. ByVal nStretchMode As Long) As Long
  18. Private Sub Form_Load()
  19. With Picture2 'source
  20. .AutoRedraw = True
  21. .ScaleMode = vbPixels
  22. .Visible = False
  23. ' .AutoSize = True 'use if loading a graphic
  24. Picture2.Print "Some Picture Box Text"
  25. 'or .Picture = LoadPicture("c:\somefolder\somegraphic.bmp")
  26. End With
  27. With Picture1 'dest
  28. 'I've heard this improves quality
  29. SetStretchBltMode .hdc, HALFTONE
  30. .AutoRedraw = True
  31. .ScaleMode = vbPixels
  32. .Move 0, 0, Picture2.Width, Picture2.Height
  33. .Picture = Picture2.Picture
  34. End With
  35. Command1.Caption = "Zoom &In"
  36. Command2.Caption = "Zoom &Out"
  37. End Sub
  38. Private Sub Command1_Click()
  39. 'zoom in by 20%
  40. With Picture1
  41. .Move 0, 0, .Width * 1.2, .Height * 1.2
  42. .Cls
  43. StretchBlt .hdc, 0, 0, .ScaleWidth, .ScaleHeight, Picture2.hdc, 0, 0,
  44. Picture2.ScaleWidth, Picture2.ScaleHeight, vbSrcCopy
  45. End With 'Picture1
  46. End Sub
  47. Private Sub Command2_Click()
  48. 'zoom out by 20%
  49. With Picture1
  50. .Move 0, 0, .Width * 0.8, .Height * 0.8
  51. .Cls
  52. StretchBlt .hdc, 0, 0, .ScaleWidth, .ScaleHeight, Picture2.hdc, 0, 0,
  53. Picture2.ScaleWidth, Picture2.ScaleHeight, vbSrcCopy
  54. End With 'Picture1
  55. End Sub

sashi | Wed, 02 Jan 2008 22:46:00 GMT |

Hi, I am new to this site and am having the same problem. i want to zoom in to my mandelbrot image but am having trouble on what the heck to do. I have one button to load the madelbrot and was hoping to click on the picturebox to zoom. please help.

aworldwithoutsin | Wed, 02 Jan 2008 22:47:00 GMT |

Quote:
Originally Posted by aworldwithoutsin
Hi, I am new to this site and am having the same problem. i want to zoom in to my mandelbrot image but am having trouble on what the heck to do. I have one button to load the madelbrot and was hoping to click on the picturebox to zoom. please help.
One fairly simple technique is to place an Image control inside a picturebox control. Set the Stretch property of the Image control to True. Then load your picture into it, and just change the size of the Image control.

You can set up scroll bars and based on their values, MOVE the Image control around (remember you can move to locations lower than zero) to scroll, as well as zoom.

Have fun!

killer42 | Wed, 02 Jan 2008 22:48:00 GMT |

Quote:
Originally Posted by aworldwithoutsin
Hi, I am new to this site and am having the same problem. i want to zoom in to my mandelbrot image but am having trouble on what the heck to do. I have one button to load the madelbrot and was hoping to click on the picturebox to zoom. please help.

hi, i want to modify this code a bit and get the picture zoom within picture box please help me out.

mruga | Wed, 02 Jan 2008 22:49:00 GMT |

Quote:
Originally Posted by mruga
hi, i want to modify this code a bit and get the picture zoom within picture box please help me out.
I believe you can do that by simply changing the size of the imagebox control which is displaying the image. As long as the Stretch property is True, the image will change size with it.

killer42 | Wed, 02 Jan 2008 22:50:00 GMT |

Microsoft Visual Basic Hot Answers

Microsoft Visual Basic New questions

Microsoft Visual Basic Related Categories