Read/write to a loaded TImage?
BlitzMax Forums/BlitzMax Beginners Area/Read/write to a loaded TImage?| 
 | ||
| Okay, my bullets are drawn in LIGHTBLEND drawing mode, and I want to give the use the option of darkening the background if they want to. I tried doing it this way: ' (Near start of program) Global DarkenBG:Float = .5 ' (Somewhere in my main draw routine...) Backgrounds.Draw() If DarkenBG > 0 SetAlpha (DarkenBG) SetColor (0,0,0) DrawRect (0,0,width,height) Endif SetColor(255,255,255) Bullets.Draw() This provided good results, but it slows my game down a little bit. So now I'm trying to figure out how to do it right after the background image is cached: 
' (Somewhere in the image-loading part of my program...)
'Apply darkening layer to BG if DarkenBG mode is set above 0.
If DarkenBG > 0
   Local map:TPixmap=LockImage(Self.BackgroundImage)
   For Local x:Int = 1 To Self.BackgroundImage.width
      For Local y:Int = 1 To Self.BackgroundImage.height
        Local argb:Int = ReadPixel(map,x,y)
        Local a:Byte =(argb Shr 24) & $ff
        Local r:Byte=(argb Shr 16) & $ff
        Local g:Byte=(argb Shr 8) & $ff
        Local b:Byte=argb & $ff
        r:*DarkenBG
        g:*DarkenBG
        b:*DarkenBG
        WritePixel(map,x,y,a|r|g|b)
      Next
    Next
  UnlockImage(Self.BackgroundImage)
EndIf
(Basically, I just wanna draw a semitransparent black rectangle on the image I loaded from my computer. OR make the whole thing darker, somehow. Sure would be nice if I could just use the drawing commands for that.) This causes an Unhandled Memory Exception Error. What am I doing wrong? This is my first time using pixmaps and also my first time messing with binary stuff. Thanks in advance. | 
| 
 | ||
| Maybe change For Local x:Int = 1 To Self.BackgroundImage.width to For Local x:Int = 0 To Self.BackgroundImage.width-1 and same for y | 
| 
 | ||
| That did the trick! :D  Thanks, Ziltch! Incidently, I followed some other advice I noticed in another thread about WritePixel, changed my WritePixel line to WritePixel(map,x,y,$ff000000|65536*r+256*g+b) Apparently this will help me stay within the bounds if I start just passing RGB values willy-nilly. :P |