Create a grayscaled image on the fly?

BlitzMax Forums/BlitzMax Beginners Area/Create a grayscaled image on the fly?

Thanks everyone!

My guess is Birdies code is faster as it only uses ONE readpixel a time!

edit: The code works fine and IS A LOT FASTER!

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