问题描述
````````for converting to bitmap
button.setonClickListener(v -> {
BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView3.getDrawable();
Bitmap bitmap = bitmapDrawable.getBitmap();
saveImage(bitmap);
private void saveImage(Bitmap bitmap) {
OutputStream fos;
long currentTime = Calendar.getInstance().getTimeInMillis();
String timestamp = DateFormat.getDateTimeInstance().format(currentTime);
try {
if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.Q){
ContentResolver resolver = getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.disPLAY_NAME,"Image"+timestamp+".jpg");
contentValues.put(MediaStore.MediaColumns.MIME_TYPE,"image/jpg");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH,Environment.DIRECTORY_PICTURES + File.separator + "test");
imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues);
fos = (FileOutputStream) resolver.openOutputStream(Objects.requireNonNull(imageUri));
bitmap.compress(Bitmap.CompressFormat.WEBP_LOSSLESS,100,fos);
Objects.requireNonNull(fos);
Toast.makeText(this,"Image saved",Toast.LENGTH_SHORT).show();
}
}
if (resultCode == RESULT_OK && requestCode == PICK_IMAGE && data != null){
imageUri = data.getData();
imageView3.setimageURI(imageUri);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)