使用“工程图视图”制作工程图,然后将其转换为图像,然后将其保存在数据库中,当活动结束时,应该与之共享选项,并且一旦保存图像就不再显示与之共享的选项。其他应用程序,但重定向到另一个视图。
dv_example = (DrawingView) findViewById(R.id.drawing_view);
saveEditedImage(dv_example.getBitmap());
UseMethod saveEditedImage
private void saveEditedImage(Bitmap bitmap) {
File file = null;
try {
file = createImageFile();
} catch (IOException e) {
Log.e("CreateImageFile", "Error after attempting to create the container file for the image.");
e.printStackTrace();
}
try {
FileOutputStream outputStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
Log.e("Crop", "Failed to save");
return;
}
Uri uri = FileProvider.getUriForFile(context, context.
getPackageName() + ".provider", file);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(intent);
}
方法createImageFile();
private File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(imageFileName, ".jpg", storageDir );
mCurrentPhotoPath = image.getAbsolutePath();
Log.i("PATH", mCurrentPhotoPath);
return image;
}
清单
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>