我希望将照片转换为base64,照片来自我的外部SD卡。我试过这段代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_picture);
File yourFile = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "MyCameraApp/Hello.jpg");
Bitmap bm = BitmapFactory.decodeFile(String.valueOf(yourFile));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] byteArrayImage = baos.toByteArray();
String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
TextView textView = (TextView) findViewById(R.id.simpleTextView);
textView.setText(encodedImage); //set text for text view
}
但是在logcat中显示 bm.compress(Bitmap.CompressFormat.JPEG,40,baos); 有错误,有人可以分享我的想法吗?
logcat错误: