3

我正在开发一个 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);
        }
    }
}
4

1 回答 1

3

您可以将位图保存到应用程序的缓存文件夹中,如下所示:

String destFolder = getCacheDir().getAbsolutePath();

FileOutputStream out = new FileOutputStream(destFolder + "/myBitamp.png");
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
于 2013-10-04T21:12:59.670 回答