-
Feb 11th, 2019, 04:19 PM
#1
Thread Starter
Fanatic Member
StretchBlt Problem
I have two Picturebox controls. One in called Picture1 and it only has a black background. It's AutoRedraw property is False. The other one is called Picture3 and it has an image in it and it is also set to AutoRedraw = False
Both Pictureboxes are set to ScaleMode = 3 (Pixel)
Both Pictureboxes are completely visible and are shown on the Form
The code is simple:
Code:
Private Declare Function StretchBlt& Lib "gdi32" (ByVal hdc&, ByVal x&, ByVal y&, ByVal nWidth&, ByVal nHeight&, ByVal hSrcDC&, ByVal xSrc&, ByVal ySrc&, ByVal nSrcWidth&, ByVal nSrcHeight&, ByVal dwRop&)
Private Sub Command1_Click()
StretchBlt Picture1.hdc, 0, 0, Picture1.Width, Picture1.Width, Picture3.hdc, 0, 0, Picture3.Width, Picture3.Height, vbSrcCopy
End Sub
When I click on Command1 no picture is copied to Picture1
EDIT:
Here is something very strange. I have another VB project which has two picture boxes. Picture1, the destination, has it's AutoRedraw property set to True and Picture2, the source, has it's AutoRedraw property set to False. When I click on the button it copies from Picture2 to Picture1. After the Picture1.Refresh you can see the copied picture in Picture1.
Now if I set Picture1 AutoRedraw to True in my problem project I get an error saying Runtime error 480 Can't create AutoRedraw image
Last edited by Code Dummy; Feb 11th, 2019 at 04:51 PM.
-
Feb 11th, 2019, 04:49 PM
#2
Re: StretchBlt Problem
Assign the destination's AutoRedraw = True, then paint, then assign AutoRedraw = False.
The PaintPicture method will do a StretchBlt so there is rarely any need to deal with the API and the problematic logical units (vbPixels) for ScaleMode. The physical unit vbTwips is the default for very good reasons.
-
Feb 11th, 2019, 05:15 PM
#3
Thread Starter
Fanatic Member
Re: StretchBlt Problem
Same problem as above: Runtime error 480 Can't create AutoRedraw image
I don't think using Paint instead of StretchBlt changes anything since I have other projects using StretchBlt without any problems so it must have something to do with the project I'm working on.
-
Feb 11th, 2019, 05:35 PM
#4
Re: StretchBlt Problem
Yes, that seems odd. You would normally get that error if the picturebox was really large, I think I've gotten it with a picturebox more than 32000 pixels wide. There indicates there isn't enough available memory for the AutoRedraw property to be set to True.
Perhaps, if you have other huge memory resource taken up in your application such as large multi-dimensional arrays, then the application is running out of memory so can't allocate the back buffer.
Of course, if you have AutoRedraw set to False for both pictureboxes, the bitblt is just copying from one area of the screen to the other (the area "above" one picturebox, to the area "above" the other picturebox).
In that case, you need to ensure you are not doing an invalidate or refresh call on the destination picturebox, or the update of the picturebox will wipeout what you just bitblted.
p.s. What dilettante is suggesting, setting AutoRedraw to True, then bitbliting, and setting AutoRedraw back to False, makes the drawing persistent, not a screen to screen copy. Of course, if you can't set AutoRedraw to True, you have a problem.
Last edited by passel; Feb 11th, 2019 at 05:39 PM.
-
Feb 12th, 2019, 08:41 AM
#5
Re: StretchBlt Problem
Originally Posted by Code Dummy
...
Both Pictureboxes are set to ScaleMode = 3 (Pixel)
Code:
Private Sub Command1_Click()
StretchBlt Picture1.hdc, 0, 0, Picture1.Width, Picture1.Width, Picture3.hdc, 0, 0, Picture3.Width, Picture3.Height, vbSrcCopy
End Sub
The picboxes scalemode may be pixels but what is the form's scalemode? You are using the Width/Height of the picboxes which will be in their container's scalemode. If wanting to use the picbox scalemode, use ScaleWidth/ScaleHeight instead
-
Feb 12th, 2019, 11:31 AM
#6
Thread Starter
Fanatic Member
Re: StretchBlt Problem
Form is Pixel.
I noticed that everytime I close out the project and then restart it the problem goes away but after awhile it returns. I'm beginning to think what passel said about not enough memory.
Last edited by Code Dummy; Feb 12th, 2019 at 11:36 AM.
-
Feb 12th, 2019, 12:32 PM
#7
Re: StretchBlt Problem
Originally Posted by Code Dummy
Form is Pixel.
I noticed that everytime I close out the project and then restart it the problem goes away but after awhile it returns. I'm beginning to think what passel said about not enough memory.
Hmmm, whenever I see a statement like "works then doesn't work after awhile", my first thought is always: memory leaks in the application.
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
|