Results 1 to 21 of 21

Thread: Saving after StretchBlt

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Saving after StretchBlt

    After I StretchBlt an image to a picture box, how can I save the strethed picture? I tried experimenting a little with the image property but I couldn't get it

    Thanks


    Has someone helped you? Then you can Rate their helpful post.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Perhaps the following will do the job:
    VB Code:
    1. Private Sub Command1_Click()
    2.     SavePicture Picture1.Picture, App.Path & "\mypicture.bmp"
    3. End Sub

  3. #3
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    That was my first guess too...if that doesn't work use BitBlt to Blt it to a new picture box (that one should now have the same size and, not be streched)..and then save it...

  4. #4

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Thanks for the suggestion but it doesn't work... It shows an error. I tried using the Image property also but I just get a gray box saved... Any other ideas?


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by NoteMe
    That was my first guess too...if that doesn't work use BitBlt to Blt it to a new picture box (that one should now have the same size and, not be streched)..and then save it...
    If I do a normal bitblt I will be able to save it?


    Has someone helped you? Then you can Rate their helpful post.

  6. #6
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by manavo11
    If I do a normal bitblt I will be able to save it?

    It's my best shot right now...


    Or you may have to use GetPixel and SetPixel..but I can't understand why taht should work any better then BitBlt...

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Originally posted by manavo11
    Thanks for the suggestion but it doesn't work... It shows an error. I tried using the Image property also but I just get a gray box saved... Any other ideas?
    Make sure Picture1.AutoRedraw = True.

  8. #8

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    It seems it isn't working...

    VB Code:
    1. picTemp.Picture = Clipboard.GetData()
    2.     StretchBlt picStretch.hdc, 0, 0, picTemp.ScaleWidth / 2, picTemp.ScaleHeight / 2, picTemp.hdc, 0, 0, picTemp.ScaleWidth, picTemp.ScaleHeight, vbSrcCopy
    3.     picStretch.Height = picTemp.Height / 2
    4.     picStretch.Width = picTemp.Width / 2
    5.     Picture2.Width = picStretch.Width
    6.     Picture2.Height = picStretch.Height
    7.     BitBlt Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, picStretch.hdc, 0, 0, vbSrcCopy
    8.     SavePicture Picture2.Image, "C:\test.bmp"

    I'm trying to make it half size...


    Has someone helped you? Then you can Rate their helpful post.

  9. #9
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    You don't need that second Blt......

  10. #10
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Yeah if you just Set AutoRedraw = True if works.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    You don't even need any api to do that:
    VB Code:
    1. Public Sub ZoomPicture(pct As PictureBox, zoom As Double)
    2.     With pct
    3.         .Width = .Width * zoom
    4.         .Height = .Height * zoom
    5.         .PaintPicture .Picture, 0, 0, .ScaleWidth, .ScaleHeight
    6.     End With
    7. End Sub
    Also, open attachments for a sample project

  12. #12

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Well, RhinoBull got it... It was the AutoRedraw... Thanks


    Has someone helped you? Then you can Rate their helpful post.

  13. #13
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Not at all, but take a look at that sample I sent last time.

  14. #14
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Seen as though you halfing the size it might be an idea to blur the image first so quality isn't lost so much.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  15. #15

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by RhinoBull
    Not at all, but take a look at that sample I sent last time.
    Thanks for that also, but making it half was just an example... Thanks anyway though


    Has someone helped you? Then you can Rate their helpful post.

  16. #16

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by Electroman
    Seen as though you halfing the size it might be an idea to blur the image first so quality isn't lost so much.
    Blur it?


    Has someone helped you? Then you can Rate their helpful post.

  17. #17
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Soften the edges....a lot of algorithms to do that....don't bother with it if this is just an example...

  18. #18
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Simplest way is to just set each pixel to the average of itself and the surounding pixels, as NoteMe says theres not really any point if your just playing around to see what StretchBlt does .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  19. #19

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by Electroman
    if your just playing around to see what StretchBlt does .
    That was the general idea... But, would I gain that much if I blurred it? And wouldn't it delay?


    Has someone helped you? Then you can Rate their helpful post.

  20. #20
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Well when you use StretchBlt its like taking everyother pixel and using that, however this means if you use it on a grid and the lines on the grid are 1 think (and lie on the every other line) they will be lost or the other way round and they will appear as a solid color.
    When you use the Blur first this means that a pixel on the missed out lines isn't forgotten because it has had an effect on the surrounding pixels.

    There is a slight delay but it all depends on how big the picture is and what method you use. Some methods you wont even notice the delay.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  21. #21

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Very interesting... Thanks for all the info


    Has someone helped you? Then you can Rate their helpful post.

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