Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Zooming Using StretchBlt() Function

i'm making an application that works with images. the user has the ability to zoom in and out of the picture. that part's done. the problem is that if the user zooms in too much and the picture gets too big, the next click on the zoom button delays a bit, and the next click delays it even more.

it must the the size of the picture that makes it work slower. is there any other function that might be useful, or do you know any ideas or tips to help the problem? i dont wanna have to limit the amount of clicks on the zoom button. that'd be know...

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Zooming Function In VBA
Is there a way that I can create 2 buttons that will will zoom in on my form. I am using a user form in VBA and about 8,000 people will be using it. Not everyone's screen resolution is the same so I need to create some zoom buttons so they can fit it to their liking. So can I create two buttons: one that will zoom in at increments of 5. and one that will zoom out in increments of 5? What is the code for that. Thank you for your help.

StretchBlt API Function
Hi All,

I have a big problem in using StretchBlt API function.

I wrote a dll that used StretchBlt API function to stretch image.
When I configure this dll as COM+, the stretchBlt API can't call.
It is OK if I don't use COM+.
But I have to use this dll as COM+ according to the design.

Do you have any idea about this problem? How can I solve?

Thanks in Advance,

Replacement StretchBLT By GDI+ Function(s)
I have written a, for me, rather complex program to store, retrieve and manipulate (enlarging, reducing, cutting/pasting parts, colors, etc.) images using many GDI functions. It works fine, apart from StretchBLt, where I miss anti-aliasing. With enlargements the result is poor.

I am looking for the possibility to replace the GDI API's SetStretchBltMode and StretchBLt with self-written functions, which do the same but use GDI+, as I expect that this will improve the resulting images.

However, I get totally lost in the GDI+ documentation and samples on various place on Internet, and I cannot find a starting point .

Can somebody help me?

I'm using vb 6.0. I have a picturebox with a graph in it generated by .Line in a for loop. Anyone know how to zoom in on it? what control would i use? thanx.

I have developed a windows application in vb6 with active-x controls, I need to zoom whole window and wants to operate active-x controls after zooming. Please help me in this regard and I am greatfull to you.

Thanks a lot,

Hello, how can i zoom in/out in a picture box in visual basic 6.0?

Hi all, so I'm still a little new to VB and I have ran into some trouble... I have a form with two picture boxes, the first PicMain is as you would think the main picture and PicTemp is a picture box off to the right of PicMain that I want to show a very slightly zoomed version of an area around where the mouse is. so far I haven't been able to get a good ratio and now I'm having trouble with PicTemp only showing the zoomed area on the lft half of the box. here is the code I have. ( please note that the map uses a reverse X and Y)
Thank you ahead of time for the help!

VB Code:
Sub PicMain_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Text = ("X: " & Int(Y / 5) & "," & "Y: " & Int(X / 5))Pictemp.PaintPicture PicMain.Image, 0, 0, Pictemp.Width, Pictemp.Height, X - 100, Y - 100, 200, 200DoEventsEnd Sub

I want some help about zooming in and zooming out of picture box.

Any ideas? Thanks.

How do I create a zoom feature for my editor?


Zooming In/out On A Map
I would like to zoom in and out of a map on my form. The map is a bitmap. Does anyone knows any way to do so? Any help would be appreciated

I am creating a page preview sort of application.
I am using picture box in that.I want to provide zooming in and zooming out facility for it.Please send me your suggestions about how can I do it? I want text and lines on the document to be zoomed in and out.
Also please suggest if I can use some other object to have this effect.

Zooming My Image
how do i make a zoom to my image on mouse over & i want the
image to change back after the mouse is no longer on the image

GDI Font Zooming
Hi all,

i'm trying to develop some kind of "label editor". A sort of small Word where an user can create customizable label with text, images and shapes.

One of the most important things to implements is the Zoom. I'have encountred some problems when i have to size fonts (fonts created with the API call CreateFont(). When the label is resized by the formula (for eg. Label.Width * ZoomValue / 100) the font is not sized correctly. If I try with Font.Size * ZoomValue / 100 sometimes font size don't match with the label size and is renderd too big or too small.

Zooming Forms Using VB 6
We have created a project that displays forms inside of the main parent form. I would like to add zooming functionality like the one that Microsoft Word has for its documents.

Does anyone out there know where I can get such a control? If not how would I code this to display the form at full page, page width and 25%, 50% 75% and 100%.

Any help would be appreciated.

Thank you.

Zooming Bitmaps
I have added a zooming function to my project from a previous thread, and am having some issues.

If I try to zoom by a factor greater than 9, I get the following error:

Cant Create AutoRedraw Image

I have seen apps zoom in much closer than this, so what am I doing wrong?

Also, if I select another zoom factor and click the Show button, the new zoom
image is not displayed (unless I close the window first).
I tried Image.Refresh in a few different spots, but that did not fix the problem.

I am attaching the project.

Zooming In On A Video
You all seem like inteligent guys, i wonder if you could help me.

I work for a hospitial and review sleeping patterns. Im using the windows media player object to play the video but I need to zoom in on a patients eyes. Can anyone give me a clue on how to do this.

Many thanks:confused

Should Zooming Be This Slow?
In my project, I shrink each level below the curently viewed one so that there is the illusion of depth. I origionaly got 37fps (wich I have plans to improve) but now I get less than one. It now takes around 1800 miliseconds to draw each cycle. Is this normal?

Ive attached the most reacent version of my project and pointed out the part that is giving me problems in the code.

Zooming In 2D Games
I am currently making a 2d space game. The camera should also follow the player, which is easy enough by setting the x and y offsets to the player co-ordinates each frame. I want to be able to zoom in and out so the feild of veiw gets larger and smaller. Currently would acheive this by having a zoom factor, which increases or decreases when I press "+" or "-" and then each object in the game's co-ordinates are multiplied by the zoom factor and the lengths and widths of the ships/planets etc are also multiplied by the zoom factor. The problem using this method is that the zoom always zooms in and out around the point 0,0 even if that point is off screen. I was wondering if there was a tutorial or source code for zooming in a 2d game or just any tips I can use? I am currently usng techniques from this demo of a space battle:

A Little Zooming Math
Well, this KDImage control is working out pretty good so far, however, it has some pretty basic limitations. One of which is a ZoomToSelection method. So, I've attempted to put together one of my own. Although The Image does zoom fairly accurately to the selection, it's a bit off.

My approach was to take the actuall area of the image and compare it to the area of the selection to result in a % of actual area. Then I calculate the current zoom level and attempt to calculate how much I need to adjust that level. Then I would zoom to the center point of the selection with an already existing method called ZoomToPoint.

My goal is to have the selection zoom to fit the current image control.

The code...

Public Sub ZoomToSelection(ByRef kdZoomImage As kdImage)

Dim lngZoomX As Long
Dim lngZoomY As Long
Dim dblZoomWidth As Double
Dim dblZoomHeight As Double
Dim dblZoomLevel As Double
Dim dblImageArea As Double
Dim dblZoomArea As Double

'Get Height and Width of zoom selection
dblZoomWidth = kdZoomImage.SelectionRight - kdZoomImage.SelectionLeft
dblZoomHeight = kdZoomImage.SelectionBottom - kdZoomImage.SelectionTop

'Calculate area of current image and zoom selection
dblImageArea = kdZoomImage.width * kdZoomImage.height
dblZoomArea = dblZoomWidth * dblZoomHeight

'Calculate Zoom Level
dblZoomLevel = kdZoomImage.Zoom + (100 - (dblZoomArea / dblImageArea) * 100)

'Get (X,Y) point to zoom to
lngZoomX = kdZoomImage.SelectionLeft + (dblZoomWidth / 2)
lngZoomY = kdZoomImage.SelectionTop + (dblZoomHeight / 2)

'Remove selection area from image
Call kdZoomImage.SelectionRemove

'Zoom to Selection
Call kdZoomImage.ZoomToPoint(dblZoomLevel, lngZoomX, lngZoomY)
Call StatusBarUpdate(kdZoomImage.Zoom & "%", STATUSBAR.SB_ELAPSEDTIME)

End Sub

Another Zooming Question
I got the zoom to work. Thanks to you guys.

Now I'm curious if there is any way to have it zoom into the region where I click?

Zooming Text

I'm building an app with a printpreview.

The printpreview prints the contents of a RichtTextbox to a PictureBox that was made the exact size of the paper used.

Now I want to be able to zoom.
I have tried the PaintPicture method using the Image of the picturebox, but I can't get it to work. Zooming in is no problem, but zooming out is.

Here is my code, just put it in a form with a commandbutton array and a picturebox.

Option Explicit

Private Sub Command1_Click(Index As Integer)
Dim vImage As IPictureDisp
Dim vZoom As Double
If Index = 0 Then
vZoom = 0.9
vZoom = 1.1
End If
Set vImage = Picture1.Image
Picture1.Width = Picture1.Width * vZoom
Picture1.Height = Picture1.Height * vZoom
Picture1.PaintPicture vImage, 0, 0, vImage.Width * vZoom, vImage.Height * vZoom
Set vImage = Nothing
End Sub

Private Sub Form_Load()
Dim i As Long
For i = 1 To 50
Picture1.Print "Dit is regel " & i
End Sub

Any suggestions?

Zooming An Image
2 questions...

How do I zoom on an image using API?


How do I make a selection on a certain area of the image and zoom that area, just like in photoshop?

Thanks a lot!

Zooming Factor
Got problem here, please help!!!

Do any 1 know how to use an image as a test to testing for zooming. I have problem making zoom 1x as the same with the actual image...

Zooming PictureBox
How can I increase width and height of a picturebox every time I zoom out/in using its scalewidth/scaleheight property so that the entire picture is magnified and is visible i.e. it does not get cut from the right side and How can I scroll through the picture using scroll bars?

Here is my code:

Private Sub ZoomIn_Click()
SH = SH - (100)
SW = SH * 1.61855670103093 'Aspect Ration of my picturebox
End Sub

Private Sub ZoomOut_Click()
SH = SH + (100)
SW = SH * 1.61855670103093 'Aspect Ration of my picturebox
End Sub

Private Sub picMain_Resize()
picMain.ScaleHeight = SH
picMain.ScaleWidth = SW
End Sub

Private Sub Form_Load()
SH = picMain.ScaleHeight
SW = picMain.ScaleWidth
End Sub

Please Help


Image Zooming
I will like to zoom the image in picturebox . is it possible to do so . can somebody help me?....pls

Picture Zooming

I've got an image in a picture box and I need the user to see close up, like 25 pixels squared, around where the cursor is pointing to. Any idea on how to do it? I've tried using the MouseMove event, and getpixel then using bitblt to create the zoomed in image. But it slows down the applictaion greatly. Any ideas??

Oh.. and also how do you convert Inches into pixels?

Thanks a lot

Zooming A Picture
Does anyone know how to zoom (+ or -) a picture in a picture box. Please give me the code.


Zooming A Form

Cam anyone please tell me whether we can zoom a form along with all its controls in VB.NET just as we zoom a page in
MS-Word.If so how to do it.

Thanking U


Zooming TEXT
I have looked all over, and I'm getting really frustrated... I need to know how to zoom TEXT...I've found tons of stuff on how to zoom pictures, but I need to know how to zoom TEXT! And I swear, every thing I download doesn't run right and I have to fix it..and then it ends up not helping me anyway... can some one PLEASE give me some suggestions on how to do this? PLEASE! :-)

Example: I am building presentation software. I want to be able to have a transparent text control over the top of a picture control. (Or in it.) And I can zoom the picture control easily, but now I need to zoom the text control. (label, or whatever, as long as it's transparent, or can have a picture loaded in the background). The idea behind zooming is so I can have an exact replica of the slide, only smaller, for a preview type thing.

Any help would be greatly appreciated.

Image Zooming

suppose one graph/image is there on the VB Form. if u r clicking on particuler point on that graph/image, only that particuler part shuold be zoomed on same graph/image, but remaning part of the graph/image should not be zoomed.

please give the answer.

Get Scrollbars When Zooming
Hi all,

I have implemented a zoom function but can someone
please show me how I can make it so that when the
picture is zoomed in, there are horizontal and vertical
scrollbars around the picture (not the form but the picture).
Can anyone show me an example of how to do this?

Many thanks!

Need Help With Zooming Pictures
I zoom a bmp-file to a pictureBox with the paintPicture function.
If I would like to zoom the picture again I need to do the paintpicture again on the zoomed picture but for that it needs to be an bmp-file, so I would like to save the new zoomed picture as a bmp but I cant. Any ideas? Someone suggested that I could "catch" the new zoomed picture with API but I have never used APIs so Im not used to that. As I said, any suggestions?

Regards Per-Erik

Zooming Images

How can I zoom in and zoom out a loaded image. I am using picture box control and image control to load images on run time. but if there is another control then tell me and if we can zoom in and zoom out the image by using image and picture box controls then please tell me how can i do that.


Nasir Daud Ahmad

Zooming On Picture-Box Please Help!!!
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, _

'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

How To Creat Zooming Vb
hello friends

i have to create tool for zooming in and out for graphics such as line etc.. displayed on picture box in vb. I will have to select some area and zoom it by some percent....
plz help me if someone have some code regarding it

best regards

About Zooming Worksheets And Userform...
Hi there. I want to have the userform1 and the worksheets behind the userform1 zoomed down to the extend that the the size of userform1 is equal to the that of the worksheets behind. I got the following vba code but don't how to zoom the worksheets.

size of userform1 = hight: 417 width:540

Private Sub CommandButton1_Click()
? Application.Width = 540
? Application.Height = 417


Picturebox Zooming Problem
now I have problem to your code when i set picturebox picture
zoom in or zoom out picture is apply for picturebox

I am try to this same code

Private Const ZoomFactor As Single = 0.05
Private mPicture As Picture
Private lPercent As Single

Private Sub Command1_Click()
ResizePicture 1 'Zoom in
End Sub

Private Sub Command2_Click()
ResizePicture 2 'Zoom out
End Sub

Private Sub Form_Load()
lPercent = 1
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = False

'Save the picture with its real size
Set mPicture = Picture1.Image
End Sub

Private Sub DrawSomething()
'Picture1.FillStyle = 0
'Picture1.DrawWidth = 2
'Picture1.FillColor = vbBlue
'Picture1.Line (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight), vbWhite, B
'Picture1.FillColor = vbWhite
'Picture1.Circle (Picture1.ScaleWidth / 2, Picture1.ScaleHeight / 2), 100
'Picture1.FillColor = vbYellow
'Picture1.Circle (Picture1.ScaleWidth / 2, Picture1.ScaleHeight / 2), 50
Picture1.Picture = LoadPicture("C:Status Screen Creation ToolStatus_Dispicondeepavali.jpg")
End Sub

Private Sub ResizePicture(pZoom As Integer)
With Picture1
If pZoom = 1 Then
lPercent = lPercent + ZoomFactor
If lPercent - ZoomFactor > 0 Then lPercent = lPercent - ZoomFactor
End If
'Zoom centered
.PaintPicture mPicture, .ScaleWidth / 2 - .ScaleWidth / 2 * lPercent, _
.ScaleHeight / 2 - .ScaleHeight / 2 * lPercent, _
.ScaleWidth * lPercent, .ScaleHeight * lPercent
End With
End Sub

I want orignal picture only zoomin and zoom out

how can i do ? explain me.

Handling Pictureboxes And Zooming
I have created a picture box(picture1) which will load an image. Within this picture box i have another smaller one (picture2) which is set to be background as transparent (still figuring out how to do this one from the other posts) and would like to move this small picbox with my mouse arnd and within the larger one. When click,that area within the small picbox would displayed like a zoom version enlarged in a new display(picture3).I understand theres many threads on this but Im not still not quite sure how to go about this. Ive never used APIs and strechblt as well. So if anyone could give me some pointers that would be great


Smooth Picture Zooming
Hi all;

I am trying to make smooth picture zoom, but i have a problem with program that i can't find. It seems everything is ok but nothing happens when i run it.

I took this code from forum and i have not enough information about API therefore i could not suggest the mistake, code attached.

in my program there is a slider for zoom, when it changed picture must get enlarged but it doesn't work

Any idea?

Zooming Vs. Resizing An Image
hello everybody

I am a fairly new user of VB, and I have a problem I am trying to figure out.

I have a form with a window that allows me to view an image. When I place my cursor over a point in the window, the program shows the coordinates of that pixel. However, when I zoom in the image, the coordinates of that pixel have now changed. It is now showing the same window coordinates as before (coordinates of the window, not the image). How can I make it so that the coordinates of the image stay the same no matter how I view the image.

For example, when you open up MS Paint and you make an "X" the coordinates of the vertex is say 200,200. and when you zoom into the image, the coordinates have now changed to 210,210. This is not what I want. I want it to be 200,200, no matter how much I zoom in or out, or move left and right

Any help would greatly be appriciated

is it become the program is resizing the image and not zooming?

Picturebox Zooming And Scrolling
What's up?

I was wondering if there was any code out there that allows me to zoom into a picture in a picturebox, and then adjust the vertical or horizontal scrollbars so that if I click on the "zoom in" or "zoom out" button, it will zoom to the middle of the image based on the values of the scrollbars?

Thanks in advanced


Zooming Picture In Picturebox

i want to zoom the picture in picturebox.
please send me code.
try to zooming picture without resizng the picturebox

Zooming Picture In Picturebox
I am making a project of image editor like corel draw.I have a problem of zooming picture in picturebox.I have a solution by using "Streathblt" function.But i want other idea of that.

Printing Picture Box And Zooming
Been trying to find an example programe that shows you how to print the contents of a pictureBox, portrait, landscape, zoom in/out etc for VB5 does anyone have an example of this or point me in the right direction?



Zooming In With PictureBox Control
I am trying to zoom in and out.
I placed Pict2 (which holds the drawing) on top of Pict1
On the side I placed a frame with 3 option buttons, In, Out, and Original.
When you click on Pict2 you zoom according to the option buttons. The zoom
increment is 0.25 whether going in or out. The Max zoom out is 0.25.

I have no trouble zooming out, or back to original. I can zoom back in the
3 steps from 0.25 back to 1.0. But I can't properly figure out zooming in.
If I don't keep the entire picture available via scroll bars, I can zoom in
forever. But I want to keep the entire picture available, and there I am
getting lost.

Any suggestions?

The sub is below



Private Sub Pict2_Click()
'Will Zoom In/Out here
Static dblScale As Double, intCount As Integer
Static oTop As Double, oLeft As Double, oWidth As Double, oHeight As
Static nTop As Double, nLeft As Double, nWidth As Double, nHeight As
If intCount = 0 Then
dblScale = 1
oTop = Pict2.Top
oLeft = Pict2.Left
oWidth = Pict2.Width
oHeight = Pict2.Height
End If
If (optIn = True) Then

VEDrawPass.Pict2.ScaleLeft = (VEDrawPass.Pict2.ScaleLeft * (dblScale
+ 0)) / (dblScale + 0.25) 'dblX1
VEDrawPass.Pict2.ScaleWidth = -VEDrawPass.Pict2.ScaleLeft * 2
'dblX1 * -2
VEDrawPass.Pict2.ScaleTop = VEDrawPass.Pict2.ScaleTop * (dblScale +
0) / (dblScale + 0.25)
VEDrawPass.Pict2.ScaleHeight = (-VEDrawPass.Pict2.ScaleTop * 2)
'-VEDrawPass.Pict2.ScaleHeight * dblScale / (dblScale - 0.25) '-dblY2 * 2

VEDrawPass.Pict2.Left = -10 'VEDrawPass.Pict2.Left * dblScale
VEDrawPass.Pict2.Top = 10 'VEDrawPass.Pict2.Top * dblScale
VEDrawPass.Pict2.Height = 20 'VEDrawPass.Pict2.Top * 2
VEDrawPass.Pict2.Width = 20 '-VEDrawPass.Pict2.Left * 2

dblScale = dblScale + 0.25
VEDrawPass.lblScale = Format(dblScale, "#0.00")
End If

If (optOut = True) And (dblScale > 0.25) Then
VEDrawPass.Pict2.ScaleLeft = VEDrawPass.Pict2.ScaleLeft * dblScale /
(dblScale - 0.25) 'dblX1
VEDrawPass.Pict2.ScaleWidth = VEDrawPass.Pict2.ScaleWidth * dblScale
/ (dblScale - 0.25) 'dblX1 * -2
VEDrawPass.Pict2.ScaleTop = VEDrawPass.Pict2.ScaleTop * dblScale /
(dblScale - 0.25)
VEDrawPass.Pict2.ScaleHeight = -VEDrawPass.Pict2.ScaleTop * 2
'-VEDrawPass.Pict2.ScaleHeight * dblScale / (dblScale - 0.25) '-dblY2 * 2
'VEDrawPass.Pict2.Width = VEDrawPass.Pict2.Width +
(VEDrawPass.Pict2.Width * 1.25) '/ (dblScale + 0.25)
'VEDrawPass.Pict2.Height = VEDrawPass.Pict2.Height +
(VEDrawPass.Pict2.Height * 1.25) '/ (dblScale + 0.25)
dblScale = dblScale - 0.25
VEDrawPass.lblScale = Format(dblScale, "#0.00")
End If
intCount = intCount + 1 ' want to reset if going to 1
If optOriginal = True Then
dblScale = 1#
VEDrawPass.lblScale = Format(dblScale, "#0.00")
intCount = 0
End If

Call DrawSizeSectionRJH(viewSizing.MSFlexGridSizeTab0.Co l)

VEDrawPass.lblTop = Format(VEDrawPass.Pict2.Top, "#0.000")
VEDrawPass.lblLeft = Format(VEDrawPass.Pict2.Left, "#0.000")
VEDrawPass.lblHeight = Format(VEDrawPass.Pict2.Height, "#0.000")
VEDrawPass.lblWidth = Format(VEDrawPass.Pict2.Width, "#0.000")
VEDrawPass.lblSTop = Format(VEDrawPass.Pict2.ScaleTop, "#0.000")
VEDrawPass.lblSLeft = Format(VEDrawPass.Pict2.ScaleLeft,
VEDrawPass.lblSHeight = Format(VEDrawPass.Pict2.ScaleHeight,
VEDrawPass.lblSWidth = Format(VEDrawPass.Pict2.ScaleWidth,

End Sub

,"Visit Our Website: http:\

Zooming To A Rectangle Of A Picture
Hi All,

been trying to zoom to a selection of a picture.

Function should go like:

1) User drag's mouse (rectangle)
2) Picture zoom's in to rectangle

Searching around i could not find much on this subject.
Also been looking for functions like Realtime Pan and Realtime Zoom.

Realtime Pan --> Mousedown + Mousemove
Realtime Pan --> Mousedown(right or left) + Mousemove (right is zoom out, left is zoom in)

Anybody any tips regarding these subjects?



Zooming Select Area

Please give me any idea how to zoom a selected area in the image of imagebox control. that mean by using mouse.


Zooming A Selected Area
thank you that you have provided me with a very good zooming application i have modified it and used it by using command buttons instead of scroll bars. Now I want that only selected area of the image is zoomed in. Please give me guidelines. I will be thankful


Copyright 2005-08, All rights reserved