0

base64文字列データをバイト配列に変換するために以下のコードを開発しましたが、表示されていますIOException

public static EncodedImage getProfileByteArray(String profilePic){
    byte[] data=profilePic.getBytes();
    byte[] base64Data;
    Bitmap bitmap=null;
    EncodedImage fullImage=null;
    try {
        base64Data = Base64InputStream.decode(data, 0, data.length);
        fullImage = EncodedImage.createEncodedImage(base64Data, 0, base64Data.length);
        bitmap = fullImage.getBitmap();
        System.out.println(data);
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println(e+"lkllllllllllllllll");
    }
    catch(Exception e){
        System.out.println(e+"lkllllllllllllllll");
    }
    return fullImage;
}

The way is that i am calling a webservice through which i am getting base64 image string and trying to convert this base64 string to byte array to display image in EncodedImage format.

4

1 に答える 1

0

Web サービスから取得した URL から画像を表示しようとしていますか? URLはWebサービスから返された画像ですか? その場合は、以下のコードを試してお知らせください。

public Bitmap connectServerForImage(String url) {

          HttpConnection httpConnection = null;
          DataOutputStream httpDataOutput = null;
          InputStream httpInput = null;
          int rc;

          Bitmap bitmp = null;
          try {
           httpConnection = (HttpConnection) Connector.open(url+ ";deviceside=true;ConnectionUID=S TCP");
            rc = httpConnection.getResponseCode();
           if (rc != HttpConnection.HTTP_OK) {
            throw new IOException("HTTP response code: " + rc);
           }
           httpInput = httpConnection.openInputStream();
           InputStream inp = httpInput;
           byte[] b = IOUtilities.streamToBytes(inp);
           EncodedImage hai = EncodedImage.createEncodedImage(b, 0, b.length);
           return hai.getBitmap();

          } catch (Exception ex) {
           System.out.println("URL Bitmap Error........" + ex.getMessage());
          } finally {
           try {
            if (httpInput != null)
             httpInput.close();
            if (httpDataOutput != null)
             httpDataOutput.close();
            if (httpConnection != null)
             httpConnection.close();
           } catch (Exception e) {
            e.printStackTrace();

           }
          }
          return bitmp;
         }
于 2012-10-11T08:39:00.747 に答える