darkshark Posted November 1, 2010 Share Posted November 1, 2010 (edited) hi guysPlease could someone give me a light? I tried some things with gdiplus but could not!for example:I have this image in 60 x 60:the image is completely black, "but will not always be so, it is an image"and I would leave it like this:ie, every 1 pixel, I paint it pink!but the image resolution can vary, and the color would I paint too, how can I do this? thanks! Edited November 1, 2010 by darkshark Link to comment Share on other sites More sharing options...
UEZ Posted November 1, 2010 Share Posted November 1, 2010 You want to paint over the black image a pink rectangle with same width and height of black image. Is that correct? 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 More sharing options...
AlmarM Posted November 1, 2010 Share Posted November 1, 2010 (edited) You want to paint over the black image a pink rectangle with same width and height of black image. Is that correct?Br,UEZI think he loads an image (size can vary). And he wants to paints a pink pixel each 1 pixel.EDIT: Typo Edited November 1, 2010 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
darkshark Posted November 1, 2010 Author Share Posted November 1, 2010 no, I want to let a pixel of the original image, and the other painting of pink!another example: Link to comment Share on other sites More sharing options...
UEZ Posted November 1, 2010 Share Posted November 1, 2010 (edited) Try this:#include <GDIPlus.au3> _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.bmp;*.gif)")) $iW = _GDIPlus_ImageGetWidth($hImage) $iH = _GDIPlus_ImageGetHeight($hImage) $hGUI = GUICreate("GDI+ Test by UEZ 2010", $iW, $iH, -1, -1, 0x80000000) GUISetState() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iW, $iH) $alpha = "0x80" $color = "7F1F7F" ;pink (hex value!) $hBrush = _GDIPlus_BrushCreateSolid($alpha & $color) _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iW, $iH, $hBrush) While 1 Switch GUIGetMsg() Case -3 _GDIPlus_BrushDispose($hBrush) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Exit EndSwitch WEndYou can change value $alpha and $color.Br,UEZ Edited November 1, 2010 by 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 More sharing options...
iamtheky Posted November 1, 2010 Share Posted November 1, 2010 (edited) With dissolve, does require showing them up front to build the array. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #Include <Array.au3> #include <IE.au3> #Include <string.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <GuiToolTip.au3> Opt("GUIOnEventMode", 1) Opt("GUICloseOnESC", 1) ;;;;;===================================Set picture arrays================================================================== Local $image1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\merlin.gif" Local $image2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\msoobe.jpg" $yGui = 90 $rows = 1 $NumOfImgs = 2 $gui = GUICreate("", $NumOfImgs * 90, $ygui * $rows, 0 , 0, $WS_POPUPWINDOW) ;row 1 GUICtrlCreatePic($image1, 0, 0, $yGui, $yGui) GUICtrlCreatePic($image2, 90, 0, $yGui, $yGui) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $gui) $merlin = _PicToArray(0, 0) $oobe = _PicToArray(90, 0) GUIDelete() Func _PicToArray($x, $y) Dim $BArray[90][90] $firstD = UBound($BArray, 1) - 1 $secondD = UBound($BArray, 2) - 1 For $B = $x To $firstD + $x For $C = $y To $secondD + $y $BArray[$B - $x][$C - $y] = "0x" & Hex(PixelGetColor($B + 1, $C + 1), 6) Next Next Return $BArray EndFunc Func _save($SrcArray , $file) $save = fileopen ($file , 10) for $K = 0 to Ubound($SrcArray, 1) - 1 For $L = 0 To UBound($SrcArray, 2) - 1 filewrite ($save, $SrcArray[$K][$L] & @CRLF) Next Next FileClose ($save) EndFunc Func _DrawPicfromArray($Srcarray, $TimerARG, $offsetX , $offsetY) Dim $ZArray[8100][3] $k = 0 For $i = 0 To 89 For $j = 0 To 89 $ZArray[$k][0] = Random(0,10000,1) $ZArray[$k][1] = $i $ZArray[$k][2] = $j $k+=1 Next Next _ArraySort($ZArray) ;========= Draw array of pixels to desktop at mouse button down =============== Local $aMPos, $dc $start1 = TimerInit () $dif = timerdiff($start1) While 1 If timerdiff($start1) >= $TimerARG Then ExitLoop Endif Local $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", 0) Local $D, $E For $i = 0 To 8099 $D = $ZArray[$i][1] $E = $ZArray[$i][2] _PixelSetColor($D + $offsetX, $E + $offsetY, $Srcarray[$D][$E]) _HPSleep(100,0) Next sleep (2000) For $i = 1 To 8099 step + 2 $D = $ZArray[$i][1] $E = $ZArray[$i][2] _PixelSetColor($D + $offsetX, $E + $offsetY, 0x7F1F7F) _HPSleep(100,0) Next DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $dc[0]) WEnd EndFunc ; Modified from http://www.autoitscript.com/forum/index.php?showtopic=7315&view=findpost&p=178779 Func _PixelSetColor($XCoord, $YCoord, $Color) Local $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", 0) If Not IsArray($dc) Then Return -1 DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $XCoord, "long", $YCoord, "long", _ "0x" & StringRegExpReplace(hex($Color,6), "(..)(..)(..)", "\3\2\1")) ; Change to 0xBBGGRR hex colour format. DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $dc[0]) EndFunc ;==>_PixelSetColor Func _HPSleep($iSleep, $fMs = 1) ; default is milliseconds, otherwise microseconds (1 ms = 1000 µs) If $fMs Then $iSleep *= 1000 ; convert to ms DllCall("ntdll.dll", "dword", "NtDelayExecution", "int", 0, "int64*", -10 * $iSleep) EndFunc ;;;;;===================================================================================================== $Symbol = "Installer Package " $gui = GUICreate("", 90, 90, 0 , 0, $WS_POPUPWINDOW) GUICtrlCreatePic($image2, 0, 0, $yGui, $yGui) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $gui) $Symbol = "Merlin " _DrawPicfromArray ($merlin, '1' , 0 , 0) $Symbol = "MSOOBE" _DrawPicfromArray ($oobe, '1' , 0 , 0) $Symbol = "Merlin " _DrawPicfromArray ($merlin, '1' , 0 , 0) $Symbol = "MSOOBE" _DrawPicfromArray ($oobe, '1' , 0 , 0) ;;;;;;;;;;;END OF INSTALL ACTIONS---------------------------------------------------------------------- ahh superimposed vs every other pixel pink, love some websense blocking image context clues. Edited November 1, 2010 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
darkshark Posted November 1, 2010 Author Share Posted November 1, 2010 (edited) Try this: #include <GDIPlus.au3> _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.bmp;*.gif)")) $iW = _GDIPlus_ImageGetWidth($hImage) $iH = _GDIPlus_ImageGetHeight($hImage) $hGUI = GUICreate("GDI+ Test by UEZ 2010", $iW, $iH, -1, -1, 0x80000000) GUISetState() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iW, $iH) $alpha = "0x80" $color = "7F1F7F" ;pink (hex value!) $hBrush = _GDIPlus_BrushCreateSolid($alpha & $color) _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iW, $iH, $hBrush) While 1 Switch GUIGetMsg() Case -3 _GDIPlus_BrushDispose($hBrush) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Exit EndSwitch WEnd You can change value $alpha and $color. Br, UEZ so the image was superimposed in pink! that's how I'd done, but it was like in the examples cited above S = Edited November 1, 2010 by darkshark Link to comment Share on other sites More sharing options...
UEZ Posted November 1, 2010 Share Posted November 1, 2010 Your image from 1st post was rasterized with pink and my version superimposes the image with pink using the alpha channel. Is this what you are loooking for or you want to rasterize the image? 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 More sharing options...
darkshark Posted November 1, 2010 Author Share Posted November 1, 2010 (edited) rasterizing, same as my picture! I'm testing a few things here to see if I can too! Edited November 1, 2010 by darkshark Link to comment Share on other sites More sharing options...
golfinhu Posted November 1, 2010 Share Posted November 1, 2010 and if you paint pixel by pixel? Link to comment Share on other sites More sharing options...
darkshark Posted November 4, 2010 Author Share Posted November 4, 2010 I've tried everything and just can not! nobody could give me a hint how to do? = [ Link to comment Share on other sites More sharing options...
iamtheky Posted November 4, 2010 Share Posted November 4, 2010 my example paints pixel by pixel (randomly) modify the last argument to specify color. _PixelSetColor($D + $offsetX, $E + $offsetY, $Srcarray[$D][$E]) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
darkshark Posted November 4, 2010 Author Share Posted November 4, 2010 I'll try, thanks! Link to comment Share on other sites More sharing options...
darkshark Posted November 4, 2010 Author Share Posted November 4, 2010 the pictoarray() returns the position of all image pixels, is it? Link to comment Share on other sites More sharing options...
AndyG Posted November 6, 2010 Share Posted November 6, 2010 Hi!Sorry for "hijacking" this thread, but due to the simplicity of the BMP-Format, it is very easy to paint/manipulate "Pixels" with Assembler-Code It is easy to rasterize an image, if the width of the image has an odd number of pixels. The only thing to do is to paint every 2nd pixel to the selected colour...._("use32") ;32bit-Mode _("mov esi," & $Scan) ;Startadress Bitmapdata (Pixel) _("mov ecx," & $iWidth * $iHeight) ;number of Pixels _("mov edi," & $colour) ;... _("_loop:") ;label to jump to _("mov dword[esi],edi") ;colour pixel _("add esi,8") ;every 2. pixel _("sub ecx,2") ;decrement number of remaining pixels _("ja _loop") ;Jump, if ecx is Above 0 (loop until ecx<=0 (whole image rasterized)) _("ret ") ;end programIf the number of pixels in a line is even, you have to set the first pixel in first line (and then every 2nd pixel until the line is full) , second pixel in second line, first pixel in 3rd line and so onIt´s a very easy and not optimized code, using only simple ASM-instructions like MOV, ADD, SUB and conditional jumps . The required #include-file can be found here: expandcollapse popup#include <AssembleIt.au3> #include <GDIPlus.au3> Global $Scan, $iWidth, $iHeight, $colour ;declare variables in Assemblerfunction Func _colour_rasterize() _("use32") ;32bit-Mode _("mov esi," & $Scan) ;Startadress Bitmapdata (Pixel) _("mov ecx," & $iWidth * $iHeight) ;number of Pixels _("mov edi," & $colour) ;... ;width even or odd? _("mov eax," & $iWidth);width into register _("bt eax,0") ;bit test bitnumber and store the result into Carry-Flag CF _("jc _odd") ;if CF=1 (bit0_of_eax=1) then jump _odd ;an even number of pixels in a line is not so easy, because we ;need a counter (EBX) to find out if we have to paint up the first pixel in the line ;or the second one! _("mov ebx,1") ;counter pixel_per_line _("_loop:") ;loop until ecx=0 (whole image rasterized) _("cmp ebx,eax") ;is end of line reached? _("jae _next") ;end of line reached, then _next: _("mov dword[esi],edi") ;else paint pixel _("add esi,8") ;every 2. pixel in memory 8 Byte = 2 pixel AARRGGBB _("add ebx,2") ;increment counter _("sub ecx,2") ;decrement # of remaining pixel _("ja _loop") ;until ecx=0, jump to _loop: _("ret ") ;end program _("_next: ") ;end of line reached _("bt ebx,0") ;last pixel# odd? _("jnc _even_line") ;if even, jump _even_line _("mov ebx,0") ;counter, every 2nd line _("add esi,4") ;next address of pixel in memory _("sub ecx,1") ;remaing # of pixel _("ja _loop") ;loop until ecx=0 (whole image rasterized) _("ret") ;end program _("_even_line:") ;paint first pixel in line _("mov ebx,1") ; _("sub esi,4") ;we are one pixel too far!... _("add ecx,1") ;...so paint the pixel before the actual one _("jmp _loop") ;fill line painting every 2nd pixel ;odd number of pixels in a line, very easy, because every 2nd ;pixel is colored to rasterize the image _("_odd:") _("_loop1:") ;until ecx=0 _("mov dword[esi],edi") ;colour pixel _("add esi,8") ;every 2. pixel _("sub ecx,2") ;decrement number of remaining pixel _("ja _loop1") ;loop until ecx=0 (whole image rasterized) _("ret ") ;end program EndFunc ;==>_colour_rasterize _GDIPlus_Startup() $file = FileOpenDialog("Select 24 or 32 Bpp Image", @ScriptDir, "Images (*.jpg;*.bmp)", 1 + 2) If @error Then Exit $hBitmap = _GDIPlus_BitmapCreateFromFile($file) Local $iWidth, $iHeight, $hBitmapData, $Scan, $Stride, $tPixelData, $pPixelStruct $iWidth = _GDIPlus_ImageGetWidth($hBitmap) $iHeight = _GDIPlus_ImageGetHeight($hBitmap) $hBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iWidth, $iHeight, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32RGB) $Scan = DllStructGetData($hBitmapData, "Scan0") ;Startadress of Bitmapdata $colour = 0x7FF17FFF ;pink $ret = _AssembleIt("ptr", "_colour_rasterize") ;Run the Assemblercode _GDIPlus_BitmapUnlockBits($hBitmap, $hBitmapData) FileDelete(@ScriptDir & "\raster_pink.bmp") _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\raster_pink.bmp") ShellExecute(@ScriptDir & "\raster_pink.bmp") FasmExit($Fasm) ;FASM remove from memoryAnd the same in "native" AutoIt , a little bit slower (60 times) but no additional #includes needed and compilable in 32/64Bit! #include <GDIPlus.au3> _GDIPlus_Startup() $file = FileOpenDialog("Select 24 or 32 Bpp Image", @ScriptDir, "Images (*.jpg;*.bmp)", 1 + 2) If @error Then Exit $hBitmap = _GDIPlus_BitmapCreateFromFile($file) Local $iWidth, $iHeight, $hBitmapData, $Scan, $Stride, $tPixelData, $pPixelStruct $iWidth = _GDIPlus_ImageGetWidth($hBitmap) $iHeight = _GDIPlus_ImageGetHeight($hBitmap) $hBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iWidth, $iHeight, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32RGB) $Scan = DllStructGetData($hBitmapData, "Scan0") ;Startadress of Bitmapdata $struct = DllStructCreate("dword[" & $iWidth * $iHeight & "]", $Scan) ;struct at startaddress of pixeldata in memory $colour = 0x7FF17FFF ;pink If $iWidth / 2 <> Int($iWidth / 2) Then ;odd number of pixels in line For $i = 1 To $iWidth * $iHeight Step 2 ;every second pixel DllStructSetData($struct, 1, $colour, $i) ;"paint" colour in memory Next Else ;even number of pixels in a line $flag = 1 For $l = 0 To $iHeight - 1 ;every line $flag = Not ($flag) ;flag 0,1,0,1,0,1,0..... For $i = $flag To $iWidth Step 2 ;every 2nd pixel to colour DllStructSetData($struct, 1, $colour, $l * $iWidth + $i);"paint" colour in memory Next Next EndIf _GDIPlus_BitmapUnlockBits($hBitmap, $hBitmapData) FileDelete(@ScriptDir & "\raster_pink.bmp") _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\raster_pink.bmp") _GDIPlus_Shutdown() ShellExecute(@ScriptDir & "\raster_pink.bmp") Link to comment Share on other sites More sharing options...
Yashied Posted November 6, 2010 Share Posted November 6, 2010 Look at _GDIPlus_BitmapSetPixel() from My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
darkshark Posted November 6, 2010 Author Share Posted November 6, 2010 (edited) Hi! Sorry for "hijacking" this thread, but due to the simplicity of the BMP-Format, it is very easy to paint/manipulate "Pixels" with Assembler-Code It is easy to rasterize an image, if the width of the image has an odd number of pixels. The only thing to do is to paint every 2nd pixel to the selected colour...._("use32") ;32bit-Mode _("mov esi," & $Scan) ;Startadress Bitmapdata (Pixel) _("mov ecx," & $iWidth * $iHeight) ;number of Pixels _("mov edi," & $colour) ;... _("_loop:") ;label to jump to _("mov dword[esi],edi") ;colour pixel _("add esi,8") ;every 2. pixel _("sub ecx,2") ;decrement number of remaining pixels _("ja _loop") ;Jump, if ecx is Above 0 (loop until ecx<=0 (whole image rasterized)) _("ret ") ;end program If the number of pixels in a line is even, you have to set the first pixel in first line (and then every 2nd pixel until the line is full) , second pixel in second line, first pixel in 3rd line and so on It´s a very easy and not optimized code, using only simple ASM-instructions like MOV, ADD, SUB and conditional jumps . The required #include-file can be found here: expandcollapse popup#include <AssembleIt.au3> #include <GDIPlus.au3> Global $Scan, $iWidth, $iHeight, $colour ;declare variables in Assemblerfunction Func _colour_rasterize() _("use32") ;32bit-Mode _("mov esi," & $Scan) ;Startadress Bitmapdata (Pixel) _("mov ecx," & $iWidth * $iHeight) ;number of Pixels _("mov edi," & $colour) ;... ;width even or odd? _("mov eax," & $iWidth);width into register _("bt eax,0") ;bit test bitnumber and store the result into Carry-Flag CF _("jc _odd") ;if CF=1 (bit0_of_eax=1) then jump _odd ;an even number of pixels in a line is not so easy, because we ;need a counter (EBX) to find out if we have to paint up the first pixel in the line ;or the second one! _("mov ebx,1") ;counter pixel_per_line _("_loop:") ;loop until ecx=0 (whole image rasterized) _("cmp ebx,eax") ;is end of line reached? _("jae _next") ;end of line reached, then _next: _("mov dword[esi],edi") ;else paint pixel _("add esi,8") ;every 2. pixel in memory 8 Byte = 2 pixel AARRGGBB _("add ebx,2") ;increment counter _("sub ecx,2") ;decrement # of remaining pixel _("ja _loop") ;until ecx=0, jump to _loop: _("ret ") ;end program _("_next: ") ;end of line reached _("bt ebx,0") ;last pixel# odd? _("jnc _even_line") ;if even, jump _even_line _("mov ebx,0") ;counter, every 2nd line _("add esi,4") ;next address of pixel in memory _("sub ecx,1") ;remaing # of pixel _("ja _loop") ;loop until ecx=0 (whole image rasterized) _("ret") ;end program _("_even_line:") ;paint first pixel in line _("mov ebx,1") ; _("sub esi,4") ;we are one pixel too far!... _("add ecx,1") ;...so paint the pixel before the actual one _("jmp _loop") ;fill line painting every 2nd pixel ;odd number of pixels in a line, very easy, because every 2nd ;pixel is colored to rasterize the image _("_odd:") _("_loop1:") ;until ecx=0 _("mov dword[esi],edi") ;colour pixel _("add esi,8") ;every 2. pixel _("sub ecx,2") ;decrement number of remaining pixel _("ja _loop1") ;loop until ecx=0 (whole image rasterized) _("ret ") ;end program EndFunc ;==>_colour_rasterize _GDIPlus_Startup() $file = FileOpenDialog("Select 24 or 32 Bpp Image", @ScriptDir, "Images (*.jpg;*.bmp)", 1 + 2) If @error Then Exit $hBitmap = _GDIPlus_BitmapCreateFromFile($file) Local $iWidth, $iHeight, $hBitmapData, $Scan, $Stride, $tPixelData, $pPixelStruct $iWidth = _GDIPlus_ImageGetWidth($hBitmap) $iHeight = _GDIPlus_ImageGetHeight($hBitmap) $hBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iWidth, $iHeight, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32RGB) $Scan = DllStructGetData($hBitmapData, "Scan0") ;Startadress of Bitmapdata $colour = 0x7FF17FFF ;pink $ret = _AssembleIt("ptr", "_colour_rasterize") ;Run the Assemblercode _GDIPlus_BitmapUnlockBits($hBitmap, $hBitmapData) FileDelete(@ScriptDir & "\raster_pink.bmp") _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\raster_pink.bmp") ShellExecute(@ScriptDir & "\raster_pink.bmp") FasmExit($Fasm) ;FASM remove from memory And the same in "native" AutoIt , a little bit slower (60 times) but no additional #includes needed and compilable in 32/64Bit! #include <GDIPlus.au3> _GDIPlus_Startup() $file = FileOpenDialog("Select 24 or 32 Bpp Image", @ScriptDir, "Images (*.jpg;*.bmp)", 1 + 2) If @error Then Exit $hBitmap = _GDIPlus_BitmapCreateFromFile($file) Local $iWidth, $iHeight, $hBitmapData, $Scan, $Stride, $tPixelData, $pPixelStruct $iWidth = _GDIPlus_ImageGetWidth($hBitmap) $iHeight = _GDIPlus_ImageGetHeight($hBitmap) $hBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iWidth, $iHeight, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32RGB) $Scan = DllStructGetData($hBitmapData, "Scan0") ;Startadress of Bitmapdata $struct = DllStructCreate("dword[" & $iWidth * $iHeight & "]", $Scan) ;struct at startaddress of pixeldata in memory $colour = 0x7FF17FFF ;pink If $iWidth / 2 <> Int($iWidth / 2) Then ;odd number of pixels in line For $i = 1 To $iWidth * $iHeight Step 2 ;every second pixel DllStructSetData($struct, 1, $colour, $i) ;"paint" colour in memory Next Else ;even number of pixels in a line $flag = 1 For $l = 0 To $iHeight - 1 ;every line $flag = Not ($flag) ;flag 0,1,0,1,0,1,0..... For $i = $flag To $iWidth Step 2 ;every 2nd pixel to colour DllStructSetData($struct, 1, $colour, $l * $iWidth + $i);"paint" colour in memory Next Next EndIf _GDIPlus_BitmapUnlockBits($hBitmap, $hBitmapData) FileDelete(@ScriptDir & "\raster_pink.bmp") _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\raster_pink.bmp") _GDIPlus_Shutdown() ShellExecute(@ScriptDir & "\raster_pink.bmp") worked perfec! not gonna lie to say I had Awe by low-level languages, but I never got to study them! but I'll study the code and try to understand it =) thanks a lot! Edited November 6, 2010 by darkshark Link to comment Share on other sites More sharing options...
AndyG Posted November 6, 2010 Share Posted November 6, 2010 (edited) The "low-level"-code makes sense, if you have computationally intensive code inside of long loops. So 99,98% of all normal "GUI-Stuff" is well done by native AutoIt-Code and there is no chance to speed up this code with ASM. Edited November 6, 2010 by AndyG Link to comment Share on other sites More sharing options...
UEZ Posted November 6, 2010 Share Posted November 6, 2010 (edited) Here the modified version of AndyG's AutoIt version using _GDIPlus_BitmapSetPixel() as suggested by Yashied:#include <GDIPlus.au3> _GDIPlus_Startup() $file = FileOpenDialog("Select 24 or 32 Bpp Image", @ScriptDir, "Images (*.jpg;*.bmp)", 1 + 2) If @error Then Exit $hBitmap = _GDIPlus_BitmapCreateFromFile($file) Local $iWidth, $iHeight, $hBitmapData $iWidth = _GDIPlus_ImageGetWidth($hBitmap) $iHeight = _GDIPlus_ImageGetHeight($hBitmap) $colour = 0x7FF17FFF ;pink For $y = 0 To $iHeight For $x = Mod($y, 2) To $iWidth Step 2 _GDIPlus_BitmapSetPixel($hBitmap, $x, $y, $colour) Next Next _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\raster_pink.bmp") _GDIPlus_Shutdown() ShellExecute(@ScriptDir & "\raster_pink.bmp") Func _GDIPlus_BitmapSetPixel($hBitmap, $iX, $iY, $iARGB = 0xFF000000) Local $aRet $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapSetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "dword", $iARGB) Return EndFunc ;==>_GDIPlus_BitmapSetPixelBr,UEZ Edited November 6, 2010 by 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 More sharing options...
darkshark Posted November 6, 2010 Author Share Posted November 6, 2010 Here the modified version of AndyG's AutoIt version using _GDIPlus_BitmapSetPixel() as suggested by Yashied: #include <GDIPlus.au3> _GDIPlus_Startup() $file = FileOpenDialog("Select 24 or 32 Bpp Image", @ScriptDir, "Images (*.jpg;*.bmp)", 1 + 2) If @error Then Exit $hBitmap = _GDIPlus_BitmapCreateFromFile($file) Local $iWidth, $iHeight, $hBitmapData $iWidth = _GDIPlus_ImageGetWidth($hBitmap) $iHeight = _GDIPlus_ImageGetHeight($hBitmap) $colour = 0x7FF17FFF ;pink For $y = 0 To $iHeight + 1 For $x = Mod($y, 2) To $iWidth + 1 Step 2 _GDIPlus_BitmapSetPixel($hBitmap, $x, $y, $colour) Next Next _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\raster_pink.bmp") _GDIPlus_Shutdown() ShellExecute(@ScriptDir & "\raster_pink.bmp") Func _GDIPlus_BitmapSetPixel($hBitmap, $iX, $iY, $iARGB = 0xFF000000) Local $aRet $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapSetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "dword", $iARGB) Return EndFunc ;==>_GDIPlus_BitmapSetPixel Br, UEZ worked well, and the code is much more "simple" Thank you for your help! really thanks =) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now