Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Misc.au3>
- #include <WinAPI.au3>
- #include <GDIPlus.au3>
- #include <GUIConstants.au3>
- #include <EditConstants.au3>
- #include <WindowsConstants.au3>
- ; - Author: name22 (www.autoit.de)
- Opt("GUIOnEventMode", 1)
- $vU32Dll = DllOpen("User32.dll")
- $iGUIColorBG = 0xFFFFFFFF
- $iGUIWidth = 800
- $iGUIHeight = 600
- $iGraphicX = 100
- $iGraphicY = 5
- $iGraphicWidth = $iGUIWidth - $iGraphicX - 5
- $iGraphicHeight = $iGUIHeight - $iGraphicY - 5
- $iRGB_Color = "0x000000"
- $iAlphaChannel = 255
- $iPenWidth = 2
- $tRect_Graphic = DllStructCreate($tagRECT)
- DllStructSetData($tRect_Graphic, "Left", $iGraphicX)
- DllStructSetData($tRect_Graphic, "Top", $iGraphicY)
- DllStructSetData($tRect_Graphic, "Right", $iGraphicX + $iGraphicWidth)
- DllStructSetData($tRect_Graphic, "Bottom", $iGraphicY + $iGraphicHeight)
- $tPoint_Mouse = DllStructCreate($tagPOINT)
- $hWnd = GUICreate("name22's supercooles Zeichenprogramm", $iGUIWidth, $iGUIHeight)
- GUICtrlCreateLabel("Pen Settings:", 5, 5, 100, 20)
- GUICtrlSetFont(-1, 10)
- GUICtrlCreateLabel("Image:", 5, 170, 100, 20)
- GUICtrlSetFont(-1, 10)
- GUICtrlCreateLabel("Pen Width:", 15, 25, 60, 20)
- GUICtrlCreateLabel("Pen Color:", 15, 75, 60, 20)
- GUICtrlCreateLabel("Alpha (0-255):", 15, 120, 70, 20)
- $cLabel_PreviewColor = GUICtrlCreateLabel("", 70, 78, 10, 10)
- GUICtrlSetBkColor(-1, 0x000000)
- $cInput_PenWidth = GUICtrlCreateInput($iPenWidth, 15, 40, 50, 20, $ES_NUMBER)
- $cUpDown_PenWidth = GUICtrlCreateUpdown($cInput_PenWidth)
- $cInput_AlphaChannel = GUICtrlCreateInput(255, 15, 135, 50, 20)
- $cButton_Color = GUICtrlCreateButton("Color...", 15, 90, 60, 25)
- $cButton_Reset = GUICtrlCreateButton("Reset", 15, 190, 60, 25)
- $cButton_Save = GUICtrlCreateButton("Save", 15, 220, 60, 25)
- GUISetState()
- _GDIPlus_Startup()
- $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
- $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iGraphicWidth, $iGraphicHeight, $hGraphic)
- $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
- _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
- _GDIPlus_GraphicsDrawRect($hGraphic, $iGraphicX - 1, $iGraphicY - 1, $iGraphicWidth + 2, $iGraphicHeight + 2)
- _GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
- _ReDraw()
- $hPen_Main = _GDIPlus_PenCreate(0xFF000000, $iPenWidth)
- GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
- GUISetOnEvent($GUI_EVENT_RESTORE, "_ReDraw")
- GUIRegisterMsg($WM_PAINT, "_ReDraw")
- GUICtrlSetOnEvent($cButton_Color, "_ChoosePenColor")
- GUICtrlSetOnEvent($cButton_Reset, "_ResetImage")
- GUICtrlSetOnEvent($cButton_Save, "_SaveImage")
- $aOldPos = "none"
- While Sleep(10)
- $aCursorInfo = GUIGetCursorInfo($hWnd)
- DllStructSetData($tPoint_Mouse, "X", $aCursorInfo[0])
- DllStructSetData($tPoint_Mouse, "Y", $aCursorInfo[1])
- If _WinAPI_PtInRect($tRect_Graphic, $tPoint_Mouse) And _IsPressed("01", $vU32Dll) Then
- If $aOldPos = "none" Then
- $aOldPos = $aCursorInfo
- Else
- If $aOldPos[0] <> $aCursorInfo[0] Or $aOldPos[1] <> $aCursorInfo[1] Then
- _GDIPlus_GraphicsDrawLine($hBuffer, $aOldPos[0] - $iGraphicX, $aOldPos[1] - $iGraphicY, $aCursorInfo[0] - $iGraphicX, $aCursorInfo[1] - $iGraphicY, $hPen_Main)
- _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, $iGraphicX, $iGraphicY, $iGraphicWidth, $iGraphicHeight)
- $aOldPos = $aCursorInfo
- EndIf
- Sleep(10)
- EndIf
- Else
- If IsArray($aOldPos) Then $aOldPos = "none"
- EndIf
- If GUICtrlRead($cInput_AlphaChannel) <> $iAlphaChannel Then
- $iAlphaChannelNew = GUICtrlRead($cInput_AlphaChannel)
- If StringReplace($iAlphaChannelNew, " ", "") = "" Then
- $iAlphaChannelNew = $iAlphaChannel
- GUICtrlSetData($cInput_AlphaChannel, $iAlphaChannelNew)
- EndIf
- $iAlphaChannel = $iAlphaChannelNew
- $iARGB_Color = "0x" & Hex($iAlphaChannel, 2) & StringTrimLeft($iRGB_Color, 2)
- _GDIPlus_PenSetColor($hPen_Main, $iARGB_Color)
- EndIf
- If GUICtrlRead($cInput_PenWidth) <> $iPenWidth Then
- $iPenWidthNew = GUICtrlRead($cInput_PenWidth)
- If StringReplace($iPenWidthNew, " ", "") = "" Then
- $iPenWidthNew = $iPenWidth
- GUICtrlSetData($cInput_PenWidth, $iPenWidth)
- EndIf
- _GDIPlus_PenSetWidth($hPen_Main, $iPenWidthNew)
- $iPenWidthNew = $iPenWidth
- EndIf
- WEnd
- Func _ReDraw()
- _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, $iGraphicX, $iGraphicY, $iGraphicWidth, $iGraphicHeight)
- EndFunc
- Func _ChoosePenColor()
- $iRGB_ColorNew = _ChooseColor(2, $iRGB_Color, 2)
- If $iRGB_ColorNew = -1 Then $iRGB_ColorNew = $iRGB_Color
- $iARGB_Color = "0x" & Hex($iAlphaChannel, 2) & StringTrimLeft($iRGB_ColorNew, 2)
- _GDIPlus_PenSetColor($hPen_Main, $iARGB_Color)
- GUICtrlSetBkColor($cLabel_PreviewColor, $iRGB_ColorNew)
- $iRGB_Color = $iRGB_ColorNew
- EndFunc
- Func _ResetImage()
- _GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
- _ReDraw()
- EndFunc
- Func _SaveImage()
- $sPathDst = FileSaveDialog("Speichern unter", @ScriptDir, "JPEG (*.jpg;*.jpeg)", 16)
- If @error Or StringReplace($sPathDst, " ", "") = "" Then Return
- If StringRight($sPathDst, StringLen($sPathDst) - StringInStr($sPathDst, ".", 0, -1)) <> "jpg" Then
- $sPathDst = StringTrimRight($sPathDst, StringLen($sPathDst) - StringInStr($sPathDst, ".", 0, -1) + 1) & ".jpg"
- EndIf
- _GDIPlus_ImageSaveToFile($hBitmap, $sPathDst)
- EndFunc
- Func _Exit()
- _GDIPlus_GraphicsDispose($hGraphic)
- _GDIPlus_GraphicsDispose($hBuffer)
- _GDIPlus_BitmapDispose($hBitmap)
- _GDIPlus_PenDispose($hPen_Main)
- _GDIPlus_Shutdown()
- Exit
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement