Results 1 to 37 of 37

Thread: How does VB stretch an Image control

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    I know that the Image control is the only (except for the Label) control that is not a wrapper of Windows own controls.
    I.e VB draws the picture directly on the form so it doesn't have it's own window (therefor the lack of a hWnd).

    But how does VB stretch the picture when you set the Stretch property to True?
    I have always assumed that it uses the StretchBlt function but when I use StretchBlt to draw a picture to a PictureBox at aprox. 1/8 of the original size the image (that is mostly green) gets mostly black. But when I load the same picture to an Image control and size it to the same size you can see all the original colours.

    So the question is if VB doesn't use StretchBlt to stretch the image what does it use?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I'm almost sure it's paintpicture, that also implemented in all pictureboxes and forms, it's also faster than stretchblt.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Thanks Kedaman.
    But PaintPicture is a VB function and must be a wrapper for some API functions. I have always assumed that it was a wrapper for BitBlt but though it can stretch an image I suppose it's not.
    So the question remains; what GDI functions except for StretchBlt can you use to stretch an image?

  4. #4
    Guest
    It's StretchBlt. Both the ImageBox and PaintPicture use this API function.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    ACtually I have no idea, Paintpicture is slightly faster than Stretchblt so it can't be stretchblt
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Guest
    Paintpicture is StretchBlt. Likewise the Line method is using the LineTo API, and showing and hiding objects is using the ShowWindow API.

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by Megatron
    Paintpicture is StretchBlt
    I don't think so because during my testing I actually found that PaintPicture is more then 8-10 times faster then StretchBlt. I also can't get the same result using StretchBlt as I can using PaintPicture so how can then PaintPicture use StretchBlt?

    You can make the test yourself.
    I just timed how long it would take to make 1000 calles to PaintPicture and how long it would take to do the same with StretchBlt.

    The difference is HUGE!

  8. #8
    Guest
    StretchBlt, StretchDlBits (and I think SetBitmapDimensionsEx) are the only functions that can do this, so it must be one of them.

    The difference in Timing is probably the time it takes VB to extract the function from the library.



  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    The difference in Timing is probably the time it takes VB to extract the function from the library.
    What do you mean? How would that differ if you call paintpicture or stretchblt?

    And Joacim, Paintpicture is about 30% faster, you probably leaved autoredraw out
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10
    Guest
    PaintPicture is located in VB and StretchBlt is located in the DLL. For the sake of argument, let's assume that PaintPicture is StretchBlt. If PaintPicture is faster, the reason is that it's faster to get the information from VB. If StretchBlt is faster (slower), it's because of the time it takes VB to extract the function from the library (DLL).

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    No Meg, the paintpicture method is in the VB runtimes. If it's using Stretchblt it would be slower since you have to call the runtimes and from the runtimes to GDI32
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Whoa. Calm it down, guys. We've already had this conversation turn strange.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  13. #13
    Guest
    Most of VB's graphical functions are based on API's. Paintpicture is one of them. Whether it's slower or faster, it's still an API call.

  14. #14
    Lively Member
    Join Date
    May 2000
    Posts
    84
    When I used stretchblt in a program of mine I noticed that when shrinking images the image becomes distorted alot (it gets black lines in it). Since you seem to be shrinking the image a lot, this might be what is happening.

    Solution: Set the stretchblt properties as follows. You have to declare the SetStretchBlt API

    Code:
    SetStretchBltMode Picture1.hdc, 3
    For you who have tested the speed...does the StretchBlt setting affect the speed much?

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    *away trying your suggestion*
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  16. #16
    Guest
    Setting HALFTONE for the mode would probably slow it down a little because it requires more processing then the rest but the image quality is a lot better.

  17. #17

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Kedaman: I didn't leave AutoRedraw out. In my test PaintPicture where about 8 times faster then StretchBlt.
    But then again this was just ONE test which i run from the VB environment. The time difference might alter if i had compiled the program.

    And I agree with you on the fact that if PaintPicture calles StretchBlt it would have run slower then calling StretchBlt directly. Just the fact that PaintPicture also have added some error checking as well would have maid the procedure slower.

    Illuminator: Thank you for suggestion using SetStretchBltMode. Now at least I get the image the way I want using StretchBlt, but since PaintPicture is noticeably faster I will go with that until I find any API that runs faster.

    To finish this up; Megatron, Kedaman and Illuminator: Thank you all guys for taking your time disscusing and testing my little problem. This is actually the first time I use this forum to ASK a question.

    Once again thank you all very much.

    Best regards

    [Edited by Joacim Andersson on 08-10-2000 at 05:31 AM]

  18. #18
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Back with the results:

    StretchBlt seems to get about 10% faster using SetStretchBltMode but still 20% slower than Painpicture which stays the same. Should confirm enough there is no connection between Stretchblt and Paintpicture.

    BTW Joacim, is it the destination picturebox that autoredraw is set to true?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  19. #19

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by kedaman

    BTW Joacim, is it the destination picturebox that autoredraw is set to true?
    Well of course it is!
    What good would it do to set AutoRedraw on the source?

  20. #20
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Sorry, i just wanted to be sure, but we still get different results, can you post your testing method?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  21. #21

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Actually, when I run the test again PaintPicture was 47 times faster!!!

    This is what I used:
    The source picture is a bitmap with the size 256x1024 pixels.
    The destination size is 64x256 pixels.
    The computer is a Dell laptop Pentium III 650 Mhz with 256MB RAM running Windows NT Workstation 4.0 SP6a.
    I have VB6 SP3 and the code I'm using is the following:
    Code:
    Private Sub Command1_Click()
        Dim i%
        Dim sngTime As Single
        
        With Picture1
            sngTime = Timer
            For i = 1 To 1000
                StretchBlt .hdc, 0&, 0&, _
                 .ScaleWidth, .ScaleHeight, _
                 Picture2.hdc, 0&, 0&, _
                 Picture2.ScaleWidth, Picture2.ScaleHeight, _
                 vbSrcCopy
            Next
            Label1 = Timer - sngTime
        End With
    End Sub
    The code for PaintPicture is exactly the same (I just exchanged the call to StretchBlt with PaintPicture)

    The result was
    StretchBlt: 229.7 sec
    PaintPicture: 4.8 sec

  22. #22
    Guest
    I think it is a wrapper for BitBlt, several items in the MSDN also mention this:

    The PaintPicture function, which is simply a wrapper function of the BitBlt Window API function, lets us avoid making an API declaration.
    and

    The PaintPicture method can be used in place of the BitBlt Windows API function to perform a wide variety of bit operations while moving a rectangular block of graphics from one position to any other position.
    (Source: http://msdn.microsoft.com/library/de...ylocations.htm )

    [Edited by Azzmodan on 08-11-2000 at 10:58 AM]

  23. #23

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    If it was just a wrapper for BitBlt then how does PaintPicture stretch an image when BitBlt can't?

  24. #24
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    How can you possibly use Bitblt since it lack the parameters to resize?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  25. #25
    Lively Member
    Join Date
    May 1999
    Location
    Singapore
    Posts
    116
    you can resize it by changing the width and height of the new image.....
    YC Sim
    Teenage Programmer
    UIN 37903254



  26. #26
    Guest
    BitBlt and StretchBlt both work with DC's, whereas PaintPicture works with Picture objects.

  27. #27
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Smile

    I agree with Megatron, most VB graphical functions are just calls to the windows APIs. Maybe PaintPicture is faster because the code from the StretchBlt API has just been reprogrammed into the VB runtimes. I can't see PaintPicture being better coded then StretchBlt, but just easy for VB to access.
    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

  28. #28

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Well rino_2 if PaintPicture is faster I must say that it's better coded that StretchBlt.

  29. #29
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287
    I do see the logic in that Joacim Andersson but what I'm saying is maybe its not better coded then StretchBlt but just easier for VB to access becasue its part of VBs runtimes.
    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

  30. #30
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Rhino, that doesn't make sense

    If Vb access the stretchblt directly, you would have
    App - API
    while if if paintpicture access API
    App - Runtimes - API

    which would be at least one call more than calling stretchblt.

    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  31. #31
    Lively Member
    Join Date
    May 1999
    Location
    Singapore
    Posts
    116
    maybe vb has its own stretching algo?
    YC Sim
    Teenage Programmer
    UIN 37903254



  32. #32
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Red face

    Thats what I'm saying ycsim. I think that the PaintPicture function isn't calling StretchBlt. I think that StretchBlt has just been reprogrammed into VBs runtimes. This would mean that no API is being used so would result in more speed.
    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

  33. #33
    Lively Member
    Join Date
    May 1999
    Location
    Singapore
    Posts
    116
    yeah, since microsoft made both windows and vb
    YC Sim
    Teenage Programmer
    UIN 37903254



  34. #34
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Thumbs up

    Absolutely
    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

  35. #35

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    But when VB calles a function in the run time library it's calling an API. All functions in the run-time library is actually API functions.

  36. #36
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Good point, but the runtimes are already loaded for that app, so it doesn't need to get them again...or am I not making any sense??? On a similar note, you can access VB runtime functions from non-VB apps, by using LoadLibrary().
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  37. #37

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Yeah well the GDI library is loaded at Windows start up!

Posting Permissions

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



Click Here to Expand Forum to Full Width