Jump to content
Sign in to follow this  
claude21

Copying image from/to a picturebox control

Recommended Posts

claude21

I'm trying to copy (to either the clipboard or to a new file on disk) the image content of a picturebox control ( [CLASS:ThunderRT6PictureBoxDC; INSTANCE:2] ) from an external app, but so far all I've got is a black rectangle. I've the handle of the control with no problem, but, being new to autoit, can't find a way to manage this. Can someone show me an example script for this purpose ?

Edited by claude21

Share this post


Link to post
Share on other sites
wolf9228

I'm trying to copy (to either the clipboard or to a new file on disk) the image content of a picturebox control ( [CLASS:ThunderRT6PictureBoxDC; INSTANCE:2] ) from an external app, but so far all I've got is a black rectangle. I've the handle of the control with no problem, but, being new to autoit, can't find a way to manage this. Can someone show me an example script for this purpose ?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
HotKeySet("{ESC}", "Capture")
While 1

WEnd





Func Capture()
Run("notepad.exe")
Sleep(2000)
$HWND = ControlGetHandle("[CLASS:Notepad]", "", "Edit1")
$hBitmap = BitmapCreateFromControlHWND($HWND)
 _GDIPlus_Startup ()
 $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap)
  _GDIPlus_ImageSaveToFile ($hImage1, @MyDocumentsDir & "\GDIPlus_Image.jpg")
 _GDIPlus_ShutDown ()
Exit
EndFunc

Func BitmapCreateFromControlHWND($HWND)
Local $Width = _WinAPI_GetWindowWidth($hWnd)
Local $Height =_WinAPI_GetWindowHeight($hWnd)
$DC = _WinAPI_GetDC($HWND)
$CompatibleDC = _WinAPI_CreateCompatibleDC($DC)
$hBitmap = _WinAPI_CreateCompatibleBitmap($DC,$Width, $Height)
_WinAPI_SelectObject($CompatibleDC, $hBitmap)
_WinAPI_BitBlt($CompatibleDC, 0, 0, $Width, $Height, $DC, 0, 0,$SRCCOPY)
Return $hBitmap
EndFunc

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
claude21

Thanks for this code wolf !

This help me a lot. However, it seems that the function can't copy the picturebox data when the main window is minimized, not visible (in background) or whatever state except when in foreground. Is there a way to copy the picturebox data no matter the window state (without bringing the window in focus, eventually restore it if minimized etc etc )??

Share this post


Link to post
Share on other sites
wolf9228

Thanks for this code wolf !

This help me a lot. However, it seems that the function can't copy the picturebox data when the main window is minimized, not visible (in background) or whatever state except when in foreground. Is there a way to copy the picturebox data no matter the window state (without bringing the window in focus, eventually restore it if minimized etc etc )??

I know this....But there is no library functions

Undertake this process .


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
claude21

I know this....But there is no library functions

Undertake this process .

humm, thats weird. Btw, How could I put back the saved image file (from disk) to the clipboard ? never mind, found here

Now, I try to send back the saved image file TO the picturebox control, do you know how to manage that ?

Edited by claude21

Share this post


Link to post
Share on other sites
claude21

I've attached a Visual basic 6 example containing the picturebox. I just want to fill this picturebox control with a bitmap file loaded from disk.

Project1.exe

Edited by claude21

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.