Android Question BitmapExtender SetPixels problem

antreg

Member
Licensed User
Longtime User
Hi,
I've a question that is probabily driving me crazy.
I have to create an image, using bitmapextender.SetPixels starting from an array of int.
This array is created converting an array of bytes, thanx to a java routine I've wrote, where each value of byte is assigned to a int, one to one.
For example, if I have an array of bytes received from a camera that send me:
52,97,95,40,41,98,117,90,36,34,51,81,129,137,135,135,137,139,143,144
I obtain an array of int with the same numbers, of course where value >127 the conversion in int is a negative number according to http://en.wikipedia.org/wiki/Two's_complement

After using:

B4X:
be.setPixels(CurrentBitmap, bufInt, 0, 640, 0,0,640,480)

where Currentbitmap is a Bitmap already initialized as mutable, I obtain a visible image...that is supposed to be a grayscale image, but with a yellow tint and probabily with other problem of saturation.
My question is: with then same values, ina vb.net program on windows I see a perfect and grayscaled, luminosity balanced image, what I'm doing wrong in android world?

Let me know if you need further information.
 
Last edited:

antreg

Member
Licensed User
Longtime User
HI! I solved. All behaviour depends from bitmap config and how you convert the integer.
For the bitmap config I solved using RGB_565. I create an image directly from a java lib I wrote for converting list of byte in array of int.
For the byte->integer conversion:
B4X:
int gByte = (int) myBytes[i] & 0xFF;
int rgb = (gByte << 16) | (gByte << 8) | gByte;
Where myBytes contains the bytes downloaded from a camera in async way.
Now bufInt contains the array of int of right value and with RGB_565 the image is displayed perfectly.
 
Upvote 0

Baltazar

Member
Licensed User
Longtime User
I am also doing some stuff with this library and I am getting exception at the setPixel line.
In short what should be the value of the replacemen color for setPixel. The documentation says, it should be int so I suppose it is a 32-bit value
unless we strip off the alpha component? Anyone please enlighten me. Below is my test code:
B4X:
Sub Process_Globals
     Dim bmpex As BitmapExtended
     Dim bmp As Bitmap
     End Sub

Sub Globals
    Private imgBMP As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim xx,yy,pix As Int
    If FirstTime Then
       bmpex.Initialize("")
    End If
     bmp.Initialize(File.DirAssets, "0.png")
     Activity.LoadLayout("bmpLayout")
'For yy = 0 To bmp.Height-1
   For xx = 0 To bmp.Width -1
       pix = bmp.GetPixel(xx,0)                            ' just one raster ; will do something later on this values
       Try
       bmpex.setPixel(bmp,xx,0,Colors.Yellow)      ' change one line of pixels to yellow
       Catch
       Log("Boom! Epic Fail")     'java.lang.Exception:  java.lang.IllegalStateException
 
       Exit
       End Try
  
    Next
'Next

   imgBMP.Bitmap = bmp     ' this is the unaltered bitmap

End Sub
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
just wondering... what's the benefit of using that other library just to draw some pixels or a line?

it's all part of the core libraries aswell.
 
Upvote 0

Baltazar

Member
Licensed User
Longtime User
just wondering... what's the benefit of using that other library just to draw some pixels or a line?

it's all part of the core libraries aswell.
I bet not when it comes to the setPixel. On the standard bitmap library , you can only read the pixel using getPixel but not to set it. That's why one of our good colleagues here extended the library.:)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
that's because you need to use canvas set pixel (it's called setpoint) :)

I don't know why Erel put it there tho and not where the getpixel is.
 
Upvote 0

Baltazar

Member
Licensed User
Longtime User
that's because you need to use canvas set pixel (it's called setpoint) :)

I don't know why Erel put it there tho and not where the getpixel is.
Splendid! It means I have to draw the target bitmap to the canvas first then do the business there (?). But of course, I am also looking for answer why I am getting an exception. :) . Thanks for the tip. Canvas always reminds me of TCanvas in Delphi/Free Pascal .;)
 
Upvote 0
Top