Jump to content

Recommended Posts

Posted (edited)

hey guys :)

i got a problem editing a picture.

At first i load the picture to my exe file with the resource hacker, thats no problem, but then i want to load the picture to memory, edit it, for example with some drawings and display it on a control then.

Thats what i got so far:

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=gdiptest2.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_After="ResHacker.exe" -add %out%, %out%, gditest.bmp, bitmap, test2, 0
#AutoIt3Wrapper_Run_After="upx.exe" --best "%out%"
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****

#Include <WinAPI.au3>
#Include <GDIPlus.au3>
#include <Constants.au3>

$guiMain = GUICreate("test",500,500)
$guiPic = GUICtrlCreatePic("",0,0)
GUISetState()

$hInstance = _WinAPI_GetModuleHandle("")
$hBitmap = _WinAPI_LoadImage($hInstance, "test2", $IMAGE_BITMAP, 0, 0, 0)

;// here i should write the picture edit part but i dont know how to "transfer" that bitmap handle to something else to use it with _GDIPlus_Graphics functions.

_SetBitmapToCtrl($guiPic, $hBitmap)

While 1
    Sleep(10)
WEnd

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
    
; set SS_BITMAP style to control
    Local $oldStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($oldStyle, $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
    
    Local $oldBmp = _SendMessage($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp <> 0 Then _WinAPI_DeleteObject($oldBmp)
    Return 1
EndFunc

read the commented line with my problem too please

just loading it from the resource and display it is working with this example, i only got the problem with editing the picture

thanks for any help :party:

Edited by nuki
Posted (edited)

what about

$hbitmap = _GDIPlus_BitmapCreateFromFile()

$backbuffer = _GDIPlus_ImageGetGraphicsContext($hbitmap)

then you can draw all you like

_GDIPlus_GraphicsDrawImageRect($backbuffer, etc....

then put down the result

_GDIPlus_GraphicsDrawImageRect($hForm1, $hbitmap

maybe is what you want.

Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Posted

imagegetgraphicscontext doesnt work somehow, and bitmapcreatefromfile isnt possible cuz the resources of an exe file cant be read with that, and i dont wanna create a temporary bitmap somewhere

i tried that already :/

Posted

try _GDIPlus_BitmapCreateFromHBITMAP and then _GDIPlus_ImageGetGraphicsContext

not working :) already tried and just tried again

$hInstance = _WinAPI_GetModuleHandle("")
$hBitmap = _WinAPI_LoadImage($hInstance, "test2", $IMAGE_BITMAP, 0, 0, 0)
$hBitmap2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$hBitmap3 = _GDIPlus_ImageGetGraphicsContext($hBitmap2)
MsgBox(0,"",_GDIPlus_ImageGetType($hBitmap3) & @CRLF & @error)

ImageGetType returns -1 ($GDIP_IMAGETYPE_UNKNOWN) and @error is set to 4 (Invalid image handle)

Posted (edited)

hmm, are you sure that _WinAPI_LoadImage($hInstance, "test2", $IMAGE_BITMAP, 0, 0, 0) does not return a hImage not hBitmap?

have you tried

$hInstance = _WinAPI_GetModuleHandle("")

$hImage = _WinAPI_LoadImage($hInstance, "test2", $IMAGE_BITMAP, 0, 0, 0)

$hGc=_GDIPlus_ImageGetGraphicsContext ($hImage)

just stabbing in the dark a bit here.

Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Posted (edited)

i tried all combinations i could imagine with ImageGetGraphicsContext and BitmapCreateFromHBITMAP... just found _WinAPI_LoadBitmap, but it seems to be exactly the same... same results at all

ImageGetGraphicsContext always returns -1

and BitmapCreate always returns 0

but _WinAPI_LoadImage / LoadBitmap always returns some hex adress like 0xE60525E6... its always different when i restart the script

Edited by nuki
Posted

he wouldn't be the first to fall on that 1, if he has done, iv forgotten it loads of times and i think most peeps have at some time. :)

I agree
Posted

haha lolz u guys are great xD what a stupid mistake :idea: of course it was _GDIPlus_Startups fault :)

and Zedna i used a function and parts of your UDF :party: ty for that <3

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
×
×
  • Create New...