Jump to content
Sign in to follow this  
cppman

Drawing Udf's

Recommended Posts

I was working on a little project and was wondering if you can Draw a pixel or something onto a GUI without having it have to be in a Graphic Control?

Any UDF's for doing this?

Share this post


Link to post
Share on other sites

Well, then is their a way to load an image into a graphics control?

-becuase im trying to draw PIXELS over an IMAGE

Edited by CHRIS95219

Share this post


Link to post
Share on other sites

Something I found:

#include <GUIConstants.au3>
$timer = TimerInit()
$szPicFile = FileOpenDialog( "Choose bitmap", @DesktopDir, "All Files (*.*)" )

Const $GWL_HINSTANCE = -6
Const $IMAGE_BITMAP = 0
Const $LR_LOADFROMFILE = 0x0010

$dimension = _ImageGetSize ($szPicFile)

GUICreate("Example Drawing", $dimension[0] + 100, $dimension[1] + 100)
$lbSta = GUICtrlCreateLabel("Loading...", 20, 80)
GUISetState(@SW_SHOW)
GUICtrlCreateGraphic(0, 0, $dimension[0], $dimension[1]);width height


Dim $hInst, $hBmp, $hMemDC, $hwnd

opt("WinWaitDelay", 1)
AutoItWinSetTitle("qqqqqq")
$hwnd = WinGetHandle("qqqqqq")

$hInst = DllCall("user32.dll", "int", "GetWindowLong", "hWnd", $hwnd, "int", $GWL_HINSTANCE)
$hInst = $hInst[0]

$hBmp = DllCall("user32.dll", "hwnd", "LoadImage", "hwnd", $hInst, "str", $szPicFile, "int", $IMAGE_BITMAP, _
      "int", 0, "int", 0, "int", $LR_LOADFROMFILE)
$hBmp = $hBmp[0]

$hMemDC = DllCall("gdi32.dll", "int", "CreateCompatibleDC", "int", 0)
$hMemDC = $hMemDC[0]
DllCall("gdi32.dll", "hwnd", "SelectObject", "int", $hMemDC, "hwnd", $hBmp)

For $y = 0 To $dimension[1] - 1
   For $x = 0 To $dimension[0] - 1
      $ret = DllCall("gdi32.dll", "int", "GetPixel", "int", $hMemDC, "int", $x, "int", $y)
      $ret = Hex($ret[0], 6)
      $ret = StringRight($ret, 2) & StringMid($ret, 3, 2) & StringLeft($ret, 2)
      
      GUICtrlSetGraphic(-1, $GUI_GR_COLOR, Dec($ret))
      GUICtrlSetGraphic(-1, $GUI_GR_PIXEL, $x, $y)
      
     ;If Mod($y, 50) = 0 And $x = 0 Then GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
   Next
Next
GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
DllCall("gdi32.dll", "int", "DeleteDC", "hwnd", $hMemDC)
DllCall("gdi32.dll", "int", "DeleteObject", "hwnd", $hBmp)
GUICtrlSetData($lbSta, "Finished.")
MsgBox( 0, "Timer - Image Drawer", TimerDiff( $timer ) )
While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

#region - LazyCat;SEE THE FUNCTIONS WRITTEN BY LazyCat
;http://www.autoitscript.com/forum/index.php?s=&showtopic=4159&view=findpost&p=27240
Func _ImageGetSize ($sFile)
   Local $sHeader = _FileReadAtOffsetHEX ($sFile, 1, 24); Get header bytes
   Local $asIdent = StringSplit("FFD8 424D 89504E470D0A1A 4749463839 4749463837 4949 4D4D", " ")
   Local $anSize = ""
   If $asIdent[0] >= 2 And StringInStr($sHeader, $asIdent[2]) = 1 Then
      Return _ImageGetSizeSimple ($sHeader, 19, 23, 0)
   EndIf
EndFunc

;FUNCTION WRITTEN BY LazyCat
Func _FileReadAtOffsetHEX ($sFile, $nOffset, $nBytes)
   Local $hFile = FileOpen($sFile, 0)
   Local $sTempStr = ""
   FileRead($hFile, $nOffset - 1)
   For $i = $nOffset To $nOffset + $nBytes - 1
      $sTempStr = $sTempStr & Hex(Asc(FileRead($hFile, 1)), 2)
   Next
   FileClose($hFile)
   Return ($sTempStr)
EndFunc

;FUNCTION WRITTEN BY LazyCat
Func _ImageGetSizeSimple ($sHeader, $nXoff, $nYoff, $nByteOrder)
   Local $anSize[2]
   $anSize[0] = _Dec (StringMid($sHeader, $nXoff * 2 - 1, 4), $nByteOrder)
   $anSize[1] = _Dec (StringMid($sHeader, $nYoff * 2 - 1, 4), $nByteOrder)
   Return ($anSize)
EndFunc

;FUNCTION WRITTEN BY LazyCat
Func _Dec ($sHexStr, $nByteOrder)
   If $nByteOrder Then Return (Dec($sHexStr))
   Local $sTempStr = ""
   While StringLen($sHexStr) > 0
      $sTempStr = $sTempStr & StringRight($sHexStr, 2)
      $sHexStr = StringTrimRight($sHexStr, 2)
   WEnd
   Return (Dec($sTempStr))
EndFunc
#endregion

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...