📜  encodeFromImage - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:18.243000             🧑  作者: Mango

代码示例1
private String encodeFromImage() {
        String encode = null;
        if (imageView.getVisibility() == View.VISIBLE) {
            Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
            //encode = Base64.encodeToString(stream.toByteArray(), Base64.DEFAULT);
            //String path = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap,"Title",null);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                encode = Base64.getEncoder().encodeToString(stream.toByteArray());
            } else {
                encode = android.util.Base64.encodeToString(stream.toByteArray(), android.util.Base64.DEFAULT);
            }
        }
        return encode;
    }