Jump to content

Error trying to create BMP files


Recommended Posts

Hi Guys,

I was looking to create a number of single colour images files (don't mind if they are BMP, JPG, PNG or whatever).

Fortunately, I came across a neat piece of code which allegedly does just what I want

However, when I run the script I get a "variable used without being declared" error in Line 16

I have checked and rechecked the script, but without any success.

Is there an eagle-eyed guru out there who can spot the error???

Script is:

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>


_GDIPlus_Startup()
Global Const $hGUI = GUICreate("GDI+ Test", 300, 300)
Global Const $iPic = GUICtrlCreatePic("", 100, 100, 100, 100)
Global Const $hPic = GUICtrlGetHandle($iPic)
GUISetBkColor(0x000000, $hGUI)
GUISetState()

#region GDI+

;create an empty bitmap
Global Const $iWidth = 100, $iHeight = 100 ;dimension of the bitmap
Global Const $iStride = 0, $pScan0 = 0, $iPixelFormat = $GDIP_PXF32ARGB ;some bitmap parameters
Global $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
Global Const $hBitmap = $aResult[6] ;this is the handle of the new empty bitmap
Global Const $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;create a context to the bitmap handle to do some GDI+ operations
Global Const $iBgColor = 0xFF004488 ;define background color -> ARGB
_GDIPlus_GraphicsClear($hContext, $iBgColor) ;clear empty bitmap with new color

Global Const $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Step_2_In.png") ;load a transparent PNG image which should be placed on the bitmap
_GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $iWidth, $iHeight) ;copy the image onto the bitmap. if image dimension <> bitmap dimension than the image will be displayed deformed

;save result as JPG and PNG (conversation is done automatically)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\New_Image.jpg")
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\New_Image.png")

;let's display the new created bitmap in the GUI
Global Const $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hPic)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, 100, 100)

#endregion

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GDIPlus_ImageDispose($hImage) ;release image
            _GDIPlus_BitmapDispose($hBitmap) ;release bitmap
            _GDIPlus_GraphicsDispose($hContext)
            _GDIPlus_GraphicsDispose($hGraphics)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
Until False

Line16 = Global $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

 

Basically, all I want to do is to create several BMP files, each one a different colour (e.g. red.bmp, blue.bmp, yellow.bmp, etc)

Many thanks

Newbie Pete

 

 

Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

pete_wilde,

That is an old script - the $ghGDIPDll DLL name was renamed a long time ago to $__g_hGDIPDll. Change that and the error is no more.

M23

P.S. When you post code please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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