Bitmap from String

前端 未结 3 507
情歌与酒
情歌与酒 2021-01-20 21:13

Is there a way or How do I take a String and create a bitmap from it using Java for development for Android?

I had a look at the java api for bitmaps and couldnt fin

相关标签:
3条回答
  • 2021-01-20 22:02

    Assuming that your image data is in a String called myImageData, the following should do the trick:

    byte[] imageAsBytes = Base64.decode(myImageData.getBytes());
    ImageView image = (ImageView)this.findViewById(R.id.ImageView);
    image.setImageBitmap(
            BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)
    );
    

    For Base64 decoding, you can use http://iharder.sourceforge.net/current/java/base64/ as Android doesn't contain Base64-support prior to 2.2.

    Note, I didn't actually run this code, so you'll have to doublecheck for errors.

    more link: using canvas http://developer.android.com/reference/android/graphics/Canvas.html

    0 讨论(0)
  • 2021-01-20 22:03

    DrawText on canvas by creating bitmap.

    0 讨论(0)
  • 2021-01-20 22:09

    You can use the decodebytearray method of bitmap factory like

    byte[] imageAsBytes = Base64.decode(myImageData.getBytes());
    Bitmap bp = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);
    

    Where myImageData is a base64 string.

    If you have an array just pass that to the decodeByteArray method.

    0 讨论(0)
提交回复
热议问题