Home » Category » Microsoft Visual Basic

Microsoft Visual Basic: Zooming On Picture-Box Please Help!

202| Fri, 08 Feb 2008 04:41:00 GMT| eladgr| Comments (3)
Hi Everybody,

I am trying to zoom on a picturebox . I've got a rectangle that the user selects a bitmap region with, and I want to zoom on it using the Bitblt and Stretchblt APIs.I've got 2 picture-boxes: I try to copy the selected region into a device-context using CreateCompatibleDC, and then reload it into the second picture-box using stretchblt. The problem is, that my code does'nt work.

Thanks to anyone who could have a look and tell me what am I doing wrong?

Here's the code:
Private Sub Zoom_On_Selection(Src As PictureBox, Tgt As Picturebox, Left As Long, Top As Long, Width As Long, Height As Long)

Dim hMemoryDC As Long
hMemoryDC = CreateCompatibleDC(Src.hdc)

'use bitblt to copy a rectangle of the source picturebox to the temporary gdi object

ret = BitBlt(hMemoryDC, 0, 0, Width, Height, Src.hdc, Left, _
Top, SRCCOPY)

'now, put it back into the second picturebox, Tgt
ret = StretchBlt(Tgt.hdc, 0, 0, Tgt.Width * 3.8, Tgt.Height * 3.8, _
hMemoryDC, 0, 0, Src.Width * 3.8, Src.Height * 3.8, SRCCOPY)

End Sub

Keywords & Tags: zooming, picture-box, microsoft, visual basic, vb

URL: http://www.programmerbase.com/visual-basic/560804/
 
«« Prev - Next »» 3 helpful answers below.
I think this may help:

Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As
Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long,
ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long,
ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As
Long, ByVal dwRop As Long) As Long

Private Sub Command1_Click()

Picture2.Cls

Picture1.Picture = LoadPicture("test.jpg")

StretchBlt Picture2.hdc, 0, 0, Picture2.Width, Picture2.Height,

Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, vbSrcCopy

SavePicture Picture2.Image, "C:test2.jpg"

End Sub

By the way, Do check that your mode is set to VBPixels. As all API's use Pixels as standard.

Happy Programming,

myMessage: Pray For Peace

neagle | Fri, 09 Nov 2007 23:57:00 GMT |

I think this may help:

Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As
Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long,
ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long,
ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As
Long, ByVal dwRop As Long) As Long

Private Sub Command1_Click()

Picture2.Cls

Picture1.Picture = LoadPicture("test.jpg")

StretchBlt Picture2.hdc, 0, 0, Picture2.Width, Picture2.Height,

Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, vbSrcCopy

SavePicture Picture2.Image, "C:test2.jpg"

End Sub

By the way, Do check that your mode is set to VBPixels. As all API's use Pixels as standard.

Happy Programming,

myMessage: Pray For Peace

neagle | Fri, 09 Nov 2007 23:58:00 GMT |

You need to also create a bitmap in memory, using CreateCompatibleBitmap, to manipulate the bitmap in memory. You may also need to use SetStretchBltMode (with a value of 4). Copying directly from picturebox to picturebox will not require the same calls, and in fact, you can do the zoom without API, although I would anyway.

wizbang | Fri, 09 Nov 2007 23:59:00 GMT |

Microsoft Visual Basic Hot Answers

Microsoft Visual Basic New questions

Microsoft Visual Basic Related Categories