Hi!
Has someone written a function that grayscales an existing image file handle?
Grisu
Has someone written a function that grayscales an existing image file handle?
Grisu
SuperStrict Local window:TGadget=CreateWindow("o_O",0,0,640,480) Local canvas:TGadget=CreateCanvas(0,0,640,480,window) Local img:TImage=LoadImage("Porn193882.JPG") MakeGrey img SetGraphics CanvasGraphics(canvas) Cls DrawImage img,0,0 Flip Notify "o_O" End Function MakeGrey(img:TImage) If img=Null RuntimeError "no image!" Local c:Int Local x:Int Local y:Int Local pm:TPixmap=LockImage(img) For y=0 Until ImageHeight(img) For x=0 Until ImageWidth(img) c= ReadPixel(pm,x,y) & 255 c:+(ReadPixel(pm,x,y) Shr 8) & 255 c:+(ReadPixel(pm,x,y) Shr 16) & 255 c:/3 WritePixel pm,x,y,$ff000000|c+256*c+65536*c Next Next UnlockImage img End Function
Function ConvertToBW(i:TImage,frame) Local col,a,r,g,b,cc,x=0,y=0 Local pix:TPixmap pix=LockImage(i,frame) While y<i.height x=0 While x<i.width col = ReadPixel( pix, x, y ) a = ( col & $ff000000) r = ( col & $ff0000 ) Shr 16 g = ( col & $ff00 ) Shr 8 b = ( col & $ff ) cc= (r+g+b)/3 col = a | (cc Shl 16) | (cc Shl 8) | cc WritePixel( pix, x, y, col ) x=x+1 Wend y=y+1 Wend UnlockImage i,frame EndFunction
Function ConvertBW(i:TImage) Local w,h,col,a,r,g,b,cc,x=0,y=0 Local pix:TPixmap=LockImage(i) h= i.height w= i.width While y < h x=0 While x < w col = ReadPixel( pix, x, y ) col = ( col & $ff000000) | ((col & $ff0000) Shl 16) | ((col & $ff00) Shl 8) | (col & $ff) WritePixel( pix, x, y, col ) x=x+1 Wend y=y+1 Wend UnlockImage i EndFunction
Graphics 640,480,0 Local full:TPixmap=LoadPixmap("IMAGEN.jpg") Local gray:TPixmap=CreatePixmap(PixmapWidth(full),PixmapHeight(full),PF_I8,1) For Local y:Int=0 To PixmapHeight(full)-1 For Local x:Int=0 To PixmapWidth(full)-1 WritePixel( gray, x, y, ReadPixel( full, x, y ) ) Next Next DrawPixmap gray,100,100 Flip WaitKey()
Graphics 640,480,0 Local full:TPixmap=LoadPixmap("IMAGEN.jpg") Local gray:TPixmap gray=full.Convert(PF_I8) DrawPixmap gray,100,100 Flip WaitKey()