简体   繁体   English

如何在不使用数据库的情况下在Android中查看拍摄的图片?

[英]How to view the taken pictures in Android Without using Database?

Hai am new in Android Application.i Generated a code to take picture by using Camera.Now i want to view the Taken Pictures without using Database.i dont know how to do this.AnyBody please help me. Hai是Android Application.i中的新手。使用Camera.Now生成一个代码来拍照。我想在不使用Database.i的情况下查看拍摄图片。我不知道怎么做.AnyBody请帮帮我。 Thanks in advance Here my Code 在此先感谢我的代码

private void createCamera() {
   // TODO Auto-generated method stub
   preview = new Preview(this);
   ((FrameLayout) findViewById(R.id.preview)).addView(preview);

   buttonClick = (Button) findViewById(R.id.buttonClick);
   buttonClick.setOnClickListener( new OnClickListener() {
      public void onClick(View v) {
         preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
      }
   });

  Log.d(TAG, "onCreate'd");
}

ShutterCallback shutterCallback = new ShutterCallback() {
   public void onShutter() {
      Log.d(TAG, "onShutter'd");
   }
};

/** Handles data for raw picture */
PictureCallback rawCallback = new PictureCallback() {
   public void onPictureTaken(byte[] data, Camera camera) {
      Log.d(TAG, "onPictureTaken - raw");
   }
};

/** Handles data for jpeg picture */
PictureCallback jpegCallback = new PictureCallback() {
   public void onPictureTaken(byte[] data, Camera camera) {
      FileOutputStream outStream = null;

      try {
         outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis())); 
         outStream.write(data);
         outStream.close();
         Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      } finally {}

      Log.d(TAG, "onPictureTaken - jpeg");
   }
};

private void createpictures() {
   img = (ImageView)findViewById(R.id.ImageView01);

   ((Button) findViewById(R.id.Button01)).setOnClickListener(new OnClickListener() {
      public void onClick(View arg0) {
         Intent intent = new Intent();
         intent.setType("image/*");
         intent.setAction(Intent.ACTION_GET_CONTENT);
         startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
      }
   });
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (resultCode == RESULT_OK) {
      if (requestCode == SELECT_PICTURE) {
         Uri selectedImageUri = data.getData();
         selectedImagePath = getPath(selectedImageUri);
         System.out.println("Image Path : " + selectedImagePath);
         img.setImageURI(selectedImageUri);
      }
   }
}

public String getPath(Uri uri) {
   String[] projection = { MediaStore.Images.Media.DATA };
   Cursor cursor = managedQuery(uri, projection, null, null, null);
   int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
   cursor.moveToFirst();
   return cursor.getString(column_index);
}

Simple as this: 很简单:

Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse("file://"+yourFileName));
startActivity(in);

Default app for viewing pictures will start, or if there's no default, user get selection dialog which app to use. 将开始查看图片的默认应用程序,或者如果没有默认值,则用户获取选择对话框以使用哪个应用程序。

you really dont need to use database to view taken picture. 你真的不需要使用数据库来查看拍摄的照片。

  1. To get new image - open an intent for Camera. 获取新图像 - 打开相机的意图。 like this 这样
  2. To see all other captured images, open Gallery. 要查看所有其他捕获的图像,请打开图库。 see this discussion 看到这个讨论

heres a good overview of opening data via intents on your phone. 这是一个很好的概述,通过手机上的意图打开数据。 All this documentation is in here as well http://developer.android.com/guide/topics/intents/intents-filters.html but not as clear to follow. 所有这些文档都在这里http://developer.android.com/guide/topics/intents/intents-filters.html,但不是很清楚。

http://indyvision.net/2010/03/android-using-intents-open-files/ http://indyvision.net/2010/03/android-using-intents-open-files/

 File imageFile2View = new File("/sdcard/nice_photo.jpeg");
 Intent i = new Intent();
 i.setAction(android.content.Intent.ACTION_VIEW);
 i.setDataAndType(Uri.fromFile(imageFile2View), "image/jpeg");
 startActivity(i);

Now if what your looking for is to display the picture you took in your own activity you can use. 现在,如果你想要的是显示你在自己的活动中拍摄的照片,你可以使用。

String file = String.format("/sdcard/%d.jpg", System.currentTimeMillis());
//SAVE IMAGE TO file
img.setImageURI(URI.parse(file));

or 要么

String file = String.format("/sdcard/%d.jpg", System.currentTimeMillis());
//SAVE IMAGE TO file
bitmap = BitmapFactory.decodeFile(file);
img.setImageBitmap(bitmap);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Android应用程序中保存相机拍摄的照片 - saving pictures taken by camera in android app 如何使用JFilechooser和Jlabel查看图片 - How to view pictures using JFilechooser and Jlabel 使用Overlay连接从Android中的数据库获取的GPS坐标 - Connecting GPS coordinates taken from a database in Android using Overlay 在图像视图中显示从相机拍摄的图像并将其添加到数据库-Android Studio - Display taken image from camera in image view and add it to database - Android Studio 使用JPA时如何映射没有主键的数据库视图 - How to map a database view without a primary key when using JPA Android Studios 上传图片到实习生数据库 - Android Studios Uploading pictures into intern database 如果我不缩放视图,如何在不占用视图空间的情况下缩放视图? - How to scale a View without it taking up the space it would have taken if I didn't scale it? Android:如何在活动中加载多张图片和声音而不会出现内存不足错误 - Android: How to load multiple pictures and sounds in an activity without a out of memory error 如何掩盖响应来自android中的服务器而不显示黑屏的时间? - How to cover up the time taken by response to come from the server in android without showing black screen? 带有图片和子项目的Android自定义列表视图搜索视图不起作用 - Android Custom List View with pictures and sub items search view not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM