从绘制的图像保存在相机的活动到SD卡 [英] Save Image from drawable to sdcard in camera activity

查看:132
本文介绍了从绘制的图像保存在相机的活动到SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个项目,通过ImageView的读取文件夹绘制图像文件,它通过

I'm working on a project, that read image file from drawable folder through ImageView, it loaded successfully through

ImageView view = (ImageView) findViewById(R.id.imageView);
view.setOnTouchListener(this);
buttonTakePicture = (Button) findViewById(R.id.takepicture);
buttonTakePicture.setOnClickListener(new Button.OnClickListener() {
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        camera.takePicture(myShutterCallback, myPictureCallback_RAW,
            myPictureCallback_JPG);

现在pressing takePicture按钮后,图像应在SD卡存储,它正在快照而不是与保存图像时,code是低于

now after pressing takePicture button , image should save in sdcard, it is taking snapshot but not saving the image with that, the code is below

File file = new File(mScreenshotPath + "/" + System.currentTimeMillis() + ".jpg");
FileOutputStream fos;
try {
    imageFileOS = getContentResolver().openOutputStream(uriTarget);
    imageFileOS.write(arg0);
    imageFileOS.flush();
    imageFileOS.close();
    fos = new FileOutputStream(file);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
    fos.close();
    Toast.makeText(AndroidCamera.this,
            "Image saved: " + uriTarget.toString(),
            Toast.LENGTH_LONG).show();

请帮我这个问题....在此先感谢

Please help me for this issue....Thanks in advance

推荐答案

您可以保存在Android中的照片,无需随之而来的OutputStream和所有其他逻辑。下面是一个简单的食谱,这将做什么,我认为你所要完成。要特别注意的意图和如何使用它来设置图像的保存,因为这是我想你要去哪里错了。

You can save photos in Android without the need for an OutputStream and all the other logic that accompanies it. Here is a simple recipe which will do what I think you are trying to accomplish. Pay special attention to the Intent and how it is used to set up the saving of the image, as this is I think where you are going wrong.

public class PhotoActivity extends Activity implements OnClickListener {

private Button takePicture;
private String path;
private File imageFile;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.your_layout);
    takePicture = (Button) findViewById(R.id.button1);
    takePicture.setOnClickListener(this);

    path = Environment.getExternalStorageDirectory() + "/my_image.png";
    imageFile = new File(path);
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.button1:
        Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
        Uri uri = Uri.fromFile(imageFile);
        i.putExtra(MediaStore.EXTRA_OUTPUT, uri);

        startActivity(i);
        break;
    }
}
}

这篇关于从绘制的图像保存在相机的活动到SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆