Jump to content

Array/GDIPlus help!!


Recommended Posts

im writing an icon editor but i cannot figure out how to write the fill bucket all of the pixels are avalable in th 64x64 image array

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <ButtonConstants.au3>
#include <GDIPlus.au3>
#include "ColorPicker.au3"
#include <array.au3>
#include <misc.au3>
#include <WinAPI.au3>
#include <GuiStatusBar.au3>

_GDIPlus_Startup()
Global $xpx = 64, $ypx = 64,$xap = @DesktopWidth-$xpx*10
Global $image[$xpx][$ypx][2], $3 = 0,$xp = Round($xap/2,-1) , $yp = 50
$Paint = GUICreate("Paint", 700, 700, -1, -1, -1, -1)
GUISetState(@SW_SHOW)
GUISetState(@SW_MAXIMIZE)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($Paint)
$rbrush = _GDIPlus_BrushCreateSolid()
$ebrush = _GDIPlus_BrushCreateSolid()
_GDIPlus_BrushSetSolidColor($ebrush, 0xFFFFFFFF)
$hFile = GUICtrlCreateMenu('File')
$hFile_New = GUICtrlCreateMenuItem('New ctrl + N',$hFile)
$hFile_Open = GUICtrlCreateMenuItem('Open Ctrl + O',$hFile)
GUICtrlCreateMenuItem('',$hFile)
$hFile_Save = GUICtrlCreateMenuItem('Save Ctrl + S',$hFile)
$hFile_SaveAs = GUICtrlCreateMenuItem('Save As Ctrl + Shift + S',$hFile)
$hImage = GUICtrlCreateMenu("Image")
$hImage_Clear = GUICtrlCreateMenuItem("Clear", $hImage)
$Trans = GUICtrlCreateSlider(80, 0, 255, 20)
$ps = GUICtrlCreateLabel('Transparency : 100 %',0,0,80,40)
GUICtrlSetData($Trans, 255)
For $i = 0 To $ypx - 1;loading background
 For $x = 0 To $xpx - 1
  $p = _GDIPlus_GraphicsFillRect($hGraphic, $x * 10 + $xp, $i * 10 + $yp, 10, 10, $ebrush)
   $image[$i][$x][0] = '0x00FFFFFF'
  If $3 = 0 Then
   _GDIPlus_BrushSetSolidColor($ebrush, 0xFF999999)
   $3 = 1
  Else
   _GDIPlus_BrushSetSolidColor($ebrush, 0xFFFFFFFF)
   $3 = 0
  EndIf
 Next
 If $3 = 0 Then
  _GDIPlus_BrushSetSolidColor($ebrush, 0xFF999999)
  $3 = 1
 Else
  _GDIPlus_BrushSetSolidColor($ebrush, 0xFFFFFFFF)
  $3 = 0
 EndIf
Next
_GDIPlus_BrushSetSolidColor($rbrush, 0xFF000000)
$e = GUICtrlCreateButton("eraser", 50, 50, 50, 50)
$b = GUICtrlCreateButton("Brush", 0, 100, 50, 50)
$hInstance = _WinAPI_LoadLibrary(@SystemDir & '\mspaint.exe')
$hCursor = DllCall('user32.dll', 'ptr', 'LoadCursor', 'ptr', $hInstance, 'dword', 1204)
$hCursor = $hCursor[0]
_WinAPI_FreeLibrary($hInstance)
$id = _GUIColorPicker_Create('', 0, 50, 50, 50, 0x000000, BitOR($CP_FLAG_DEFAULT, $CP_FLAG_CHOOSERBUTTON), 0, -1, -1, $hCursor, 'Colour Picker')
$status = _GUICtrlStatusBar_Create($Paint)
Local $aParts[3] = [150, 350, -1]
_GUICtrlStatusBar_SetParts($status, $aParts)
_GUICtrlStatusBar_SetText($status, 'Hex Colour Code : 0xFF000000', 1)
_GUICtrlStatusBar_SetText($status, 'Color Name : Black')
$er = 0
While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $hImage_Clear
   _GDIPlus_BrushSetSolidColor($rbrush, 0xFFFFFFFF)
   $3 = 0
   For $i = 0 To $ypx - 1;loading background
    For $x = 0 To $xpx - 1
     $p = _GDIPlus_GraphicsFillRect($hGraphic, $x * 10 + $xp, $i * 10 + $yp, 10, 10, $ebrush)
     If $3 = 0 Then
      _GDIPlus_BrushSetSolidColor($ebrush, 0xFF999999)
      $3 = 1
     Else
      _GDIPlus_BrushSetSolidColor($ebrush, 0xFFFFFFFF)
      $3 = 0
     EndIf
    Next
    If $3 = 0 Then
     _GDIPlus_BrushSetSolidColor($ebrush, 0xFF999999)
     $3 = 1
    Else
     _GDIPlus_BrushSetSolidColor($ebrush, 0xFFFFFFFF)
     $3 = 0
    EndIf
   Next
  Case $e
   $er = 1
  Case $b
   $er = 0
   case $trans
   $colour = _GDIPlus_BrushGetSolidColor($rbrush)
   Local $tran
      $tran = GUICtrlRead($Trans)
   GUICtrlSetData($ps,'Transparency : ' & $tran & " %")
   _GDIPlus_BrushSetSolidColor($rbrush,'0x' & Hex(Round($tran*2.55), 2) &StringTrimLeft(Hex($colour,8),2))
   _GUICtrlStatusBar_SetText($status, 'Hex Colour Code : ' & '0x' & hex(Round($tran*2.55),2) &StringTrimLeft(Hex($colour,8),2), 1)
  Case $id
   $s = _GUIColorPicker_GetColor($id, 1)
   Local $tran
      $tran = GUICtrlRead($Trans)
   GUICtrlSetData($ps,'Transparency : ' & $tran & " %")
   $icolour = '0x' & Hex($tran*2, 2) & Hex($s[0], 6)
   _GUICtrlStatusBar_SetText($status, 'Hex Colour Code : ' & $icolour, 1)
   If $s[1] <> '' Then
    _GUICtrlStatusBar_SetText($status, 'Color Name : ' & $s[1])
   Else
    _GUICtrlStatusBar_SetText($status, 'Color Name : No Name')
   EndIf
   _GDIPlus_BrushSetSolidColor($rbrush, $icolour)
  Case $GUI_EVENT_PRIMARYDOWN
   If $er Then
    _erase()
   Else
    _paint()
   EndIf
 EndSwitch
WEnd
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func _paint()
 Do
  $cPos = GUIGetCursorInfo($Paint)
  Local $x = StringTrimRight($cPos[0], 1) & 0, $y = StringTrimRight($cPos[1], 1) & 0
  If $x >= $xp And $y >= $yp And $x < $xpx * 10 + $xp And $y < $ypx * 10 + $yp Then
  $yx1 = $yp - $y
   $xx1 = $xp - $x
   $yx = StringReplace($yx1 / 10, "-", "")
   $xx = StringReplace($xx1 / 10, "-", "")
   If $image[$yx][$xx][0] <> '0x'&hex( _GDIPlus_BrushGetSolidColor($rbrush),8) Then
   $h = _GDIPlus_GraphicsFillRect($hGraphic, $x, $y, 10, 10, $rbrush)
   $image[$yx][$xx][0] = '0x'&hex( _GDIPlus_BrushGetSolidColor($rbrush),8)
   EndIf
   
  EndIf
 Until Not $cPos[2]
EndFunc   ;==>_paint
Func _erase()
 Do
  $cPos = GUIGetCursorInfo($Paint)
  Local $x = StringTrimRight($cPos[0], 1) & 0, $y = StringTrimRight($cPos[1], 1) & 0
  If $x >= $xp And $y >= $yp And $x < $xpx * 10 + $xp And $y < $ypx * 10 + $yp Then
  $yx1 = $yp - $y
   $xx1 = $xp - $x
   $yx = StringReplace($yx1 / 10, "-", "")
   $xx = StringReplace($xx1 / 10, "-", "")
   If isodd($xx) And isodd($yx) Then
    _GDIPlus_BrushSetSolidColor($ebrush, 0xFFFFFFFF)
   ElseIf isodd($xx) = 0 And isodd($yx) = 0 Then
    _GDIPlus_BrushSetSolidColor($ebrush, 0xFFFFFFFF)
   Else
    _GDIPlus_BrushSetSolidColor($ebrush, 0xFF999999)
   EndIf
   $h = _GDIPlus_GraphicsFillRect($hGraphic, $x, $y, 10, 10, $ebrush)
   $image[$yx][$xx][0] = '0x00FFFFFF'
  EndIf
 Until Not $cPos[2]
EndFunc   ;==>_erase
Func isodd($number)
 $chr = StringRight($number, 1)
 Switch $chr
  Case 1, 3, 5, 7, 9
   Return 0
  Case 0, 2, 4, 6, 8
   Return 1
 EndSwitch
EndFunc   ;==>isodd

All my projects live on github

Link to comment
Share on other sites

#include "ColorPicker.au3"

Where is it located ?

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

You are painting to a graphic handle not to a bitmap. Either you assign a bitmap to the graphic handle

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphic)
$hGfxContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

or you create a bitmap where you set parallel the same pixels in the background.

 

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 2 weeks later...

im not the best with GDI+ can you show me how to implement the code

You are painting to a graphic handle not to a bitmap. Either you assign a bitmap to the graphic handle

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphic)
$hGfxContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

or you create a bitmap where you set parallel the same pixels in the background.

 

Br,

UEZ

All my projects live on github

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