Convert bitmap to base64 string in blackberry

后端 未结 3 1192
没有蜡笔的小新
没有蜡笔的小新 2021-01-29 08:25

I have an image which needs to be sent to the server. Is there a way to convert a bitmap(jpg) to base64 string in blackberry?

3条回答
  •  广开言路
    2021-01-29 09:09

    What you request is a bit vague and odd, however I hope this can help:

    With the following piece code it's possible to get a JPEG binary data for a Bitmap (note, it is a compressed one, so the size of the data is as small as possible if compare to raw bitmap):

    Bitmap bmp = ...; // your bitmap
    int quality = 85;
    EncodedImage encodedImg = JPEGEncodedImage.encode(bmp, quality);
    byte[] data = encodedImg.getData();
    

    Then you can encode it with Base64OutputStream. See the API for sample code on how to encode.

提交回复
热议问题