我想在我的活动中返回一个位图,以便其他应用程序可以使用它。
返回文本很清楚。
Intent data = new Intent();
data.putExtra("text1", "text.");
data.putExtra("text2", "longer text.");
setResult(RESULT_OK, data);
但是如何返回位图呢?
更多信息:该活动有几个意图,可供想要获取图像的每个人使用。
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.OPENABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="vnd.android.cursor.dir/image" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="vnd.android.cursor.dir/image" />
</intent-filter>
编辑:这是一个功能的解决方案:
public void finish(Bitmap bitmap) {
try {
File folder = new File(Environment.getExternalStorageDirectory() + "/Icon Select/");
if(!folder.exists()) {
folder.mkdirs();
}
File nomediaFile = new File(folder, ".nomedia");
if(!nomediaFile.exists()) {
nomediaFile.createNewFile();
}
FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/Icon Select/latest.png");
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
File bitmapFile = new File(Environment.getExternalStorageDirectory() + "/Icon Select/latest.png");
if(bitmapFile.exists()) {
Intent localIntent = new Intent().setData(Uri.fromFile(bitmapFile));
setResult(RESULT_OK, localIntent);
} else {
setResult(RESULT_CANCELED);
}
super.finish();
} catch (Exception e) {
e.printStackTrace();
Log.d("beewhale", "Error writing data");
}
}