【问题标题】:Get camera image Inside Iistview在 Iistview 中获取相机图像
【发布时间】:2012-12-27 06:03:37
【问题描述】:

我有自定义Listview。里面有一个ButtonImageView

在按钮点击相机将打开。(相机意图触发)。

我希望将捕获的图像(也称为位图)放到 ImageView 上,这也是一个 ListItem。

这意味着当我捕获图像并按下相机的完成按钮时,我的 imageview 必须设置该图像。

我该怎么做?

【问题讨论】:

    标签: android android-intent camera


    【解决方案1】:

    按照以下步骤,

    1. 从您的活动中为相机意图的结果启动活动。
    2. 捕获图片控件后回调到onActivityResult的你的activity。
    3. 处理图片路径。
    4. 通过在列表视图项位置设置属性来设置图像的路径。

    【讨论】:

      【解决方案2】:
       private static int FILE_SELECT_CODE_1 = 0;
          function intentCamera(){
               Intent i = new Intent(
                              android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
               startActivityForResult(i, FILE_SELECT_CODE_1);
      
      
        }
      
      private String getLastImagePath() {
              final String[] imageColumns = { MediaStore.Images.Media._ID,
                      MediaStore.Images.Media.DATA };
              final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
              Cursor imageCursor = managedQuery(
                      MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns,
                      null, null, imageOrderBy);
              if (imageCursor.moveToFirst()) {
                  //int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID));
                  String fullPath = imageCursor.getString(imageCursor
                          .getColumnIndex(MediaStore.Images.Media.DATA));
                  // Log.d(TAG, "getLastImageId::id " + id);
                  // Log.d(TAG, "getLastImageId::path " + fullPath);
                  imageCursor.close();
                  return fullPath;
              } else {
                  return "";
              }
          }
      
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (requestCode == FILE_SELECT_CODE_1 && resultCode == RESULT_OK){
               String lastImagePath = getLastImagePath();
               File fileImage = new File(lastImagePath);
               Uri u = Uri.fromFile(fileImage);
               //now you can set the image example:
               ImageView img = new ImageView(this);
               img.setImageURI(u);
      
      
      
      
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多