Android Question OutOfMemory Camera

headingwest

Member
Licensed User
Longtime User
Hi All, I'm trying to measure the "R" "G" and "B" in a camera photo. Basic idea is to scroll through each pixel and add up each color.

This is crashing with OutOfMemory half way through 640x480 camera image. Any ideas?

B4X:
Sub Camera1_PictureTaken (Data() As Byte)
       
    Dim In As InputStream
    In.InitializeFromBytesArray(Data, 0, Data.Length)
   
    Dim bmp As Bitmap
   
    bmp.Initialize2(In)
    In.Close
   
    Dim x As Int, y As Int, z As Int
    Dim numPix As Long
    Dim PixelColor As Int
    numPix = bmp.Height * bmp.Width
    Dim res(4) As Int
    Dim ARGB(4) As Long
   
    For x = 0 To bmp.Width - 1
        For y = 0 To bmp.Height - 1
            PixelColor = bmp.GetPixel(x,y)
           
            res(0) = Bit.UnsignedShiftRight(Bit.And(PixelColor, 0xff000000), 24)
            res(1) = Bit.UnsignedShiftRight(Bit.And(PixelColor, 0xff0000), 16)
            res(2) = Bit.UnsignedShiftRight(Bit.And(PixelColor, 0xff00), 8)
            res(3) = Bit.And(PixelColor, 0xff)
    '        Log("ARGB = " & res(0) & "," & res(1) & "," & res(2) & "," & res(3))       
           
            For z = 0 To 3
                ARGB(z) = ARGB(z) + res(z)       
            Next
           
        Next
        Log("Line " & x & " / " & bmp.Height)
    Next
   
    For z = 0 To 3
        ARGB(z) = ARGB(z) / numPix       
    Next
End Sub
 

headingwest

Member
Licensed User
Longtime User
Hi Erel,

Log(bmp.Width & " x " & bmp.Height) = 640 x 480

I'm using a different PC today and the error is on this line:
B4X:
res(0) = Bit.UnsignedShiftRight(Bit.And(PixelColor, 0xff000000), 24)

It's processed 126 / 480 lines of the bitmap when it crashes. The error seems to have changed but always occurs at this point. Here's 2 different errors thrown up:


 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…