我正在将图库中的图像作为位图加载到画布上并在其上执行一些绘图。
在任何时候,我都有这个包含我的绘图的位图,随时可用。
我需要裁剪此位图。为此,我需要首先将位图转换为图像文件 - 因为没有可用于直接裁剪位图的API或库。 2-3秒,我在这个转换过程中松了一口气。
是否有出路(或使用任何第三方库),我可以直接裁剪位图,而无需将其转换为图像文件。这将有助于我提高应用程序的性能。
非常感谢任何帮助。
PS:作为参考,我在下面添加了位图转换代码。我目前用于裁剪的库是 - https://github.com/jdamcd/android-crop
drawView.setDrawingCacheEnabled(true);
Date d = new Date();
CharSequence s = DateFormat.format("MM-dd-yy hh-mm-ss", d.getTime());
Bitmap bitmap = drawView.getResultBitmap();
File sdCardDirectory = Environment.getExternalStorageDirectory();
File image = new File(sdCardDirectory, "DCIM/Camera/" + s.toString() + ".png");
boolean success = false;
// Encode the file as a PNG image.
FileOutputStream outStream;
try {
outStream = new FileOutputStream(image);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
/* 100 to keep full quality of the image */
outStream.flush();
outStream.close();
success = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//static final Uri imgUri;
if (success) {
MediaScannerConnection.scanFile(getActivity(), new String[]{
image.getAbsolutePath()},
null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
beginCrop(uri);
}
});