Jump to content
Sign in to follow this  

Create bank image

Recommended Posts


I did some searching and I found this (from ProgAndy)

; Load Image
$oldImage = _GDIPlus_ImageLoadFromFile()

;Create New image
$GC = _GDIPlus_ImageGetGraphicsContext($oldImage)
$newBmp = _GDIPlus_BitmapCreateFromGraphics($newW,$newH,$GC)
$newGC = _GDIPlus_ImageGetGraphicsContext($newBmp)



But what im trying to do is place 2 pictures next to each other, I did manage to get that to work but I was woundering if their was a way to make a blank image with the resolution I want then load the images. I gess is their any way to create GraphicsContext with out loading it from a file.


Got it working with

$hWnd = _WinAPI_GetDesktopWindow()

$hDC = _WinAPI_GetDC($hWnd)

$hBMP = _WinAPI_CreateCompatibleBitmap($hDC, 350, 304)

_WinAPI_ReleaseDC($hWnd, $hDC)

Was woundering if their was a shorter way.

Edited by Bam

Share this post

Link to post
Share on other sites


#include <GUIConstantsEx.au3>
#include <GDIPLus.au3>
#Include <WinAPI.au3>

Opt("MustDeclareVars", 1)

Global $sRegPath, $sImagePath1, $sImagePath2, $hImage1, $hImage2, $iW, $iH, $hBmp, $hBitmap1, $hGraphic, $hBitmap2, $Pic, $OldBmp

; Getting the path to autoit's install directory so I can use 2 images
$sRegPath = "HKLM\SOFTWARE\AutoIt v3\AutoIt"
If StringInStr("X64IA64", @OSArch) Then $sRegPath = StringReplace($sRegPath, "SOFTWARE", "SOFTWARE\Wow6432Node")

; This is the path to 2 images in autoit's install directory that I'll use
$sImagePath1 = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\Advanced\Images\Button.png"
$sImagePath2 = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\Advanced\Images\Torus.png"

; Start GDIPlus

; Load image 1

$hImage1 = _GDIPlus_ImageLoadFromFile($sImagePath1)

; Load image 2
$hImage2 = _GDIPlus_ImageLoadFromFile($sImagePath2)

; Get the width & height of the first image. I scale the second image to the same size of this when I draw it on the new blank hBitmap side by side
$iW = _GDIPlus_ImageGetWidth($hImage1)
$iH = _GDIPlus_ImageGetHeight($hImage1)

; Create a blank blank bitmap object
$hBmp = _WinAPI_CreateBitmap($iW * 2, $iH, 1, 32)

; Create a new Bitmap that's compatible with GDIPlus from the Blank bitmap to draw the 2 images on.
$hBitmap1 = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)

; Can delete blank blank bitmap object.

; Get the graphic context of the new Bitmap
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap1)

; I'm clearing the new blank bitmap color to a slightly transparent white (Grey)
_GDIPlus_GraphicsClear($hGraphic, 0xEFFFFFFF)

; Draw the first loaded image into the new bitmap.
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage1, 0, 0, $iW, $iH)

; Dispose of the first loaded image as we've drawn it on the new blank bitmap

; Draw the second loaded image into the new bitmap beside the first drawn image.
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2,  $iW, 0, $iW, $iH)

; Dispose of the second loaded image as we've drawn it on the new blank bitmap

; Dispose of the graphic context as both images are drawn into the new bitamp

; Convert the newly drawn on bitmap into a bitmap that can be sent to a Picture control.
$hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)

; Dispose of the newly drawn bitmap as we now have a new bitmap to send to a picture control

; Shutdown GDIPlus

; Create a gui based on the size of the new image
GUICreate("GDI+", $iW * 2, $iH)

; Create a picture control to show the new image.
$Pic = GUICtrlCreatePic("", 0, 0, $iW * 2, $iH)

; Send the new drawn bitmap onto the Picture control
$OldBmp = GUICtrlSendMsg($Pic, 0x0172, 0, $hBitmap2)

; When sending the control an image it will return the previous image handle, dispose of it's not being used.
If $OldBmp Then _WinAPI_DeleteObject($OldBmp)




Share this post

Link to post
Share on other sites


Thats what I was looken for thx Smashly.


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.