Jump to content

Create bank image


Bam
 Share

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)

;Draw
_GDIPlus_GraphicsDrawImageRect($newGC,$oldImage,0,0,$newW,$newH)
_GDIPlus_ImageSaveToFile($newBmp,$newFileName)

;Clenaup
_GDIPlus_GraphicsDispose($GC)
_GDIPlus_GraphicsDispose($newGC)
_GDIPlus_BitmapDispose($newBmp)
_GDIPlus_ImageDispose($oldImage)

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.

Edite:

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
Link to comment
Share on other sites

Hi,

#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
_GDIPlus_Startup()

; 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.
_WinAPI_DeleteObject($hBmp)

; 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
_GDIPlus_ImageDispose($hImage1)

; 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
_GDIPlus_ImageDispose($hImage2)

; Dispose of the graphic context as both images are drawn into the new bitamp
_GDIPlus_GraphicsDispose($hGraphic)

; 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
_GDIPlus_BitmapDispose($hBitmap1)

; Shutdown GDIPlus
_GDIPlus_Shutdown()


; 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)

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Cheers

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...