Search the Community
Showing results for tags 'pixelize'.
-
An "improper" "unusual" use of Excel the script allows the creation of artistic images by simply coloring the background of the individual cells of the Excel workbook. Although definitely useless ... I find it quite funny though have a good time many thanks to @UEZ , @Malkey , @water p.s. I think the pixelite + color to array process can be simplified, but I used the two ready-made functions provided by UEZ and Malkey. I thank both of you (credits and links in listing) p.p.s. strange behaviour: while excell is filling cells, if you move the mouse pointer off the excell window, the fill speed increases ... (?) ; =============================================================================================================================== ; Name ..........: Excel in art ; Description ...: This script allows the creation of artistic images in Excel from a choosed picture. ; The picture is done by simply coloring the background of the individual cells of an Excel workbook. ; Although definitely useless, I find it quite funny though ; ; Return values .: An artistic image in an Excel workbook ; Author ........: Addiego Gianni (chimp) ; Modified ......: ; Remarks .......: Many thanks to UEZ, Malkey and Water ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== #include <GDIPlus.au3> #include <Excel.au3> _PixelsToCells(50) ; <-- Parameter 50 is the cumber of horizontal Excel cells to be filled MsgBox(64, "All done", "Excel art is ready") Func _PixelsToCells($iHcells = 50) ; Check application object Local $oExcel = _Excel_Open() If Not IsObj($oExcel) Then MsgBox(16, "Error", "Sorry, You need to have 'Excel' intalled") ; Choose Image File Local $sPath = FileOpenDialog("Choose Image File", @ScriptDir & "", "Images (*.gif;*.png;*.jpg;*.bmp)| All (*.*)") If $sPath = '' Then Exit MsgBox(16, "Error", "Sorry, no image was chosen") ; Create a new Excel workbook $oWorkbook = _Excel_BookNew($oExcel, 1) ; initialize GDI+ _GDIPlus_Startup() Local $hBmp = _GDIPlus_BitmapCreateFromFile($sPath) Local $iWidth = _GDIPlus_ImageGetWidth($hBmp) ; get image width ; Local $iHeight = _GDIPlus_ImageGetHeight($hBmp) ; not needed here Local $iStep = $iWidth / $iHcells ; calculate the pixelation factor Local $hBitmap_new = _GDIPlus_PixelateBitmap($hBmp, $iStep) ; pixelate the image Local $aPixelColors = _FileImageToArray($hBitmap_new) ; get pixel colors ; reduce Excel columns width Local $xx = 1, $yy = 1 For $iCol = 0 To UBound($aPixelColors, 2) - 1 Step $iStep $oWorkbook.Sheets(1).Columns($xx).ColumnWidth = 1 $xx += 1 Next ; reduce Excel rows height For $iRow = 0 To UBound($aPixelColors) - 1 Step $iStep $oWorkbook.Sheets(1).Rows($yy).RowHeight = 9 $yy += 1 Next $xx = 1 $yy = 1 For $iRow = 0 To UBound($aPixelColors) - 1 Step $iStep For $iCol = 0 To UBound($aPixelColors, 2) - 1 Step $iStep $oWorkbook.Sheets(1).Range(_Excel_ColumnToLetter($xx) & $yy).Interior.Color = Number("0x" & $aPixelColors[$iRow][$iCol]) $xx += 1 Next $yy += 1 $xx = 1 Next _GDIPlus_BitmapDispose($hBmp) _GDIPlus_Shutdown() EndFunc ;==>_PixelsToCells ; by UEZ ; https://www.autoitscript.com/forum/topic/167707-imagepixelate/?do=findComment&comment=1227509 Func _GDIPlus_PixelateBitmap($hBitmap, $iPixelate, $bSmooth = 1) Local $iWidth = _GDIPlus_ImageGetWidth($hBitmap), $iHeight = _GDIPlus_ImageGetHeight($hBitmap) Local $iNewW = Round($iWidth / $iPixelate, 0), $iNewH = Round($iHeight / $iPixelate, 0) Local $hBitmap_scaled = _GDIPlus_BitmapCreateFromScan0($iNewW, $iNewH) Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_scaled) Local $iInterpolation = 5 If $bSmooth Then $iInterpolation = $GDIP_INTERPOLATIONMODE_BILINEAR _GDIPlus_GraphicsSetInterpolationMode($hCtxt, $iInterpolation) _GDIPlus_GraphicsDrawImageRect($hCtxt, $hBitmap, 0, 0, $iNewW, $iNewH) _GDIPlus_GraphicsDispose($hCtxt) Local $hBitmap_pixelated = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_pixelated) _GDIPlus_GraphicsSetInterpolationMode($hCtxt, $GDIP_INTERPOLATIONMODE_NearestNeighbor) _GDIPlus_GraphicsDrawImageRectRect($hCtxt, $hBitmap_scaled, 0, 0, $iNewW, $iNewH, -$iPixelate, -$iPixelate, $iWidth + 2 * $iPixelate, $iHeight + 2 * $iPixelate) _GDIPlus_GraphicsDispose($hCtxt) Return $hBitmap_pixelated EndFunc ;==>_GDIPlus_PixelateBitmap ; by Malkey ; https://www.autoitscript.com/forum/topic/112540-is-there-a-function-for-reading-images-into-2d-arrays/?do=findComment&comment=788472 Func _FileImageToArray($hImage) Local $Reslt, $stride, $format, $Scan0, $iIW, $iIH ; , $hImage Local $v_Buffer, $width, $height ; _GDIPlus_Startup() ; $hImage = _GDIPlus_ImageLoadFromFile($sFileName) $iIW = _GDIPlus_ImageGetWidth($hImage) $iIH = _GDIPlus_ImageGetHeight($hImage) ProgressOn("Progress Bar", "Filling a " & $iIW & " x " & $iIH & " size array.", "0 percent") $Reslt = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iIW, $iIH, $GDIP_ILMREAD, $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits () $width = DllStructGetData($Reslt, "width") $height = DllStructGetData($Reslt, "height") $stride = DllStructGetData($Reslt, "stride") $format = DllStructGetData($Reslt, "format") $Scan0 = DllStructGetData($Reslt, "Scan0") Local $aArray[$height][$width] For $j = 0 To $iIH - 1 For $i = 0 To $iIW - 1 $v_Buffer = DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4)) $aArray[$j][$i] = StringRegExpReplace(Hex(DllStructGetData($v_Buffer, 1), 6), "(.{2})(.{2})(.{2})", "\3\2\1") ; To RGB format Next ProgressSet(Int(100 * $j / ($iIH)), Int(100 * $j / ($iIH)) & " percent") Next _GDIPlus_BitmapUnlockBits($hImage, $Reslt) ProgressOff() _GDIPlus_ImageDispose($hImage) Return $aArray EndFunc ;==>_FileImageToArray
-
ImagePixelate function : Func _GDIPlus_ImagePixelate ( $hImage, $iPixelBlockSize=10 ) If $iPixelBlockSize < 1 Then Return SetError ( 1, 0, 0 ) Local $iWidth = _GDIPlus_ImageGetWidth ( $hImage ) If $iPixelBlockSize > $iWidth Then Return SetError ( 2, 0, 0 ) Local $iWidthAdapted = $iWidth - Mod ( $iWidth, $iPixelBlockSize ) ; adapt size for avoid no Pixelated zone on the right side. Local $iHeight = _GDIPlus_ImageGetHeight ( $hImage ) If $iPixelBlockSize > $iHeight Then Return SetError ( 3, 0, 0 ) Local $iHeightAdapted = $iHeight - Mod ( $iHeight, $iPixelBlockSize ) ; adapt size for avoid no Pixelated zone on the bottom side. Local $hBitmap = _GDIPlus_BitmapCreateFromScan0 ( $iWidthAdapted, $iHeightAdapted ) Local $hContext = _GDIPlus_ImageGetGraphicsContext ( $hBitmap ) _GDIPlus_GraphicsDrawImageRect ( $hContext, $hImage, 0, 0, $iWidthAdapted, $iHeightAdapted ) _GDIPlus_GraphicsDispose ( $hContext ) Local $tBitmapData = _GDIPlus_BitmapLockBits ( $hBitmap, 0, 0, $iWidthAdapted, $iHeightAdapted, BitOR ( $GDIP_ILMWRITE, $GDIP_ILMREAD ), $GDIP_PXF32ARGB ) Local $iScan0 = DllStructGetData ( $tBitmapData, 'Scan0' ) Local $tPixel = DllStructCreate ( 'int[' & $iWidthAdapted * $iHeightAdapted & '];', $iScan0 ) Local $iPixelColor For $x = 0 To $iWidthAdapted - $iPixelBlockSize Step $iPixelBlockSize For $y = 0 To $iHeightAdapted - $iPixelBlockSize Step $iPixelBlockSize $iPixelColor = DllStructGetData ( $tPixel, 1, $x*$iHeightAdapted + 1 + $y ) For $i = $x To $x + $iPixelBlockSize -1 ; create pixel block with same color. For $j = $y To $y + $iPixelBlockSize -1 DllStructSetData ( $tPixel, 1, $iPixelColor, $i*$iHeightAdapted + 1 + $j ) Next Next Next Next _GDIPlus_BitmapUnlockBits ( $hBitmap, $tBitmapData ) Local $hBitmap_Scaled = _GDIPlus_ImageResize ( $hBitmap, $iWidth, $iHeight ) ; restore original size. _GDIPlus_BitmapDispose ( $hBitmap ) $tPixel = 0 $tBitmapData = 0 Return $hBitmap_Scaled EndFunc ;==> _GDIPlus_ImagePixelate() Working on an other project, i made a pause by playing with pixellated image effect. Avoid big images, it's a bit slow. Don't know if it can be usefull to someone... Sure that an unpixelate/depixelize function should be better, but it's not for today ! Just run example, it's fun. ImagePixelate Example : ImagePixelate Example.au3.html