gpt4 book ai didi

android - 无法将图片保存在给定位置

转载 作者:行者123 更新时间:2023-11-29 22:03:36 25 4
gpt4 key购买 nike

我是 android 编程的初学者。这是拍摄图像并将其保存在 sdcard 文件夹中的代码。图像保存在图库中,但未保存在我想要的位置。请帮助...


public class CameraActivity extends Activity {
/** Called when the activity is first created. */

Button button1;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button1=(Button)findViewById(R.id.button1);

}

public void send(View v)
{
Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

File imagesFolder = new File(
Environment.getExternalStorageDirectory(),
"MyImages");

imagesFolder.mkdirs(); //

File image = new File(imagesFolder, "image_001.jpg");

Uri uriSavedImage = Uri.fromFile(image);

imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);

startActivityForResult(imageIntent,0);

}

}

最佳答案

终于得到解决方案,修改后的代码为:

File image = new File("/sdcard/picture.jpg");
Uri uriSavedImage = Uri.fromFile(image);

intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);

// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

关于android - 无法将图片保存在给定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11348762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com