readpixel problem

Monkey Forums/Monkey Programming/readpixel problem

pyongpyong(Posted 2013) [#1]
hello!









Black pixels Is there a way to suppress?

please advice~~


therevills(Posted 2013) [#2]
You need to do some bit shifting, search for pixel perfect collisions on here to find an example.


Markus(Posted 2013) [#3]
here:
Import mojo
    
Const WIDTH=100
Const HEIGHT=100

Class Game Extends App

    Field image:Image
    Field check:Bool
    Field scrshot:Image
    
    Method OnCreate()
        SetUpdateRate 60
        
    End

    Method OnUpdate()
        
    End

    Method OnRender()
        Cls(0,0,0)
        
        If check=False
          SetColor(0, 255, 0)
          DrawCircle(100, 100, 50)
          scrshot = CreateImage(WIDTH, HEIGHT,Image.MidHandle)
          Local pixels:Int[] = New Int[WIDTH * HEIGHT]
          ReadPixels(pixels, 50, 50, WIDTH, HEIGHT)

          For Local i:Int=0 To pixels.Length-1
          	pixels[i]=Alpha(pixels[i])
          Next
          
          scrshot.WritePixels(pixels, 0, 0, WIDTH, HEIGHT)
          
          check=True
        Else
          SetColor(255, 255, 255)
          DrawCircle(100, 100, 50)
          DrawImage(scrshot, MouseX(), MouseY())
        End
        
    End

End

Function Alpha:Int(argb:int)

		Local a : Int = ( argb Shr 24 ) & $ff
		Local r : Int = ( argb Shr 16 ) & $ff
		Local g : Int = ( argb Shr 8 ) & $ff
		Local b : Int = argb & $ff

		If r<8 And g<8 And b<8 'below is black = transparent
			a=$0
		Endif
		
		Return (a Shl 24)+(r Shl 16)+(g Shl 8)+b
End

Function Main()
    New Game()
End




pyongpyong(Posted 2013) [#4]
therevills----
Thank you!

Markus-------
super ultra Thank you!
I got it!