dcsimg
Results 1 to 7 of 7

Thread: StretchBlt Problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2017
    Posts
    464

    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.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,081

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2017
    Posts
    464

    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.

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,138

    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.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,119

    Re: StretchBlt Problem

    Quote Originally Posted by Code Dummy View Post
    ...
    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2017
    Posts
    464

    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.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,119

    Re: StretchBlt Problem

    Quote Originally Posted by Code Dummy View Post
    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width