|
-
Dec 22nd, 2001, 05:15 AM
#1
Thread Starter
Fanatic Member
Anyone?? How does StretchBlt work?
Hello,
I need to resize an image to the size of a picturebox (or anything else) and then save it in that size, not in jpg, gif or whatever just bmp.
I have search through old threads, but didn't find a real answer...
I know it is possible with StretchBlt, but how??
Thanx in advance.
Last edited by arsmakman; Dec 22nd, 2001 at 05:31 AM.
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Dec 22nd, 2001, 05:32 AM
#2
Thread Starter
Fanatic Member
Hello?
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Dec 22nd, 2001, 07:22 AM
#3
Thread Starter
Fanatic Member
Why won't anyone explain StretchBlt to me?
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Dec 22nd, 2001, 11:16 AM
#4
Addicted Member
I have never used that api nor do I know how it works, but I would suggest searching http://www.vbapi.com or http://www.pscode.com. Search on these and see what you find.
Patience and perserverence have a magical effect before which difficulties disappear and obstacles vanish.
John Quincy Adams
-
Dec 22nd, 2001, 11:53 AM
#5
We had a long discussion about StretchBlt once in this forum (it must be a couple of years ago ) and, believe it or not, we found out that using PaintPicture is faster.
(Just because I mention it this thread will probably turn into a new long discussion about this fact but guys try it and you'll see).
The regular BitBlt is much faster though.
Anyway to answer your question I will show you both StretchBlt and PaintPicture.
To use the API you first have to declare it
VB Code:
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
Now, not to make this post to long just try the following:
Put the above declaration in the General Declaration section of a Form.
Add two picture boxes to that form.
One of the picture boxes we will use to load the image in it's normal size and format.
This picturebox don't have to be visible so set the Visible property to False.
It must resize though to the same size as the image we load into it so set the AutoSize property to True.
Also since the StretchBlt function uses Pixels as messurment set the ScaleMode property of both PictureBoxes to vbPixels.
The second PictureBox we use to resize the image.
So size it to any size you like.
Now since we're going to draw at it set the AutoRedraw property to True.
If you forgot it or didn't read it a few lines above: Make sure the ScaleMode property is set to Pixels.
Now in the code I'm using I've named the PictureBoxes to picOriginal and picStretch (guess which is which )
In this example I use the Click event of a CommandButton to do the stretch and save...
VB Code:
Private Sub Command1_Click()
picOriginal.Picture = LoadPicture("c:\ThePic.gif") 'or any supported picture format
With picStretch
StretchBlt .hdc, 0, 0, .ScaleWidth, .ScaleHeight, _
picOriginal.hdc, 0, 0, _
picOriginal.ScaleWidth, picOriginal.ScaleHeight, _
vbSrcCopy
.Refresh
End With
SavePicture picStretch.Image, "c:\stretchImage.bmp"
End Sub
And there you go....
If you would like to test the PaintPicture function instead simply change the code in the Command1_Click event to this:
VB Code:
Private Sub Command1_Click()
picOriginal.Picture = LoadPicture("c:\ThePic.gif") 'or any supported picture format
With picStretch
.PaintPicture picOriginal.Picture, 0, 0, .ScaleWidth, .ScaleHeight, _
0, 0, picOriginal.ScaleWidth, picOriginal.ScaleHeight, _
vbSrcCopy
.Refresh
End With
SavePicture picStretch.Image, "c:\stretchImage.bmp"
End Sub
and if you use the PaintPicture method you don't need the API declaration.
Best regards
-
Dec 23rd, 2001, 01:41 AM
#6
Thread Starter
Fanatic Member
These codes don't work... 
They give no image and saves a picture of an empty picturebox.
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Dec 23rd, 2001, 03:39 AM
#7
Set the AutoRedraw property of picOriginal to True as well and it will work.
Best regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|