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"
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"
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.
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.
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
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
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.