[R] Changer de couleur un certain pixel par un autre pixel
Posté : lun. 13 déc. 2010 17:57
Bonjour, voilà mon problème j’aimerai remplacer dans une image bmp, uniquement les pixels de couleur 0xe5e5e5 par la couleur 0xffffff. Mais le souci ces que âpres mainte recherche et test je n’arrive pas a faire ceci. J’ai trouvé un exemple de code sur ce lien.
http://www.autoitscript.fr/forum/viewto ... ?f=3&t=921
Le forum anglais en parle aussi.
http://www.autoitscript.com/forum/topic ... __lockbits
Voici le code qui permettrai de réalisé ceci.
Dans ce code je n’arrive pas à comprendre ou le pixel d’entré est pris.
Sur cette ligne qui je pense est le pixel de sortie, je ne comprends pas pourquoi le code de couleur est sur 8 caractères ?
Si je laisse comme ceci, j’ai une trainé noir incompressible en bas à droite de l’image.
Si j’enlève 2 zéro dans le code de couleur de 8 caractères pour qu’il n’en fasse que 6 alors mon image est toute noir (pixel 0x000000).
Dans mon image il n’y a que 2 pixel différant. Le pixel e5e5e5 et le pixel 0x000000.
Comment résoudre le problème ?
http://www.autoitscript.fr/forum/viewto ... ?f=3&t=921
Le forum anglais en parle aussi.
http://www.autoitscript.com/forum/topic ... __lockbits
Voici le code qui permettrai de réalisé ceci.
Code : Tout sélectionner
#include<GDIPlus.au3>
#include<GUIConstantsEx.au3>
global const $largeur_gui=119
global const $hauteur_gui=39
$gui=guicreate("",$largeur_gui,$hauteur_gui)
guisetstate()
_gdiplus_startup()
$image=_gdiplus_imageloadfromfile("test.bmp")
;Get handle to a Graphics object
$graphique=_gdiplus_graphicscreatefromhwnd($gui)
;Draw the picture into the GUI - it will stretch to fit the GUI
_gdiplus_graphicsdrawimageRect($graphique,$image,0,0,100,$hauteur_gui)
;Get $tagGDIPBITMAPDATA structure
$bmp=_gdiplus_bitmapLockbits($image,20,20,60,60,$GDIP_ILMWRITE,$GDIP_PXF32RGB)
if @ERROR then msgbox(0,"","Error locking region for writing")
;Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
$dll=dllstructgetdata($bmp,"Stride")
consolewrite("Bitmap Stride: " & $dll & @CRLF)
;Image width - Number of pixels in one scan line of the bitmap.
$largeur = dllstructgetdata($bmp,"largeur")
consolewrite("Bitmap Width: " & $largeur & @CRLF)
;Image height - Number of scan lines in the bitmap.
$hauteurt=dllstructgetdata($bmp,"hauteur")
consolewrite("Bitmap Height: " & $hauteurt & @CRLF)
;Pixel format - Integer that specifies the pixel format of the bitmap
$pixel=dllstructgetdata($bmp, "pixel")
consolewrite("Bitmap PixelFormat: " & $pixel & @CRLF)
;Scan0 - Pointer to the first (index 0) scan line of the bitmap.
$scan=dllstructgetdata($bmp,"scan")
consolewrite("Bitmap Scan0: " & $scan & @CRLF)
for $for=0 to $hauteurt -1
for $for2=0 to $largeur -1
$pixel=dllstructcreate("dword", $scan+$for*$dll+$for2*4)
dllstructsetdata($pixel,1,0x0000FF00)
;consolewrite(Hex(dllstructgetdata($pixel, 1)) & @CRLF)
next
;consolewrite("-------" & @CRLF)
next
;Unlock region previously locked for writing
_gdiplus_bitmapunlockbits($image,$bmp)
_gdiplus_graphicsdrawimagerect($graphique,$image,100,0,100,100)
while 1
$message=guigetmsg()
if $message=$GUI_EVENT_CLOSE then exitloop
wend
func OnAutoItExit()
if $image then _gdiplus_imagedispose($image)
_gdiplus_shutdown()
endfuncCode : Tout sélectionner
dllstructsetdata($pixel,1,0x0000FF00)Si je laisse comme ceci, j’ai une trainé noir incompressible en bas à droite de l’image.
Si j’enlève 2 zéro dans le code de couleur de 8 caractères pour qu’il n’en fasse que 6 alors mon image est toute noir (pixel 0x000000).
Dans mon image il n’y a que 2 pixel différant. Le pixel e5e5e5 et le pixel 0x000000.
Comment résoudre le problème ?