Results 1 to 12 of 12

Thread: save .bmp only image1 not picture1

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    183

    save .bmp only image1 not picture1

    Hello, all members!

    i draw 4 image box in form1 name image1 , image2 , image3 and image4

    i load different image in all 4 images box

    move all so image2 , image3 and image4 different *.left in image1
    watch image
    Name:  234.png
Views: 254
Size:  4.9 KB
    how save this image1
    i save picture type ym.bmp
    thanks

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

    Re: save .bmp only image1 not picture1

    try this
    Code:
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
    Private Const WM_PAINT As Long = &HF&
    
    Private Sub Command1_Click()
        
        Picture1.AutoRedraw = True  ' turn on if not already on
                                    ' have VB paint the content onto itself
        SendMessage Picture1.hwnd, WM_PAINT, Picture1.hDC, ByVal 0&
                                    ' save the image
        SavePicture Picture1.Image, "[path/filename].bmp"  ' << change to valid location & file name
        
        Picture1.AutoRedraw = False ' turn off unless needed for something else
    End Sub
    Edited. If using a form as the image control containers, replace Picture1 with Me in the above code.
    Oh, if it was so easy... if using a form, the Image property remains full screen size. A workaround is to use a picturebox as a temporary buffer.

    1. Add picturebox to form, make it borderless and visible=false
    2. Then this adjusted code:
    Code:
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
    Private Const WM_PAINT As Long = &HF&
    
    Private Sub Command1_Click()
        
        Picture1.AutoRedraw = True  
        Picture1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
                                    ' have VB paint the content into buffer
        SendMessage Me.hwnd, WM_PAINT, Picture1.hDC, ByVal 0&
                                    ' save the image            
        SavePicture Picture1.Image, "[path/filename].bmp"
        
        Picture1.AutoRedraw = False ' turn off and free buffer
    End Sub
    Last edited by LaVolpe; Jul 1st, 2020 at 02:02 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}

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: save .bmp only image1 not picture1

    I thought he only had a (windowless) Image control with 3 more positioned above it. No PictureBox.

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

    Re: save .bmp only image1 not picture1

    Quote Originally Posted by dilettante View Post
    I thought he only had a (windowless) Image control with 3 more positioned above it. No PictureBox.
    Honestly, I wasn't sure what he had. But after reading it for the umpteenth time, sounds like a form with 4 image controls. I modified the code for capturing the form if that's the scenario.
    Last edited by LaVolpe; Jul 1st, 2020 at 02:03 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}

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: save .bmp only image1 not picture1

    Kako,

    If it truly is the Image control with which you're dealing, why not just change it to the Picture control. That will give you many more options, and it can have hWnd and hDC properties.

    When VB6 first came out, there were concerns about the memory and resources available to the OS. However, with any relatively contemporary computer, that's just no longer a concern (from a VB6 perspective).

    So, there's virtually no down-side to just using the Picture control.

    Good Luck,
    Elroy

    EDIT: Ahhh, LaVolpe beat me to it.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: save .bmp only image1 not picture1

    why not use Microsoft Windows Image Acquisition Library 2?
    since you have the "images" already in your drive, as you are loading them into the images, you can actually do the "merging" without using the image-control at all,
    simply, load all the images using WIA, use the stamp method to paste the images into into the right coordination (you can retrieve the left/top from the images)
    and lastly save as bmp/png/jpg.

    dilettante has a bunch of examples for WIA if you search.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: save .bmp only image1 not picture1

    No idea what he is actually trying to do. For all we know the user is allowed to drag the "inner" Image controls around and then take a snapshot.

    Or may these are already PictureBox controls.

    The Socratic method sure gets tedious.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    183

    Re: save .bmp only image1 not picture1

    Thinks all members,
    i used only images not picturebox
    i saved ym.bmp picture only images box
    i load different picture in different images box and all images combine and saved ym.bmp
    thanks

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

    Re: save .bmp only image1 not picture1

    So, is this resolved? If not, what code are you using and what part of that code is not working?
    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
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: save .bmp only image1 not picture1

    To capture an area of the desktop, I use the following method.
    Place a non-visible picturebox sized to be where and how much you want to capture.
    Save the Screen Area hDC of the picturebox (the .hDC when AutoRedraw is False).
    Set AutoReDraw to True, and bitblt from the saved hDC to the current .hDC (draws the picturebox area of the screen to .Image object of the Picturebox.
    Save the .Image object (or do with it what you want).

    So, place a non-visible picturebox at the bounds of your image1 image control, and then capture and save the image as described above, and you capture the other images that are located in the same area.
    Code:
    Option Explicit
    
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal Y As Long, _
                                                 ByVal nWidth As Long, ByVal nHeight As Long, _
                                                 ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, _
                                                 ByVal dwRop As Long) As Long
    
    
    Private Sub Command1_Click()
      Picture1.Visible = False
      Dim noAuto_hDC As Long
      
      With Image1
        Picture1.Move .Left, .Top, .Width, .Height
      End With
    
      With Picture1
        .ScaleMode = vbPixels
        .AutoRedraw = False
        noAuto_hDC = .hDC
        .AutoRedraw = True
        BitBlt .hDC, 0, 0, .Width, .Height, noAuto_hDC, 0, 0, vbSrcCopy
        SavePicture Picture1.Image, "C:\c\ym.bmp"
        
      End With
      
    End Sub
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    183

    Re: save .bmp only image1 not picture1

    Thanks passel,
    your code is best work.
    i many animated banner create using your code.
    Thanks again

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: save .bmp only image1 not picture1

    You can also use a memory DC instead of playing footsie with an extra PictureBox control. This is slightly easier now that palettized display depths are a thing of the past.
    Attached Files Attached Files

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