Inversé les couleurs d'une image
Publié : sam. 27/févr./2010 1:52
Bonjour,
voilà ce code vous permet d'inverser la couleur des pixels d'une image.
Si jamais ça peu servir a quel qu'un le voici
:
@++
voilà ce code vous permet d'inverser la couleur des pixels d'une image.
Si jamais ça peu servir a quel qu'un le voici

Code : Tout sélectionner
Structure img
x.l
y.l
color.l
EndStructure
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()
file$ = OpenFileRequester("fichier image", "", "image compatible|*.bmp;*.jpg;*.png;*.tga;*.tif", 0) ; <---- ont choisit une image bitmap
If LoadImage(1, file$) ; <--- ont charge l'image du dessus
If StartDrawing(ImageOutput(1))
width = ImageWidth(1) ; <--- ont prend la largeur de l'image
height = ImageHeight(1) ; <--- ont prend la hauteur de l'image
size = width * height ; <--- ont multiplie la largeur par la hauteur pour savoir le nombre de pixels au total
Dim Array.img(size)
; <------------------------- ont récupère la couleur de chaque pixel -----------------------
i = 0
For y = 0 To height - 1
For x = 0 To width - 1
color = Point(x, y)
Array(i)\x = x
Array(i)\y = y
Array(i)\color = color
i + 1
Next
Next
; <------------------------------------------------------------------------------------------
StopDrawing()
EndIf
EndIf
If OpenWindow(0, 0, 0, ImageWidth(1), ImageHeight(1), "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) ; <------------------------- ont ouvre une fenêtre a la taille de l'image
If CreateImage(0, ImageWidth(1), ImageHeight(1)) ; <------------------------- ont charge l'environnement image
If StartDrawing(ImageOutput(0))
For i = 0 To size - 1
i = 0
For y = 0 To height - 1
For x = 0 To width - 1
i + 1
Plot(Array(i)\x = x, Array(i)\y = y, RGB(255-Red(Array(i)\color), 255-Green(Array(i)\color), 255-Blue(Array(i)\color))) ; <----- ici ont redessine pixel par pixel sur le Drawing() couleur inversé
Next
Next
Next
StopDrawing()
EndIf
EndIf
ImageGadget(0, 0, 0, 0, 0, ImageID(0))
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
EndIf
; <------------------------- et ont quitte
@++