我正在开发一个Android应用程序,它捕获图像然后使用opencv函数处理它,然后返回结果图像并在图像视图中显示它。如何暂时保存捕获的图像以进行处理?
public class Camera extends Activity
{
ImageView imgview;
Bitmap Bmp;
final static int cameraData=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);
imgview= (ImageView) findViewById(R.id.imgview);
Intent i=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,cameraData);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK)
{
Bundle extras=data.getExtras();
Bmp=(Bitmap)extras.get("data");
imgview.setImageBitmap(Bmp);
}
}
}
答案 0 :(得分:2)
您可以将位图保存到应用程序的缓存文件夹中,如下所示:
String destFolder = getCacheDir().getAbsolutePath();
FileOutputStream out = new FileOutputStream(destFolder + "/myBitamp.png");
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);