Androidは画像をバイトストリームに変換し、さらにString型データに変換します。

この機能はサブ関数を記述することで実現されます。具体的なコードは次のとおりです。

/**
     * 将图片转换成字节流,并进一步转换成String类型的数据
     */
    public static String putImageToShare(Context mContext, ImageView imageView) {
    
    
        BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
        Bitmap bitmap = drawable.getBitmap();
        ByteArrayOutputStream byStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 80, byStream);
        byte[] byteArray = byStream.toByteArray();
        String imgString = new String(Base64.encodeToString(byteArray, Base64.DEFAULT));
        return imgString;
    }

———————————————————————————————
最後に、私の個人的な公開アカウントを投稿します。WeChat で「Chaqian」を検索するか、下の写真をスキャンしてください。通常はプログラミング関連の記事が更新されるので、ぜひ注目してください〜
お茶の移動

おすすめ

転載: blog.csdn.net/weixin_46269688/article/details/111307848