dcsimg
Results 1 to 40 of 40

Thread: StretchBlt vs Enlarging Image Control

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    StretchBlt vs Enlarging Image Control

    I have a Picturebox with an image in it. I also have an Image Control with the same image in it. Both the Picturebox and Image Control are 25 x 25.

    I use StretchBlt to enlarge the picture in Picture1 to Picture2 to 400 x 400. The enlarged picture looks terrible because of the jagged edges. But if I enlarge the same picture in the Image Control by stretching it's width and height to 400 x 400 the enlarged picture looks extremely smooth, no jagged edges.

    So, my question is what does the Image Control do differently when enlarging a picture than the StretchBlt does.

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

    Re: StretchBlt vs Enlarging Image Control

    Even without SetStretchBltMode, I haven't noticed dramatic rendering quality between StretchBlt (better: yes, dramatic: no) and that of an image control with Stretch property set to true. From the description you provided, almost sounds like the image control is using bicubic rendering (extremely smooth edges) where StretchBlt uses nearest-neighbor (jagged edges).

    In the screenshot below (resized by the forum), the images look identical. Left side is the image control, the right side is a picturebox rendered with StretchBlt w/o SetStretchBltMode.

    Image source is 61x61 and stretched to 488x488

    By chance, are you using that class of mine from your "Orbiting Balls" thread?

    Name:  SShot2.jpg
Views: 191
Size:  20.2 KB
    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}

  3. #3
    Fanatic Member
    Join Date
    Dec 2014
    Posts
    810

    Re: StretchBlt vs Enlarging Image Control

    windows 10 has gdi scaling functions right? maybe its not the image control but windows 10 that do the scaling while the other is the stretchblt

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    Don't know about image control using bicubic rendering (extremely smooth edges). All I know is I put the image (bmp) in a picturebox and the same image in an Image Control. I stretch both. For the bitmap picture in the picturebox I use StretchBlt and for the picture in the Image Control I just increase the size of the control. When the pictures get bigger the picturebox is jagged but the Image Control is smooth (just as smooth as the original picture).

    No, I am not using your class. This is a game I am working on and all the code is what I write.

    I will play around with what dile suggested by using SetStretchBltMode(). and see what happens.

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

    Re: StretchBlt vs Enlarging Image Control

    So, when you use StretchBlt which image handle are you putting into the source hDC? Is it the image control's picture handle or is it the picturebox's .Image property's handle or the .Picture property's handle. I'm wondering if you may be resizing a rendered image vs rendering from a static image. In other words, if you resize something, then resize that result again, and that new result again and so on -- the quality will be horrific. But if you use the same unchanged image handle every time, you should get better results.

    If you are willing the share the bitmap, I'd like to try to replicate the problem.
    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
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    Quote Originally Posted by LaVolpe View Post
    So, when you use StretchBlt which image handle are you putting into the source hDC? Is it the image control's picture handle or is it the picturebox's .Image property's handle or the .Picture property's handle.
    Code:
     dW = dW + 5
     dH =  dH + 5
    
     StretchBlt(Picture2.hDC, 0, 0, dW, dH, _
                Picture1.hDC, 0, 0, Picture1.Width, Picture1.Height, _
                vbSrcCopy)
    Quote Originally Posted by LaVolpe View Post
    I'm wondering if you may be resizing a rendered image vs rendering from a static image. In other words, if you resize something, then resize that result again, and that new result again and so on -- the quality will be horrific. But if you use the same unchanged image handle every time, you should get better results.
    Am I not resizing the original.
    Last edited by Code Dummy; Feb 12th, 2019 at 06:04 PM.

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

    Re: StretchBlt vs Enlarging Image Control

    Am I not resizing the original.
    Should be if Picture1 is 25x25 and AutoRedraw=True and the original 25x25 image was drawn on to it. But without more details how Picture1 was setup, can't answer for sure. Also, I'm guessing you are clearing/erasing Picture2 before rendering?

    There is a better way to do this if you only want to render a single picture vs an entire hDC. You use the image's Render method.

    For this example, the picture to be rendered is loaded into a Image/PictureBox control or a stdPicture object, i.e.,
    Dim thePic As StdPicture: Set thePic = LoadPicture(...)

    Code:
     Dim X As Single, Y As Single ' left/top respectively
    Dim cX As Single, cY As Single  ' width/height respectively
    
    ' swap Image1.Picture below with a stdPicture object if you chose that route
    
    cX = Picture1.Width ' assuming picture1 parent's scalemode is pixels
    cY = Picture1.Height ' X,Y,cX,cY must be in pixels only, not twips or anything else
    
    With Image1.Picture
        .Render (Picture2.hDC), X, Y, cX, cY, 0!, .Height, .Width, -.Height, ByVal 0&
    End With
    Last edited by LaVolpe; Feb 12th, 2019 at 06:19 PM.
    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}

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    I tried your approach but it doesn't improve on the flicker. As far as smooth edges are concerned I did a little experimenting and I found that if I start out with a small image loaded into the Image Control then using a timer and increase the width and height of the control on each timer event the edges start to appear jagged as the image get bigger and bigger. However, if I load an image that is as big as I want to get into the Image Control then start out with the Image Control as a small square then increase it on each timer event the image doesn't get jagged edges as it gets bigger and bigger

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

    Re: StretchBlt vs Enlarging Image Control

    What size is the actual image, as shown in the file properties? Flicker is a different issue altogether
    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}

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    Quote Originally Posted by LaVolpe View Post
    What size is the actual image, as shown in the file properties? Flicker is a different issue altogether
    I have the same picture in two .gif files. One file is small 25 x 25 and the other is large 500 x 500.

    If I use the small file and gradually increase it up to the max size I want in my project about 700 x 700 it gets highly jagged edge when it starts to get around 100 x 100 and bigger the jagged edges become more and more obvious. Now on the other hand if I start out with the big gif image but make the Image Control small (25 x 25) and enlarge it's width and height the picture stays smooth even up to the 700 x 700 max size in my project. So, I am convinced to use a large image as opposed to a small image.

    Now, I need to find a way to avoid the flicker especially as the picture gets bigger and bigger. I'm sure there are other ways to do what I am doing with Image Controls but it seems that using Image Controls is the easiest because it is easy to move them around while increasing their sizes. No need to erase and redraw. Moving them around does not cause a problem; just resizing them causes the flickering.

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

    Re: StretchBlt vs Enlarging Image Control

    That was what I was thinking. To say that the image control was nice & smooth was misleading. Even at 400x400, you are not increasing the size of the base image (500x500). Reducing size scales/draws better than increasing. If you were to put that 25x25 picture in the image control and stretch it to 400x400, you should get the jaggies.

    Recommendation. Use larger image and scale down instead of using smaller image and scaling up.

    Edited: Just for clarification. If you have a 500x500 picture inside an image control stretched to 25x25, the image isn't 25x25. It is still 500x500 scaled down to 25x25. So when you then stretch the image control to 400x400, you are still reducing the 500x500 to 400x400
    Last edited by LaVolpe; Feb 12th, 2019 at 10:09 PM.
    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}

  12. #12
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: StretchBlt vs Enlarging Image Control

    Quote Originally Posted by Code Dummy View Post
    I have a Picturebox with an image in it. I also have an Image Control with the same image in it. Both the Picturebox and Image Control are 25 x 25.

    I use StretchBlt to enlarge the picture in Picture1 to Picture2 to 400 x 400. The enlarged picture looks terrible because of the jagged edges. But if I enlarge the same picture in the Image Control by stretching it's width and height to 400 x 400 the enlarged picture looks extremely smooth, no jagged edges.

    So, my question is what does the Image Control do differently when enlarging a picture than the StretchBlt does.
    So, you didn't really have the same image, you had a larger image in the Image Control.
    Despite the name, i.e. StretchBlit, you can resize in both directions, i.e. the stretch can actually be a shrink if you start with a larger image and blit to a smaller area.

    An image control will always tend to flicker since it is a lightweight control, so isn't its own window. It has to draw on its container, which means it is being drawn on the screen while you watch. And since it has to redraw the background of the container it is in, you often catch it in the process of being drawn as it first erases the previous version of itself, restoring the background, then redrawing itself on top.

    A picturebox is its own window, so it can be doubled buffer, so you don't see the drawing process. And even it if isn't double buffered, it doesn't have to draw draw the background of the container within its borders, first, before drawing itself.

    I don't know what your game needs are, but for most games, I would double-buffer the whole drawing area, and draw the whole thing in the backbuffer and then refresh the whole scene at once.

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

    Re: StretchBlt vs Enlarging Image Control

    Quote Originally Posted by Code Dummy View Post
    Now, I need to find a way to avoid the flicker especially as the picture gets bigger and bigger. I'm sure there are other ways to do what I am doing with Image Controls but it seems that using Image Controls is the easiest because it is easy to move them around while increasing their sizes. No need to erase and redraw. Moving them around does not cause a problem; just resizing them causes the flickering.
    As passel mentioned... Common way is to use an offsreen buffer, draw your updates to that and then either copy the entire buffer to your display, or just affected portions. On slower PCs (remember those?), flicker is even worse.

    However, don't know if this hack is still legitimate and works as it did in older systems. The idea was to have Windows do the buffering for us, at the form level. This was achieved by adding, to the form, the extended window style bit: WS_EX_LAYERED. Then calling SetLayeredWindowAttributes setting form opacity to 99%. Once SetLayeredWindowAttributes is called, supposedly Windows draws the form in a buffer then updates the screen. So most/all of that flickering occurs off-screen. Anyway that was a hack for XP/Win2K times. But he standard workaround is to do the buffering yourself.
    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}

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    Well, I have decided not to pursue this approach anymore as I can now see that it is not going to get me where I want without the curse of flickering so I have decided to take advantage of your pretty Form project. Maybe there I will learn a few things about buffering.

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

    Re: StretchBlt vs Enlarging Image Control

    Note that that project uses backbuffers. If I were to actually load the PNGs into the image controls, I would get flickering too as they moved around the form. In any case even with images having transparency, flicker can be even worse if any images happen to overlap because that causes multiple images to repaint their backgrounds.
    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}

  16. #16
    Fanatic Member
    Join Date
    Dec 2014
    Posts
    810

    Re: StretchBlt vs Enlarging Image Control

    remember that u can use direct2d, u can use linear interpolation for the resize mode, u dont need to think about buffering and direct2d can control dpi.

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    I'm playing around with your pretty Form project. One thing I am having trouble with is resizing the sun. From looking at the code in PlotPlanets where you render the sun...
    Code:
       '
       '
       '
    With mSun
      Cx = .radSelf + .radSelf
    
      .Picture.Render (mDC), CtrX - .radSelf, CtrY - .radSelf, Cx, Cx, _
                       0, .Picture.Height, .Picture.Width, -.Picture.Height, ByVal 0
    End With  
       '
       '
    I'm assuming that Cx is the size of the rectangle (.radSelf + .radSelf or radius of itself x 2) that holds the picture of the sun. So, it appears to me that to increase the size of the sun all I have to do is add a value to Cx to make the sun bigger and then reduce the X and Y by the same value.

    So I do this: (variables already defined)

    NewCx = NewCx + 2 increase the diameter by 2

    Cx = .radSelf + .radSelf + NewCx

    NewCtrX = NewCtrX + 2
    NewCtrY = NewCtrY + 2

    .CtrX - .radSelf - NewCtrX
    .CtrY - .radSelf - NewCtrY

    .Picture.Render (mDC), CtrX, CtrY, Cx, Cx, _
    0, .Picture.Height, .Picture.Width, -.Picture.Height, ByVal 0

    OK, the sun gets bigger as expected but the x and y doesn't work. As the Sun gets bigger it moves diagonally across the screen. I would have expected the location of the sun would stay centered. What am I doing wrong.

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

    Re: StretchBlt vs Enlarging Image Control

    To resize the sun, resize the top image control in the form.

    To try to answer your question
    .radSelf is 1/2 the width or height (square). So if you are going to try to increase Cx, make .radSelf = Cx/2 (radius)

    CtrX and CtrY are the center points to render the center of the sun to. So you want the center of the sun (Cx/2 which is also .radSelf) centered on Cx. The left edge of the sun will be CtrX - .radSelf
    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}

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    OK, about resizing the image control I made this little routine using your code

    Code:
    Private Sub PlotPlanets()
      '
      '
      '
     With mSun
       ResizeSun
    
       Cx = .radSelf + .radSelf
     
      .Picture.Render (mDC), CtrX - .radSelf, CtrY - .radSelf, Cx, Cx, _
                            0, .Picture.Height, .Picture.Width, -.Picture.Height, ByVal 0
     End With
       '
       '
    End Sub
    
    Private Sub ResizeSun()
     Dim tPic As StdPicture  
     Dim tScale As Double
    
     spSun.Width = spSun.Width + 1 
     spSun.Height = spSun.Height + 1 
    
     tScale = 0.95            
    
     With mSun
       .radSelf = (spSun.Width / 2) * tScale
       Set tPic = cPics.LoadPictureEx(App.Path & "\Planets\Sun.png")
       Set .Picture = cPics.CopyStdPicture(tPic, spSun.Width * tScale, spSun.Height * tScale)
     End With
     
     Set tPic = Nothing
    End Sub
    It works fine. The only drawback is I have to reload the Sun.png each time

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

    Re: StretchBlt vs Enlarging Image Control

    No. You can load it one time, full image size. You'll notice in the routine where they are loaded, I call a method to resize the images to the size that would be used in the program. This was to speed up rendering since we wouldn't need to be scaling the image every time it is rendered.

    Simply modify the lines in that pvResetScreen routine as follows or in Form_Load if using an older version of the project:
    Code:
    ' From
    ...
            Set tPic = cPics.LoadPictureEx(App.Path & "\Planets\Sun.png")
            Set .Picture = cPics.CopyStdPicture(tPic, spSun.Width * tScale, spSun.Height * tScale)
    ...
    
    ' To
            Set .Picture = cPics.LoadPictureEx(App.Path & "\Planets\Sun.png")
    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}

  21. #21
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,230

    Re: StretchBlt vs Enlarging Image Control

    Not to horn in because this is not my area of expertise, but I'm not seeing terrible flicker even if I fullscreen this demo:

    Name:  sshot.png
Views: 124
Size:  5.2 KB

    But maybe this is too simplistic to encounter it?


    Sorry, still some glitches in the animation logic related to Form resizing even after fiddling with it. But that wasn't really the point anyway. Feel free to fix it if you care.
    Attached Files Attached Files
    Last edited by dilettante; Feb 15th, 2019 at 12:09 AM. Reason: Fixed Form resize, added a cat

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

    Re: StretchBlt vs Enlarging Image Control

    dilettante, he was using image controls. At least that is the way I interpreted him.

    I'd imagine if you add a GIF to an Image control and move it around at intervals less than full width/height of the control (i.e., small intervals), at a speedy rate, you might see flickering.
    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}

  23. #23
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,230

    Re: StretchBlt vs Enlarging Image Control

    Sorry, I thought you had talked him out of that.

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

    Re: StretchBlt vs Enlarging Image Control

    Quote Originally Posted by dilettante View Post
    Sorry, I thought you had talked him out of that.
    Think he talked himself out of it. What he's talking about now is an option I presented in his "Orbting Balls" thread last week. That option uses backbuffers like many animation routines. Now, I think he's trying to figure out how to adjust the logic to fit his needs.
    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}

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    OK, I tried your suggestion about loading the image only once. Works great. Something really bizarre is happening however. I have two buttons on the Form; one is for enlarging the sun ball and the other is for reducing it. When I run the project everything is normal. The sun is on the stary background which covers the Picturebox completely. By default the sun gets bigger and bigger by a factor of 1. If I allow the sun to get really big, like as big as the Form and bigger then I click the button which starts to reduce the image. As the image gets smaller there's a side affect which looks like sun rays coming out from around the circumference. Also the stary background is reduced to a square in the center of the picturebox. I have included picture so you can see the affect. Any ideas what causes this.

    Here is the code I am using

    Code:
      With mSun
        Static SunWidth As Integer
        
        tScale = 0.95            ' want planet orbit to use 75% of screen height if full scale
    
        If MakeLarger Then
          SunWidth = SunWidth + VelFactor
        Else
          SunWidth = SunWidth - VelFactor
        End If
    
        .radSelf = (SunWidth / 2) * tScale
    
        Cx = .radSelf + .radSelf
        
        .Picture.Render (mDC), CtrX - .radSelf, CtrY - .radSelf, Cx, Cx, _
                        0, .Picture.Height, .Picture.Width, -.Picture.Height, ByVal 0
      End With
    Note: This only occurs if the sun is enlarged beyond the boundaries of the Picturebox and only on the top boundary.
    Attached Images Attached Images  

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

    Re: StretchBlt vs Enlarging Image Control

    Possibly something is off with the scale you are using to transfer mDC to your form? I'd look there first. It's going to be a bit tough to offer advice because it sounds like you have modified my original code (that's fine), but I don't know what it looks like now
    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}

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

    Re: StretchBlt vs Enlarging Image Control

    Code Dummy, can you try to explain what you are doing with that "Orbiting Balls" project? It almost sounds like you are trying to figure out how to scale it or convert it to draw on something else other than the form. Since this is for a teaching project, I don't mind converting the code to something easier for you to use. Say drawing into a picturebox or even converted as a windowless transparent control that you place on a form or picturebox or another usercontrol. Windowless UCs are much like a VB image control and have same restrictions regarding placement/ZOrder among other controls.

    For all others, this thread seems to be merging into the original thread which can be found here
    http://www.vbforums.com/showthread.p...Orbiting-balls
    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}

  28. #28

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    The problem also occurs in your program. All I did to your program was to add the code to enlarge the sun which is the same code I posted in post 25. I included a zip of my project which is a highly stripped down version of yours.
    Attached Files Attached Files

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

    Re: StretchBlt vs Enlarging Image Control

    If you want me to rework the project for your wife's use, I can. Just tell me what you need. This is not an open-ended offer

    The problem you appear to having is that you are rendering an area larger than the erase area. Therefore, not all of the rendered area is erased before the next frame is rendered.

    The original project logic worked a bit like this:
    1. A full screen buffer is created. My original logic would never allow an area larger than that to be rendered to that buffer
    2. An update area was calculated that would be the largest possible area that could be rendered to, relative to full screen.
    3. A second buffer was created that simply copied from the main buffer that update area. This buffer is used at the beginning of the frame rendering to erase what was previously drawn.

    Your code appears to be exceeding that update area. So when the backup is painted onto the buffer to erase the previously drawn frame, the previously drawn frame is larger than the calculated update area and not everything is being erased/replaced. I wrote my samples to minimize rendering just to that "update rectangle". Your changes are not honoring those dimensions and therefore the effects you are seeing.

    Edited: That "square" of stars that you see when you reverse the zoom... That's the update area based on the scaling calculations. In your coding. If you exceed that size, you'll see some unexpected rendering effects. The bounds of that area is roughly the height of your picturebox.


    To allow my logic to work for your example would require reworking the logic. But I'm not sure what your end goal is. It likely is not to render a single planet or sun, at different zoom levels. So, I don't know how to advise. If you run my project (not yours) and resize the form, is that what you are attempting to replicate, but in the context of zooming inside a picturebox?
    Last edited by LaVolpe; Feb 16th, 2019 at 04:37 PM.
    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}

  30. #30
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: StretchBlt vs Enlarging Image Control

    You're obviously not redrawing the whole star background so you're not erasing around the sun when it is fairly large, and shrinking.
    The following lines are where you draw the background, which erases the sun. If you change the Raster OP from srcCopy to srcInvert, the background will be black every other "erase" draw so will easily show the area being affected by the draw, and show why the sun isn't being cleared outside that area.
    'In the PlotPlanets Sub:
    Code:
      With mOrbitRect
        CtrX = .Width / 2 + .Left
        CtrY = .Height / 2 + .Top
        BitBlt mDC, .Left, .Top, .Width, .Height, mDCstars, .Left, .Top, vbSrcInvert 'vbSrcCopy
      End With
    The easiest fix would be to just redraw the whole background rather than a smaller background area around each planet. It might be slightly slower, but probably not slow enough to matter in this case, and since you want to zoom in and out, may be worth the slight penalty for the simplicity.
    Based on the code you had earlier where you setup the initial starfield, with cx,cy set to the Picture1 Width and Height ...
    Code:
      With mOrbitRect
        CtrX = .Width / 2 + .Left
        CtrY = .Height / 2 + .Top
       ' BitBlt mDC, .Left, .Top, .Width, .Height, mDCstars, .Left, .Top, vbSrcInvert 'vbSrcCopy
        BitBlt mDC, 0, 0, Picture1.Width, Picture1.Height, mDCstars, 0, 0, vbSrcCopy
      End With
    Last edited by passel; Feb 16th, 2019 at 07:39 PM.

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

    Re: StretchBlt vs Enlarging Image Control

    @passel. The OP has modified quite a bit of code with trial & error. If zooming in/out is his end goal, then simple logic like you described should work for him just fine:
    1. Redraw the star background (star field) to offscreen DC before each frame
    2. Render on top of that with whatever is wanted
    3. Blt the entire background to target, scaled as needed

    The original project pretty much did the same thing with a couple of major differences. The 1st step used a pre-calculated max dimensions of how much to be erased/redrawn per frame. Everything was rendered at a static scale (full screen), then scaled down as needed for display onto a maximized or resized form, keeping aspect, centered out, with extremes being clipped if aspect of Form-to-Screen was skewed enough. There was no need to zoom in to make rendering larger. The goal of that project was to display the solar system, not zooming in onto a single planet or star.

    @Code Dummy. Hard to stress this enough. It feels like you are trying to modify my original code for a different rendering logic which is akin to forcing it to fit. I think you'd be better off by starting anew and using my project as a guide. You might spend less time and run into less problems. It appears that most of this is new to you and if asked I'll try to offer advice on converting my code to your needs. But you are quickly approaching a point where one of my rules comes into play: If you break it, you fix it. The lines of code are becoming too dissimilar to be fairly/easily compared.

    Edited: Here's something to play with. Instead of rendering to a form, this will render into a picturebox. Using the menus, F2 zooms in & F3 zooms out. Might want to back up the previous form version first. To zoom with a timer as done in your project, simply move the zoom factor adjustment logic into a timer event. The picturebox is resized with the form, keeping the picturebox's original X,Y coordinates. The key difference here is the that the stars background is rendered to the buffer each frame, then the planets plotted in the buffer, then the buffer rendered to the picturebox. Changes provided for proof of concept. It could use some optimization. For example, when zooming in deeply, odds are some planets are going to get clipped when rendered -- so why render them. Just a matter of calculating the size & position of each & if outside the target bounds, skip drawing it.

    Form replacement: frmPretty.frm
    Last edited by LaVolpe; Feb 17th, 2019 at 04:39 PM.
    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}

  32. #32

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    Actually, LaVolpe, I started out using a Picturebox instead of the Form's surface. Everything worked same as your original until I allowed the sun to get too big and go beyond the borders of the picture box and then upon the sun getting smaller I ran into that problem that the area outside the plotting area wasn't being erased. At that time I didn't know too much about how you did things so I wasn't sure what was causing it. Then in your post #29 you stated something about exceeding the update area. Well, at first I didn't quite understand what you meant so I started playing around a bit. I started to pay more attention to your code and in Form_Load I saw this:

    Code:
     With mOrbitRect
       .Height = ((oPlanet(Neptune).Top + oPlanet(Neptune).Height) * 2)
       tScale = (Cy * tScale) / .Height
       .Width = .Height * tScale
       .Height = .Width
       .Left = (Cx - .Width) / 2
       .Top = (Cy - .Height) / 2
     End With
    Well, I started thinking about this structure and kind of figured that it must have something to do with that plotting area you were talking about. Seeing that I am using a picture box and not the form to draw on and I am not doing the planets orbiting around the sun; I'm only doing the sun for this project, it occurred to me that I should modify your code at this point in the Form_Load so I made the following changes:

    Code:
     With mOrbitRect
       '.Height = ((oPlanet(Neptune).Top + oPlanet(Neptune).Height) * 2)
       'tScale = (Cy * tScale) / .Height
       .Width = Picture1.Width   '.Height * tScale
       .Height = Picture1.Height '.Width
       .Left = 0                 '(Cx - .Width) / 2
       .Top = 0                  '(Cy - .Height) / 2
     End With
    When I ran the program again and enlarged the sun beyond the borders of the picture box and then reduced the sun's size it came out perfect.

    Now I understand a lot more than I did at first; oh yes, there are still a few things I'm in the dark about but nothing that affects what I have already done. Those things I'll deal with later.

    I do have a slight problem I don't understand. I have some buttons on the Form that I use to do certain things. A button to start and a button to pause the animation by setting the timer to either true or false, another button to make the sun get bigger and one to make it get smaller. I also have two more buttons, one which will make the red lines appear and one to turn them off. The lines are picture boxes which I reduced to a width of 1 and they lay on top of the picture box. Now while the animation is running I can click on the show button and the lines in red appear. If I click on the hide button the lines disappear. This is exactly what I want it to do. Now the problem with the lines. If I pause the animation and then show the lines they appear on top of the current display. No problem here. But when I click on the hide button the lines disappear but leave a white line instead because that is the color of the picture box's background color. I understand this because I am in a paused mode and no updating is taking place. So, the cure this problem I make a single call to PlotPlanets() to erase and redraw the scene. For some reason it doesn't work and the white lines are still there even though I can see that the picture was updated. If I single-step through the code one instruction at a time the white lines dissappear which is exactly what I want. So, the problem is that while the animation is running there is no problem but while in pause mode I can turn off the lines but it leave a white area where they used to occupy. Why does it work in debug mode but not in normal mode while the animation is in a paused mode.

  33. #33
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: StretchBlt vs Enlarging Image Control

    Quote Originally Posted by Code Dummy View Post
    ...
    I do have a slight problem I don't understand.
    ... So, the cure this problem I make a single call to PlotPlanets() to erase and redraw the scene. For some reason it doesn't work and the white lines are still there even though I can see that the picture was updated. If I single-step through the code one instruction at a time the white lines dissappear which is exactly what I want. So, the problem is that while the animation is running there is no problem but while in pause mode I can turn off the lines but it leave a white area where they used to occupy. Why does it work in debug mode but not in normal mode while the animation is in a paused mode.
    The problem is because you're using controls, i.e. pictureboxes, for the lines.
    You expect the pictureboxes to go away as soon as you set them to not be visible, but that isn't the case. The pictureboxes are controls, which are windows, and they won't go away (become not visible) until they get a message from Windows to hide themselves. They can't get a message, because you're in the middle of processing a message when you get the button event.
    So, in the below code, setting the Visible Property to false will cause both pictureboxes to remove themselves when the next pass through the message loop occurs, which would normally be after you leave the sub.
    When you call PlotPlanets, the pictureboxes are still there, so you update your drawing, and then leave the Sub.
    Once you leave the sub, the pictureboxes hide themselves, leaving the background color of your picturebox showing where they were. (if you had updated the .Image property of the picturebox, then the screen would have been restored from there, so you wouldn't have the issue).
    If you press the button a second time, since the pictureboxes would have been removed by then, you will see the image restore itself.
    Code:
    Private Sub Command5_Click()
     HLineRed.Visible = False
     VLineRed.Visible = False
     PlotPlanets
    End Sub
    One way to "fix" the problem, since you know you need to process events for the pictureboxes to hide themselves, is to make a call to DoEvents, so that the pending events you are causing will be processed, before you code continues.
    Code:
    Private Sub Command5_Click()
     HLineRed.Visible = False
     VLineRed.Visible = False
     DoEvents   'Allow the pictureboxes to hide themselves
     PlotPlanets
    End Sub
    Another option, the hiding of the pictureboxes will cause a paint event on the container (Picturebox1) since you don't have AutoRedraw set to True.
    So, rather than add code to the Command5 Click event handler, you could add code to the Paint event to redraw the image.
    Code:
    Private Sub Picture1_Paint()
      Dim tmpVel As Integer
      tmpVel = VelFactor
      VelFactor = 0
      PlotPlanets
      VelFactor = tmpVel
    End Sub
    The third option is to not add code to either the command button or add a Paint event handler for Picture1.
    You would use the built in backbuffer provided with the picturebox by setting the Picturebox's AutoReDraw property to True.
    With AutoReDraw set true, the bitblt (StretchBlt in this case) will draw into the picturebox's backbuffer.
    You just have to let the picturebox know when you're done drawing by calling the Invalidate or Refresh method of the picturebox.

    At the bottom of the PlotPlanets Sub, after the StretchBlt call, add the call (Picture1.Invalidate in this example) to update the screen with the current contents of the picturebox's backbuffer (also know as the AutoRedraw Buffer, and is accessible through the .Image property of the picturebox, if you wanted to use SavePicture, for instance).
    Code:
    '...
      StretchBlt Picture1.hDC, _
                         -10, -15, _
                         1300, 750, _
                         mDC, _
                         0, 0, _
                         lMaxX, lMaxY, _
                         vbSrcCopy
      Picture1.Invalidate                             'update the screen
      SetStretchBltMode Picture1.hDC, defValue
    End Sub
    By using the built-in backbuffer, when you hide the pictureboxes, the picturebox will automatically refresh the image from its backbuffer to fill in the gaps left by the hidden pictureboxes, so you don't have to add code to redraw an already drawn image.
    Last edited by passel; Feb 18th, 2019 at 09:51 AM.

  34. #34

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    @passel

    I tried all three of your suggestions. The only one that did anything worthwhile was your first suggestion putting DoEvents just before the call to PlotPlanets. The second suggestion, using Picture1_Paint(), doesn't do any better than the first suggestion so I don't see the point of having it and it is called every time anything is drawn onto Picture1. Your third suggestion about using Picture1.Invalidate wont work because VB says that this property does not exists. As far as using the DoEvents, although better than not using it, still leaves the background color momentarily and is quite obvious over the image of the sun.

    Maybe there is no absolute solution to this situation.

    I'll continue to use the DoEvents approach until I find a better way. Thank you so much for your help

    BTW: I just saw your suggestion in post #30 and I think it is a better way than what I did. Thanks

  35. #35
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: StretchBlt vs Enlarging Image Control

    Quote Originally Posted by Code Dummy View Post
    ... Your third suggestion about using Picture1.Invalidate wont work because VB says that this property does not exists.

    As far as using the DoEvents, although better than not using it, still leaves the background color momentarily and is quite obvious over the image of the sun.

    Maybe there is no absolute solution to this situation.
    ...
    As for Invalidate, I was getting my languages confused. Use Refresh instead of Invalidate.

    As for a better solution, don't use pictureboxes to be the lines, just draw the lines, if enabled, on the picturebox after doing the StretchBlt and before doing the Refresh. In fact, if you draw the lines on the picturebox, you may not need to do a refresh as drawing with a VB drawing statement should cause the picturebox to refresh automatically.

    I tested to see if drawing the lines did an auto refresh and it did.

    Since you do your animation in the PlotPlanets as well as the drawing, I added an optional parameter to the sub so that the animation portion could be skipped if all we want to do is redraw the image, as is.

    So, first I added a boolean so we can check whether the lines should be draw or not.
    Code:
    '... first three lines already existing
    Dim MakeLarger As Boolean
    Dim StartShow As Boolean
    Dim VelFactor As Integer
    Dim showLines As Boolean  'to control whether red lines are drawn, or not
    Next, added a boolean parameter to the PlotPlanets sub so we can control whether we animate or not.
    Made it an optional parameter, so the existing code would work without having to be modified to pass an argument.
    Put the "guard" around the animation calculation (making larger or smaller).
    Added the line drawing code.
    Code:
    Private Sub PlotPlanets(Optional animate As Boolean = True)
    
    '...
        If animate Then  'Guard around animation code, selected by parameter passed. Default is to animate
          If MakeLarger Then
            SunWidth = SunWidth + VelFactor
          Else
            SunWidth = SunWidth - VelFactor
          End If
        End If
    
    '... added drawing of redlines after the Stretchblt. Make sure Picture1.AutoRedraw is set True (can be done in IDE)
    
      StretchBlt Picture1.hDC, _
                         -10, -15, _
                         1300, 750, _
                         mDC, _
                         0, 0, _
                         lMaxX, lMaxY, _
                         vbSrcCopy
      If showLines Then
        Picture1.Line (Picture1.ScaleWidth / 2, 0)-Step(0, Picture1.ScaleHeight), vbRed
        Picture1.Line (0, Picture1.ScaleHeight / 2)-Step(Picture1.ScaleWidth, 0), vbRed
      Else
        Picture1.Refresh
      End If
    '...
    Next, changed the line related buttons to set the boolean, and call the plot function.
    Code:
    Private Sub Command4_Click()
    ' HLineRed.Visible = True
    ' VLineRed.Visible = True
      showLines = True   'the lines will be drawn
      PlotPlanets False  'redraw the image without animating
    End Sub
    Private Sub Command5_Click()
     'HLineRed.Visible = False
     'VLineRed.Visible = False
      showLines = False  'the lines won't be drawn
      PlotPlanets False  'redraw the image without animating
    End Sub
    Last edited by passel; Feb 18th, 2019 at 04:30 PM.

  36. #36

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    I tried doing that but they flicker as program goes through timer loop.

    OK, I think I got it. I thought about the sun and I think if I can do the sun why can't I do the lines the same way. So I make two picture files; one called VLine.png and the other HLine.png. In the code what ever I do for the sun I do same thing for the lines. When I click button to show lines I set a boolean to true and when I don't want them to show I set the boolean to false. In the PlotPlanets routine I do this after I plot the sun (because I want them on top of everything else:

    Code:
       '
       '
      If HVLines Then
        With mHRedLine
          .Picture.Render (mDC), 0, Picture1.Height \ 2, HLineRed.Width, HLineRed.Height, 0, .Picture.Height, .Picture.Width, -.Picture.Height, ByVal 0
        End With
        
        With mVRedLine
          .Picture.Render (mDC), Picture1.Width \ 2, -3, VLineRed.Width, VLineRed.Height, 0, .Picture.Height, .Picture.Width, -.Picture.Height, ByVal 0
        End With
      End If
       '
       '
    Appears to do exactly what I want. No flicker, no background showing through.

    Thanks, passel, for all your help and advice.

    EDIT 1: I didn't see your added code until after I submitted this post. I will try what you suggested

    EDIT 2: OK, I tried your last suggestion. The lines flicker
    Last edited by Code Dummy; Feb 18th, 2019 at 05:34 PM.

  37. #37
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: StretchBlt vs Enlarging Image Control

    Did you set AutoRedraw to True on your picturebox? There is no way the lines should be flickering if you're updating the pictureboxes AutoRedraw Buffer.

  38. #38

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    Your code:

    Code:
      '
      '
    If showLines Then
        Picture1.AutoRedraw = True
        Picture1.Line (Picture1.ScaleWidth / 2, 0)-Step(0, Picture1.ScaleHeight), vbRed
        Picture1.Line (0, Picture1.ScaleHeight / 2)-Step(Picture1.ScaleWidth, 0), vbRed
        Picture1.AutoRedraw = False
      Else
        Picture1.Refresh
      End If
      '
      '
    Before I added your suggestions:

    When I first launch the program the stary background shows up. It sits and waits until you press the start button. When I press the start button you will see the sun gradually getting bigger.

    After I added your code:

    When I first launch the program the stary background shows up for a fraction of a second and then goes completely black (the background color of Picture1). This is because of the Picture1.Refresh statement. It doesn't matter whether you have AutoRedraw true or false. So my question why do you have it there in the first place.

    Anyway, I commented out the Else clause from your code so it behaves like it did before I added your code. Now only the True clause is left

    Now when I press start everything is normal until I turn on the red lines. Turning the lines on causes the entire screen to flicker from background color to normal screen over and over again. This is caused by the Picture1.AutoRedraw being set to true. If I remove the AutoRedraw statements then only the red lines flicker.

  39. #39
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: StretchBlt vs Enlarging Image Control

    {
    p.s. I posted the below response, but then noticed that in the previous post you said that snippet was my code, but I realized that it wasn't my code. I didn't turn AutoRedraw On and Off in my code. I just set it On in the IDE so it was permanently on from the start.
    You shouldn't be turning if off. You want all the drawing, your StretchBlt and the red lines to be drawn in that back buffer. The Refresh would then refresh the screen area of the picturebox from that backbuffer.
    } Continuing original post Response:

    I guess it is easiest to just attach the project I'm working with.
    You must have made a number of changes, because the star background didn't show up until you started the timer in your original code from post #28.

    It still sounds like that AutoRedraw is not being set for your picturebox. Perhaps you set AutoRedraw on the form instead. If you do a Refresh, and the picturebox goes black, that indicates you didn't draw in the AutoRedraw buffer, but rather drew to the picturebox's screen context. The refresh would then wipe that out (it updates the screen from the AutoRedraw buffer, but if you didn't draw in the buffer, then it wouldn't have anything in it, so would just clear the picturebox to its background color.

    Give the attached project a try and see if it behaves reasonably. I didn't add a call to PlotPlanet during startup, so the box is empty at startup. You can toggle the lines on and off to get the initial background showing.
    Attached Files Attached Files
    Last edited by passel; Feb 19th, 2019 at 12:11 AM.

  40. #40

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    539

    Re: StretchBlt vs Enlarging Image Control

    You're absolutely right, passel, I didn't have AutoRedraw set to true from the beginning; only as shown in the code snippet. When I set it to true in design mode and removed it from the code everything worked as you said it would. Thank you so much for your help, your patience, and advice. Really appreciated.


    EDIT: There is one thing I don't understand, however. Just out of curiosity why did you put Picture1.Refresh only in the Else clause? If I remove the Else clause and put the Picture1.Refresh below the If statement it doesn't appear to cause any problems nor do I see any difference.
    Last edited by Code Dummy; Feb 19th, 2019 at 05:20 PM.

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