Dim bmc As BitmapCreator
Dim i As Int
Dim linePixels(128) As Int
Dim bc As ByteConverter
bmc.Initialize(128,1)
For i = 0 To 127
linePixels(i) = Colors.Red
Next
bc.LittleEndian = True
Bit.ArrayCopy(bc.IntsToBytes(linePixels),0,bmc.buffer,0,4*128)
XUIViewsUtils.SetBitmapAndFill(imgTest,bmc.Bitmap)
For i = 0 To 127
k = i*255/127
linePixels(i) = k
Next
Dim newcolor as int
newcolor = oldcolor*256+255 ' Bit.Shift can be used too
bc.LittleEndian = False
bc.LittleEndian = True
In B4J is straight forward, but in B4A I have to do this manual conversion.
What other (built-in, more efficient) option I have to pass a line of pixels (as an Int array) to BitmapCreator?
For i = 0 To 127
bmc.setcolor(i,0,colors.red)
Next
XUIViewsUtils.SetBitmapAndFill(imgTest,bmc.Bitmap)
It was just as a simple example how color as an int is handled by BitmapCreator in B4A (different than in B4J).into your one-pixel-wide bmc.Initialize(128,1) end up near to what you're aiming for?
pixel color:Dim linePixels(128) As Int ... Bit.ArrayCopy(bc.IntsToBytes(linePixels),0,bmc.buffer,0,128)
Bit.ArrayCopy(bc.IntsToBytes(linePixels), 0, bmc.buffer, 0, 128 * 4)
and things are making way more sense here now. ?
For i = 0 To 127
'B4J under Windows: byte order is (B, G, R, A)
linePixels(i) = bc.IntsFromBytes(Array As Byte(0, 0, i, 255))(0)
Next
Is a typo in my example, as is manually reduced from what I have in my app.I don't have a working B4A setup here, but I've been mucking about in B4J with your sample code, and eventually I noticed that you have an array of 128 ints which is converted into an array of 512 bytes, but ArrayCopy is only copying the first 128 bytes. I added a multiply-by-four to the line:
...
Yes, but in B4A, byte order looks like R,G,B,A to be correctly added in BitmapCreator.'B4J under Windows: byte order is (B, G, R, A)
The pixel underlying format is different on different OS, in b4a a pixel byte order is RGBA, but b4j is BGRA ..., so you need convert color int to bytes according to different OS, as Erel said you'd better use built-in method to manipulate them as possible.Is a typo in my example, as is manually reduced from what I have in my app.
Of course is 4x128. This not the issue. The issue is with the color int format required by BitmapCreator in B4A.
As written in my message, behavior in B4J is the expected one, so no issue at all in B4J. Only in B4A the format is different.
For i = 0 To 127
#if b4a
'B4A under android: byte order is (R, G, B, A)
LinePixels(i) = bc.IntsFromBytes(Array As Byte(i, 0, 0, 255))(0)
#else
'B4J under windows: byte order is (B, G, R, A)
LinePixels(i) = bc.IntsFromBytes(Array As Byte(0, 0, i, 255))(0)
#end if
Next
SetColor per pixel is to slow
May be even faster.
On the other side, I didn't tried to see if SetPixel accept the right color format (as in B4J), not as when writing directly in BitmapCreator. If yes ... I can use SetPixel directly in BitCreator. May be even faster.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Dim bmc As BitmapCreator
Dim i As Int
Dim LinePixels(128) As Int
Dim bc As ByteConverter
bmc.Initialize(128, 1)
Dim TempARGB As ARGBColor
TempARGB.Initialize 'sets all to 0, including alpha (wth?)
TempARGB.a = 255
Log("Starting timing test")
Dim StartTime As Long = DateTime.Now
For ProfilingDoLots = 1 To 100000
For i = 0 To 127
TempARGB.r = i * 2
bmc.SetARGB(i, 0, TempARGB)
Next
Next
Dim EndTime As Long = DateTime.Now
Log("Finished timing test")
Log(((EndTime - StartTime) / 1000))
'''no longer needed - is already in bmc
'''Bit.ArrayCopy(bc.IntsToBytes(LinePixels), 0, bmc.buffer, 0, LinePixels.Length * 4)
XUIViewsUtils.SetBitmapAndFill(ImageView1, bmc.Bitmap)
End Sub
in my app I build the linePixels using a palette array (byte to color)
Not as I'm aware. I build the pallete as a Ints Array with 256 values. In fact initially the palette is a bitmap from where I extract the colors using GetPixel. The colors returned by GetPixel are the expected ones. I suppose SetPixel in BitmapCreator do the same, but as my problem is currently solved in an acceptable way, I will not further dig on this.BitmapCreator does paletted stuff too? I'm wondering if it converts from your palette table index bytes to internal ARGB format.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?