Android 将相机的照片保存到内存中

发布于 2024-11-27 23:47:20 字数 893 浏览 0 评论 0原文

我是这个网站和安卓的新手。如何将相机的图片保存到特定文件夹中并将图片的名称也保存到sqlite数据库中。

 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
 //  setContentView(R.layout.camera);
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);  
    File photo = new File(Environment.getExternalStorageDirectory(),  "Pic.jpg");
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(photo));
    imageUri = Uri.fromFile(photo);

    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);  
    onActivityResult(1337, 0, cameraIntent);

}



protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == CAMERA_PIC_REQUEST) {

    }

我打开了相机活动。如何获取图片名称和图片名称将其保存到特定位置?

请帮我解决这个问题。

先感谢您。

I am new to this site and android. how to save the camera's picture into specific folder and save the picture's name into sqlite databse also.

 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
 //  setContentView(R.layout.camera);
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);  
    File photo = new File(Environment.getExternalStorageDirectory(),  "Pic.jpg");
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(photo));
    imageUri = Uri.fromFile(photo);

    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);  
    onActivityResult(1337, 0, cameraIntent);

}



protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == CAMERA_PIC_REQUEST) {

    }

I opened camera activity. How to get the picture name & save it to particular location?

please help me on this.

thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

好菇凉咱不稀罕他 2024-12-04 23:47:20

我正在调用相机

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

并像这样保存到 SD 卡

final ImageView img = new ImageView(this);
img.setLayoutParams(new LayoutParams(100, 100));
image2 = (Bitmap) data.getExtras().get("data");
img.setImageBitmap(image2);
String incident_ID = IncidentFormActivity.incident_id;
//l2.addView(img);
    imagepath="/sdcard/RDMS/"+incident_ID+ x + ".png";
File file = new File(imagepath);
try {
bm = Bitmap.createScaledBitmap( image2,400, 300, true);
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bm.compress(CompressFormat.PNG, 90, ostream);
ostream.close(); 
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),"yourfirst  error message is "
+ e.toString(), 1000).show();
        }

I'm calling camera

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

and saving to sd card like this

final ImageView img = new ImageView(this);
img.setLayoutParams(new LayoutParams(100, 100));
image2 = (Bitmap) data.getExtras().get("data");
img.setImageBitmap(image2);
String incident_ID = IncidentFormActivity.incident_id;
//l2.addView(img);
    imagepath="/sdcard/RDMS/"+incident_ID+ x + ".png";
File file = new File(imagepath);
try {
bm = Bitmap.createScaledBitmap( image2,400, 300, true);
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bm.compress(CompressFormat.PNG, 90, ostream);
ostream.close(); 
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),"yourfirst  error message is "
+ e.toString(), 1000).show();
        }
月下伊人醉 2024-12-04 23:47:20

您可能需要将该行更改

 if (resultCode == CAMERA_PIC_REQUEST) {

 if (requestCode == CAMERA_PIC_REQUEST) {

You may need to change the line

 if (resultCode == CAMERA_PIC_REQUEST) {

to

 if (requestCode == CAMERA_PIC_REQUEST) {
海之角 2024-12-04 23:47:20

您已经在保存图片了。您在 MediaStore.EXTRA_OUTPUT 中提供了位置。

链接

做数据库你必须看看这个<一href="http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBcQFjAA&url=http://developer.android.com/refere nce/android/database/sqlite/package-summary.html&ei=Y5E6TuHGMNK4hAecrO2jBQ&usg=AFQjCNF8aHy__4EKyivNW9vK1dQKVVb5ag" rel="nofollow">link 解释起来有点太多

You are already saving the picture. You provided the location in MediaStore.EXTRA_OUTPUT.

Link

Doing a DB you will have to have a look at this link is a little bit to much to explain

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文