Skip to main content

Kanzi Android framework; How to set Bitmap to image 2D node?

Answered

Comments

1 comment

  • Jason Stanczyk

    You can set the Texture of the Image2D using the Image2D setImage(Texture) API.

    To create a Texture, you can use the TextureBuilder API. 
    For example:

          mBitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), Uri.parse(mUrl));
    ...
    mBitmap = BitmapUtils.flip(mBitmap);

    int[] data = BitmapUtils.bitmapToPixelArray(mBitmap);
    data = BitmapUtils.swizzleARGBToRGBA(data);

    ByteBuffer byteBuffer = ByteBuffer.allocate(data.length * 4);
    IntBuffer intBuffer = byteBuffer.asIntBuffer();
    intBuffer.put(data);

    GraphicsFormat format = GraphicsFormat.GraphicsFormatR8G8B8A8_UNORM;
    BitmapImage images[] = {
    new BitmapImage(mBitmap.getWidth(), mBitmap.getHeight(),
    format, byteBuffer.array(), "AlbumArt")
    };

    TextureBuilder builder = new TextureBuilder()
    .setName("AlbumArtTexture")
    .setWidth(mBitmap.getWidth())
    .setHeight(mBitmap.getHeight())
    .setImages(images)
    .setFormat(format);

    mTexture = builder.build(mDomain);

    If you need to use URI such as "content://" with Kanzi, you need to introduce a custom protocol handler. 

    The BitmapUtils class can be found here:


    KanziWorkspace_3_9_7_242\Examples\Android\Resource_import\Application\configs\platforms\android_gradle\resourceplugin\src\main\java\com\example\resourceplugin\android

    As well as the 
    Android\Resource_import project 

     

     

     

     

    1

Please sign in to leave a comment.