B4J Question B4J BitmapFactory.decodeByteArray ?

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hi all ,

Do we have an equivalent to this android method ? in Java or B4J
B4X:
public static Bitmap decodeByteArray (byte[] data,
               int offset,
               int length)
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Yes. Use BitmapCreator.
Sorry I was not clear
B4X:
fpdev.GetBmpImage(bmpdata,bmpsize);
                                    Bitmap bm1=BitmapFactory.decodeByteArray(bmpdata, 0, 74806);
I want to use same in java (library ) or B4J
I hope this makes it a bit clearer
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
What is the format of the image stored in the data array?
I am not sure which format and so I am just trying to convert android sample to Java.

In android the library depends on a .jar and .so and it worked for me
But Windows version calls .dll methods(WINAPI) and the sample included was for C# and I couldn't find any support searching internet.
I used jna and managed to get part of library working
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
I am not sure I am allowed to share this or not but I can't find any information or support for this device
This code is decompiled from their dll

B4X:
 public int GetBmpImage(byte[] lpbmpdate, int[] lpsize)
  {
    lpsize[0] = 74806;
    memcpy(lpbmpdate, 0, this.bmpdata, 0, 74806);
    return 0;
  }
it might help you understand their way of retrieving Image
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is difficult to guess the format. Code to convert raw image data to bitmap:
B4X:
Sub ConvertToBitmap (data() As Byte, mWidth As Int, mHeight As Int) As B4XBitmap
   Dim WriteableImage As JavaObject
   WriteableImage.InitializeNewInstance("javafx.scene.image.WritableImage", Array(mWidth, mHeight))
   Dim writer As JavaObject = WriteableImage.RunMethod("getPixelWriter", Null)
   Dim PixelFormat As JavaObject
   PixelFormat.InitializeStatic("javafx.scene.image.PixelFormat")
   writer.RunMethod("setPixels", Array(0, 0, mWidth, mHeight, PixelFormat.RunMethod("getByteRgbInstance", Null), _
       data, 0, mWidth * 3))
   Return WriteableImage
End Sub
For this to work correctly you need to know the format.

https://docs.oracle.com/javase/8/javafx/api/javafx/scene/image/PixelFormat.html
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
It is difficult to guess the format. Code to convert raw image data to bitmap:
B4X:
Sub ConvertToBitmap (data() As Byte, mWidth As Int, mHeight As Int) As B4XBitmap
   Dim WriteableImage As JavaObject
   WriteableImage.InitializeNewInstance("javafx.scene.image.WritableImage", Array(mWidth, mHeight))
   Dim writer As JavaObject = WriteableImage.RunMethod("getPixelWriter", Null)
   Dim PixelFormat As JavaObject
   PixelFormat.InitializeStatic("javafx.scene.image.PixelFormat")
   writer.RunMethod("setPixels", Array(0, 0, mWidth, mHeight, PixelFormat.RunMethod("getByteRgbInstance", Null), _
       data, 0, mWidth * 3))
   Return WriteableImage
End Sub
For this to work correctly you need to know the format.

https://docs.oracle.com/javase/8/javafx/api/javafx/scene/image/PixelFormat.html
I think we are getting closer
The result does not seem to be the real fingerprint shown by the DrawImage method
fp.png
 
Upvote 0
Top