コード例 #1
0
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
      case 1001: // 历史地址
        if (data != null) {
          picUrl = data.getStringExtra("persion_imag");
          if (!TextUtils.isEmpty(picUrl)) {
            try {
              Bitmap bitmap =
                  MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(picUrl));
              ByteArrayOutputStream bao = new ByteArrayOutputStream();
              bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bao);
              byte[] ba = bao.toByteArray();
              img64 = Base64.encodeBytes(ba);
            } catch (FileNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
        }

        break;
      case 1:
        break;

      default:
        break;
    }
  };
コード例 #2
0
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   switch (requestCode) {
     case CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE:
       if (resultCode == Activity.RESULT_OK) {
         Uri selectedImage = imageUri;
         AddFragment.this.getActivity().getContentResolver().notifyChange(selectedImage, null);
         imageView = (ImageView) view.findViewById(R.id.imageView2);
         ContentResolver cr = AddFragment.this.getActivity().getContentResolver();
         try {
           Matrix matrix = new Matrix();
           matrix.postRotate(90);
           bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImage);
           Bitmap rotatedBitmap =
               Bitmap.createBitmap(
                   bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
           imageView.setImageBitmap(rotatedBitmap);
           recupLocation();
         } catch (Exception e) {
           Toast.makeText(AddFragment.this.getActivity(), "Failed to load", Toast.LENGTH_SHORT)
               .show();
           Log.e("Camera", e.toString());
         }
       }
   }
 }
コード例 #3
0
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
      /*
       * Bundle extras = data.getExtras(); Bitmap imageBitmap = (Bitmap) extras.get("data");
       * imageToSend = imageBitmap; //mImageView.setImageBitmap(imageBitmap);
       * //SendBitmapTaskFTP sendToFTP = new SendBitmapTaskFTP(); //sendToFTP.execute();
       * SendBitmapTask sendImage = new SendBitmapTask(); sendImage.execute();
       */
      /*
       * if(data == null){ File file = new File(imageUri.getPath()); fileToSend = file;
       * SendBitmapTask sendImage = new SendBitmapTask(); //sendImage.execute();
       * Log.d("CameraDemo", "Pic saved"); }
       */

      Uri fullPhotoUri = data.getData();

      try {
        Bitmap bm = MediaStore.Images.Media.getBitmap(this.getContentResolver(), fullPhotoUri);
        imageToSend = getResizedBitmap(bm, 1000);
        SendBitmapTask sendImage = new SendBitmapTask();
        sendImage.execute();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
        Toast.makeText(getApplicationContext(), fullPhotoUri.getPath(), Toast.LENGTH_SHORT).show();
      }

      // Toast.makeText(getApplicationContext(), fullPhotoUri.getPath() ,
      // Toast.LENGTH_SHORT).show();
    }
  }
コード例 #4
0
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PICK_IMAGE_REQUEST
        && resultCode == RESULT_OK
        && data != null
        && data.getData() != null) {
      Uri filePath = data.getData();
      try {
        // Getting the Bitmap from Gallery
        bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
        // String image = getStringImage(bitmap);
        Bitmap img_oval = getCroppedBitmap(bitmap);

        /** ******************** Imagen Final ******************* */
        // Setting the Bitmap to ImageView
        imageView.setImageBitmap(img_oval);

      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      Toast.makeText(this, "Tamaño maximo superado", Toast.LENGTH_LONG).show();
    }
  }
コード例 #5
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PICK_IMAGE_REQUEST
        && resultCode == Activity.RESULT_OK
        && data != null
        && data.getData() != null) {
      Uri uri = data.getData();
      try {
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), uri);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] image = stream.toByteArray();
        ParseFile imageFile = new ParseFile("something.png", image);
        Upload upload = new Upload();
        upload.setMedia(imageFile);
        upload.setUserID(ParseUser.getCurrentUser().getObjectId());
        upload.setComment("");
        thisUploads.add(upload);
        newUploads.add(upload);
        adapter.notifyDataSetChanged();

      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #6
0
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   // TODO Auto-generated method stub
   if (resultCode == Activity.RESULT_OK) {
     switch (requestCode) {
       case C.ActivityRequest.REQUEST_SELECT_CITY_ACTIVITY:
         String province = data.getStringExtra("provinceText");
         String city = data.getStringExtra("cityText");
         editArea.setText(province + " " + city);
         break;
       case C.ActivityRequest.REQUEST_SELECT_CAMERA_ACTIVITY:
         Uri cropUri = data.getParcelableExtra("cropPicUri");
         imgPath = cropUri.getPath();
         try {
           Bitmap bmp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), cropUri);
           editAvatar.setImageBitmap(bmp);
         } catch (FileNotFoundException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
         break;
       case C.ActivityRequest.REQUEST_DATE_PICKER_ACTIVITY:
         String birthday = data.getStringExtra("birthday");
         editBirthday.setText(birthday);
         break;
       case C.ActivityRequest.REQUEST_SELECT_GENDER:
         editSex.setText(data.getStringExtra("gender"));
         break;
     }
   }
 }
コード例 #7
0
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   Log.i(TAG, " requestcode: " + requestCode);
   Log.i(TAG, " resultCode: " + resultCode);
   switch (requestCode) {
     case 100:
       if (resultCode == Activity.RESULT_OK) {
         Uri selectedImage = imageUri;
         getActivity().getContentResolver().notifyChange(selectedImage, null);
         ContentResolver cr = getActivity().getContentResolver();
         Bitmap bitmap;
         try {
           bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImage);
           imgFavorite.setImageBitmap(bitmap);
           Log.i(TAG, " butmap " + bitmap.toString());
           Log.i(TAG, " img view " + imgFavorite.toString());
           Log.i(TAG, " img uri " + imageUri.toString());
           imageAdapter.addmThumbIds(imageUri.toString());
         } catch (Exception e) {
           Log.e("Camera", e.toString());
         } finally {
           imageAdapter.notifyDataSetChanged();
         }
       }
   }
 }
コード例 #8
0
  /**
   * 压缩图片到指定大小以内用于附件上传
   *
   * @param context 上下文
   * @param oriImageUri 原始图片 Uri
   * @param fileSize 最大文件大小
   * @return 新得到的图片的 Uri
   */
  public static Uri compressImage(Context context, Uri oriImageUri, int fileSize) {
    try {
      // 压缩图片到指定大小
      Bitmap bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), oriImageUri);

      double targetWidth = Math.sqrt(fileSize * 1000);
      if (bitmap.getWidth() > targetWidth || bitmap.getHeight() > targetWidth) {
        // 创建操作图片用的 matrix 对象
        Matrix matrix = new Matrix();

        // 计算宽高缩放率
        double x = Math.min(targetWidth / bitmap.getWidth(), targetWidth / bitmap.getHeight());

        // 缩放图片动作
        matrix.postScale((float) x, (float) x);
        bitmap =
            Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
      }

      return saveImageToTmpPath(context, bitmap);
    } catch (IOException e) {
      String message = "saveImageToTmpPath >> 压缩图片到指定大小以内用于附件上传失败";
      Log.e(TAG, message, e);
      CommonUtils.debugToast(context, message);
      return null;
    }
  }
コード例 #9
0
ファイル: EquipmentFragment.java プロジェクト: b4w/Projects
  /**
   * Выбираем изображение из галереи телефона и сохраняем в imageView.
   *
   * @param requestCode
   * @param resultCode
   * @param data
   */
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    Bitmap galleryPic = null;

    switch (requestCode) {
      case GALLERY_EQUIPMENT_REQUEST:
        if (resultCode == getActivity().RESULT_OK) {
          Uri selectedImage = data.getData();
          try {
            galleryPic =
                MediaStore.Images.Media.getBitmap(
                    getActivity().getContentResolver(), selectedImage);
          } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          getImage().setImageBitmap(galleryPic);
        }
    }
  }
コード例 #10
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) return;

    try {
      // Load picture from camera and scale/crop it to at most 640x400
      Uri imgFile = Uri.fromFile(new File(getExternalFilesDir(null), "temp.jpg"));
      Bitmap img = MediaStore.Images.Media.getBitmap(getContentResolver(), imgFile);

      int newHeight = (int) ((float) img.getHeight() / (float) img.getWidth() * 640.0f);
      img = Bitmap.createScaledBitmap(img, 640, newHeight, true);

      if (img.getHeight() > 400) {
        img = Bitmap.createBitmap(img, 0, (img.getHeight() - 400) / 2, img.getWidth(), 400);
      }

      System.gc();

      // Store picture with user
      if (mUser != null) {
        try {
          mUser.put("picture_updated", true);
          mUser.put("picture", Util.encodePicture(img));
        } catch (JSONException e) {
          Log.e(TAG, e.toString());
        }
      }

      // Show picture
      mPicture = img;
      onPictureUpdated();
    } catch (IOException e) {
      Log.e(TAG, e.toString());
    }
  }
コード例 #11
0
ファイル: Ocrmain.java プロジェクト: ahm23ad/ScopeMate
  public void ocr_main() {
    Log.v(TAG, "entering tess");

    // Getting uri of image/cropped image
    try {
      myimage = MediaStore.Images.Media.getBitmap(this.getContentResolver(), image_uri);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    // Log.v(TAG, "bitmap " + myimage.getByteCount());
    //        Bitmap argb = myimage;
    //        argb = argb.copy(Bitmap.Config.ARGB_8888, true);
    //        Log.v(TAG, "bitmap after argb:" + argb.getByteCount());
    //
    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inSampleSize = 2;
    myimage = BitmapFactory.decodeFile(filepath, opt);
    // Log.v(TAG, "bitmap after comp:" + myimage.getByteCount());

    // TessBase starts
    TessBaseAPI baseApi = new TessBaseAPI();

    baseApi.setDebug(true);
    baseApi.init(DATA_PATH, lang);
    Log.v(TAG, "Before baseApi");
    baseApi.setImage(myimage);
    Log.v(TAG, "Before baseApi2");
    String recognizedText = baseApi.getUTF8Text();
    Log.v(TAG, "Before baseApi3");
    baseApi.end();

    Log.v(TAG, "OCRED TEXT: " + recognizedText);

    if (lang.equalsIgnoreCase("eng")) {
      recognizedText = recognizedText.replaceAll("[^a-zA-Z0-9]+", " ");
    }

    // recognizedText is the final OCRed text
    recognizedText = recognizedText.trim();

    //		String ocrtext = "And...BAM! OCRed: " + recognizedText;
    //		Toast toast = Toast.makeText(this.getApplicationContext(), ocrtext,
    //				Toast.LENGTH_LONG);
    //		toast.show();

    // deleting temporary crop file created
    File file =
        new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            "temp.bmp");
    boolean deleted = file.delete();
    Log.i(TAG, "File deleted: " + deleted);

    Intent intent = new Intent(this, ResultActivity.class);
    intent.putExtra("ocrText", recognizedText);
    startActivity(intent);
  }
コード例 #12
0
ファイル: DisplayTaskActivity.java プロジェクト: ScottyB/RAT
  private void loadTask() {
    String dataString = "";
    if (task.repetition != null) dataString += "Repetitions: " + task.repetition + '\n';
    if (task.holdTime != null) dataString += "Hold Time: " + task.holdTime + '\n';

    data.setText(dataString);

    txt.setText(task.longName);
    des.setText(task.text);

    anima = new AnimationDrawable();
    Log.e("tag", "IdddddO Exception");
    try {
      Log.e("tag", "" + task.getFrames().get(0));
      still =
          new BitmapDrawable(
              MediaStore.Images.Media.getBitmap(getContentResolver(), task.getFrames().get(0)));
    } catch (FileNotFoundException e1) {
      Log.e("tag", "File Not Found");
    } catch (IOException e1) {
      Log.e("tag", "IO Exception");
    }
    Log.e("tag", "IdddddO Exception");
    int w = still.getIntrinsicWidth();
    int h = still.getIntrinsicHeight();
    img.setMinimumWidth(w * 2);
    img.setMinimumHeight(h * 2);
    Log.e("tag", "Safe ");
    for (int i = 0; i < task.getFrames().size(); i++) {
      Bitmap temp1;
      try {
        temp1 = MediaStore.Images.Media.getBitmap(getContentResolver(), task.getFrames().get(i));
        Log.i("tag", "hello1");
        BitmapDrawable drw = new BitmapDrawable(temp1);
        img.setBackgroundDrawable(drw);
        anima.addFrame(drw, task.frameTimes.get(i) * 1000);
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (IOException e) {

        e.printStackTrace();
      }
    }
    Log.i("tag", "hello");
    img.setBackgroundDrawable(still);
  }
コード例 #13
0
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != RESULT_OK) {
      return;
    }
    Bitmap bm = null;
    ContentResolver resolver = getContentResolver();
    if (requestCode == REQUEST_CODE_PICK_IMAGE) {
      try {
        bm = null;
        Uri originalUri = data.getData();
        bm = MediaStore.Images.Media.getBitmap(resolver, originalUri);
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor cursor = managedQuery(originalUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        String path = cursor.getString(column_index);
        Toast.makeText(getBaseContext(), "pick:" + path, Toast.LENGTH_SHORT).show();
        Bitmap bt = convertToBitmap(path, 100, 120);

        profile_circleimageview.setImageDrawable(new BitmapDrawable(bt));
        saveBitmap(bt);

      } catch (IOException e) {
      }
    } else if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
      //  Bitmap bt=convertToBitmap(path,100,120);
      bm = null;
      try {
        Uri originalUri = data.getData();
        bm = MediaStore.Images.Media.getBitmap(resolver, originalUri);
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor cursor = managedQuery(originalUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        String path = cursor.getString(column_index);
        Bitmap bt = convertToBitmap(path, 100, 120);
        // Toast.makeText(getBaseContext(),"take:"+path,Toast.LENGTH_SHORT).show();
        profile_circleimageview.setImageDrawable(new BitmapDrawable(bt));
        saveBitmap(bt);

      } catch (IOException e) {
        Toast.makeText(getBaseContext(), "Exception", Toast.LENGTH_SHORT).show();
      }
    }
  }
コード例 #14
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    switch (requestCode) {
      case CATEGORY_REQUEST:
        if (resultCode == RESULT_OK) {
          loggedUser.setMajorJobCategory(intent.getStringExtra("major"));
          loggedUser.setMinorJobCategory(intent.getStringExtra("minor"));
          displayCategory();
        }
        break;
      case SKILL_REQUEST:
        if (resultCode == RESULT_OK) {
          loggedUser.setSkills(intent.getStringExtra("strongestSkillsList"));
          displaySkill();
        }
        break;
      case PROFILE_PIC_REQUEST:
        if (resultCode == RESULT_OK) {
          Uri selectedImage = imageUri;

          if (selectedImage != null) {
            getContentResolver().notifyChange(selectedImage, null);

            try {
              OutputStream fOut = null;

              Bitmap bitmap =
                  MediaStore.Images.Media.getBitmap(getContentResolver(), selectedImage);
              Bitmap resizedImage = GraphicUtils.resizeProfileImage(bitmap);

              File file = new File(new URI(selectedImage.toString()));
              fOut = new FileOutputStream(file);

              // Set picture compression
              resizedImage.compress(CompressFormat.JPEG, 70, fOut);
              fOut.flush();
              fOut.close();

            } catch (IOException e) {
            } catch (URISyntaxException e) {
            }

            // Upload user Photo
            exe.uploadUserProfilePhoto();

          } else {
            new CustomDialog(
                    ActivitySettings.this,
                    "Info",
                    "Unable to save picture! We are working on that...")
                .show();
          }
        }

        break;
    }
  }
コード例 #15
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // The preferences returned if the request code is what we had given
    // earlier in startSubActivity
    switch (requestCode) {
      case REQUEST_CODE_CAMERA:
        setRequestedOrientation(
            ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); // pull it out of landscape mode
        break;

      case REQUEST_CODE_IMAGE:
        if (resultCode != RESULT_OK) {
          return;
        }
        Uri uri = data.getData();
        Bitmap b = null;
        try {
          b = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
        } catch (FileNotFoundException e) {
          break;
        } catch (IOException e) {
          break;
        }
        ByteArrayOutputStream byteArrayos = new ByteArrayOutputStream();
        try {
          b.compress(CompressFormat.JPEG, 75, byteArrayos);
          byteArrayos.flush();
        } catch (OutOfMemoryError e) {
          break;
        } catch (IOException e) {
          break;
        }
        filename = "android_pic_upload" + randomString() + ".jpg";
        ImageManager.writeImage(byteArrayos.toByteArray(), filename);
        UshahidiService.fileName = filename;
        selectedPhoto.setText(UshahidiService.fileName);
        break;

      case VIEW_MAP:
        if (resultCode != RESULT_OK) {
          return;
        }

        bundle = null;
        extras = data.getExtras();
        if (extras != null) bundle = extras.getBundle("locations");

        if (bundle != null && !bundle.isEmpty()) {
          incidentLocation.setText(bundle.getString("location"));

          AddIncident.latitude = bundle.getDouble("latitude");
          AddIncident.longitude = bundle.getDouble("longitude");
        }
        break;
    }
  }
コード例 #16
0
 private Bitmap prepareImage(String uri) throws IOException {
   Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(uri));
   ;
   // rotate bitmap
   Matrix matrix = new Matrix();
   matrix.postRotate(getExifOrientation(uri));
   // create new rotated bitmap
   return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
 }
コード例 #17
0
      @Override
      public void onClick(View v) {
        // TODO: Check flag
        final Album album = mAlbums.get(getAdapterPosition());
        mCountPhotos = mImageUris.size();
        if (mSendPhoto) {
          mProgressDialog.show();
          for (Uri imageUri : mImageUris) {
            try {
              final Bitmap bitmap =
                  MediaStore.Images.Media.getBitmap(
                      SearchableActivity.this.getContentResolver(), imageUri);

              ByteArrayOutputStream stream = new ByteArrayOutputStream();
              bitmap.compress(Bitmap.CompressFormat.JPEG, 20, stream);
              final byte[] data = stream.toByteArray();

              ParseFile file = new ParseFile("teste.jpg", data);

              file.saveInBackground(
                  new SaveCallback() {
                    public void done(ParseException e) {
                      // Handle success or failure here ...
                      mCountPhotos--;
                      if (mCountPhotos == 0) {
                        mProgressDialog.dismiss();
                      }
                    }
                  },
                  new ProgressCallback() {
                    public void done(Integer percentDone) {
                      // Update your progress spinner here. percentDone will be between 0 and 100.
                    }
                  });

              Photo photo = new Photo();
              photo.setImage(file);
              photo.setAlbum(album);
              photo.setAuthor(ParseUser.getCurrentUser());
              photo.saveInBackground();

            } catch (IOException e) {
              e.printStackTrace();
            }
            mSendPhoto = false;
          }

        } else {
          Intent intent = new Intent(SearchableActivity.this, AlbumDetailActivity.class);
          intent.putExtra(AlbumDetailActivity.ALBUM_ID_EXTRA, album.getObjectId());
          intent.putExtra(AlbumDetailActivity.ALBUM_NAME_EXTRA, album.getName());
          startActivity(intent);
        }
      }
コード例 #18
0
  @Test
  public void decodeUri_shouldGetWidthAndHeightFromHints() throws Exception {
    ShadowBitmapFactory.provideWidthAndHeightHints(Uri.parse("content:/path"), 123, 456);

    Bitmap bitmap =
        MediaStore.Images.Media.getBitmap(
            Robolectric.application.getContentResolver(), Uri.parse("content:/path"));
    assertEquals("Bitmap for content:/path", shadowOf(bitmap).getDescription());
    assertEquals(123, bitmap.getWidth());
    assertEquals(456, bitmap.getHeight());
  }
コード例 #19
0
 private Bitmap getBitmapFromUri(ContentResolver context, Uri uri) {
   try {
     // 读取uri所在的图片
     Bitmap bitmap = MediaStore.Images.Media.getBitmap(context, uri);
     return bitmap;
   } catch (Exception e) {
     Log.e("[Android]", e.getMessage());
     Log.e("[Android]", "目录为:" + uri);
     e.printStackTrace();
     return null;
   }
 }
コード例 #20
0
 private void handleCrop(int resultCode, Intent result) {
   if (resultCode == RESULT_OK) {
     ib_avatar.setImageURI(Crop.getOutput(result));
     try {
       avatarBitmap =
           MediaStore.Images.Media.getBitmap(this.getContentResolver(), Crop.getOutput(result));
     } catch (IOException e) {
       e.printStackTrace();
     }
     btnSave.setProgress(0);
   } else if (resultCode == Crop.RESULT_ERROR) {
     Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
   }
 }
コード例 #21
0
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
      String sdCardState = Environment.getExternalStorageState();
      if (!sdCardState.equals(Environment.MEDIA_MOUNTED)) {

        return;

      } else {
        ContentResolver resolver = getContentResolver();
        Uri imgUri = data.getData();
        try {
          Bitmap photo = MediaStore.Images.Media.getBitmap(resolver, imgUri);
          base64pic = bitmaptoString(photo);
          new Thread(
                  new Runnable() {

                    @Override
                    public void run() {
                      if (!curActionID.equals("") && !"".equals(base64pic)) {

                        showWaitingDialog();
                        ReturnResult<String> rrbase64 =
                            ConnectProviderZX.upActivityPhoto(
                                UserManager.uid, curActionID, base64pic);
                        if (rrbase64.status.equals("0")) {
                          getData();
                          getData();
                        } else {
                          Toast.makeText(getApplicationContext(), "上传图片失败!", Toast.LENGTH_SHORT)
                              .show();
                        }
                        hideWaitingDialog();
                      }
                    }
                  })
              .start();

        } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    } else {
      Toast.makeText(getApplicationContext(), "相册获取图片失败!", Toast.LENGTH_SHORT).show();
    }
  }
コード例 #22
0
ファイル: Submit.java プロジェクト: Econitex/Slide
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {

      if (requestCode == 1) {
        Uri selectedImageUri = data.getData();
        try {
          Bitmap bitmap =
              MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
          new UploadImgur().execute(bitmap);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
コード例 #23
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    //    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
      Bitmap imageBitmap = null;
      ImageView pictureView = fanImage;
      contextMenuInUse = true;

      switch (requestCode) {
        case REQUEST_IMAGE_CAPTURE:
          Bundle extras = data.getExtras();
          imageBitmap = (Bitmap) extras.get("data");
          updateProfileImage = true;
          break;
        case REQUEST_LOAD_IMAGE:
          Uri selectedImage = data.getData();
          try {
            if (isAttached) {
              ContentResolver contentResolver = getActivity().getContentResolver();
              imageBitmap = MediaStore.Images.Media.getBitmap(contentResolver, selectedImage);
              imageBitmap =
                  Bitmap.createScaledBitmap(
                      imageBitmap, pictureView.getWidth(), pictureView.getHeight(), true);
              fanImageByteArray = toByteArray(imageBitmap);
              updateProfileImage = true;
              Picasso.with(getActivity())
                  .load(selectedImage)
                  .transform(new CircleTransform())
                  .into(fanImage);
            }
          } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(
                    getActivity().getApplicationContext(),
                    "Error cargando la imagen",
                    Toast.LENGTH_SHORT)
                .show();
          }
          break;
      }

      if (pictureView != null && imageBitmap != null)
        pictureView.setImageDrawable(ImagesUtils.getRoundedBitmap(getResources(), imageBitmap));
    }
  }
コード例 #24
0
ファイル: DroidGap.java プロジェクト: j0ton/phonegap-android
  protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    if (resultCode == Activity.RESULT_OK) {
      Uri selectedImage = imageUri;
      getContentResolver().notifyChange(selectedImage, null);
      ContentResolver cr = getContentResolver();
      Bitmap bitmap;
      try {
        bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImage);
        launcher.processPicture(bitmap);
      } catch (Exception e) {
        launcher.failPicture("Did not complete!");
      }
    } else {
      launcher.failPicture("Did not complete!");
    }
  }
コード例 #25
0
ファイル: EditProfile.java プロジェクト: WaiKeith/CanteenPOS
  private void showSelectedImage(Uri selectedImageUri) {

    try {
      Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), selectedImageUri);
      int nh = (int) (bitmap.getHeight() * (512.0 / bitmap.getWidth()));
      Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 512, nh, true);

      if (mLoadImageNo == 1) {
        mImageProfile.setImageDrawable(null);
        mImageProfile.setScaleType(ImageView.ScaleType.FIT_XY);
        mImageProfile.setImageBitmap(scaled);
        mBitmapImage1 = scaled;
        // ImageView2.setVisibility(View.VISIBLE);
      } else genericError(null);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #26
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1) {
      if (resultCode == Activity.RESULT_OK) {

        Bitmap bm = null;
        // 外界的程序访问ContentProvider所提供数据 可以通过ContentResolver接口
        ContentResolver resolver = getContentResolver();

        try {
          Uri originalUri = data.getData(); // 获得图片的uri
          Log.d("huang", "uri=" + originalUri);
          bm = MediaStore.Images.Media.getBitmap(resolver, originalUri); // 显得到bitmap图片

          // 这里开始的第二部分,获取图片的路径:

          String[] proj = {MediaStore.Images.Media.DATA};

          // 好像是android多媒体数据库的封装接口,具体的看Android文档
          @SuppressWarnings("deprecation")
          Cursor cursor = managedQuery(originalUri, proj, null, null, null);
          // 按我个人理解 这个是获得用户选择的图片的索引值
          int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
          // 将光标移至开头 ,这个很重要,不小心很容易引起越界
          cursor.moveToFirst();
          // 最后根据索引值获取图片路径
          final String path = cursor.getString(column_index);
          File file = new File(path); // 这里的path就是那个地址的全局变量
          addPhotoFileList.add(file);

          ImageView image = new ImageView(UpTravleNoteActivity.this);
          image.setScaleType(ScaleType.CENTER_CROP);
          image.setLayoutParams(new LayoutParams(150, 150));
          image.setPadding(5, 5, 5, 5);
          image.setImageURI(originalUri);

          travelAddPictureLinearLayout.addView(image);

        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
コード例 #27
0
ファイル: ProfileActivity.java プロジェクト: Sivashankar06/KK
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   switch (requestCode) {
     case UPDATE_PIC:
       if (resultCode == RESULT_OK && data != null) {
         // Bundle extras = data.getExtras();
         Uri filePath = data.getData();
         Log.d(TAG, "Data : " + filePath);
         try {
           // mBitmap = data.getParcelableExtra("data");
           Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
           if (bitmap != null) {
             mBitmap = Helper.scaleBitmap(bitmap);
             Log.d(
                 TAG,
                 "L : "
                     + mBitmap.getWidth()
                     + "  : "
                     + mBitmap.getScaledHeight(getResources().getDisplayMetrics()));
             profileImgView.setImageBitmap(mBitmap);
             imageprofilestring = Helper.getStringImage(mBitmap);
             Log.d(TAG, "Image message value length : " + imageprofilestring.length());
             Log.d(TAG, "Image message value is : " + imageprofilestring);
             if (!TextUtils.isEmpty(userid)) {
               String body =
                   Helper.getUpdateProfileBody(userid, Keys.KEY_PROFIMG, imageprofilestring);
               new ProfileUpdateTask().execute(body);
               mDBHelper.updateProfile(body);
             }
           } else {
             Snackbar.make(profileImgView, "Bitmap is null", Snackbar.LENGTH_LONG)
                 .setAction("Action", null)
                 .show();
             Log.d(TAG, "Bitmap is null");
           }
         } catch (IOException e) {
           e.printStackTrace();
         }
       }
       break;
   }
 }
コード例 #28
0
 public void onActivityResult(int reqCode, int resCode, Intent data) {
   if (resCode == RESULT_OK) {
     if (reqCode == 1) {
       imageUri = data.getData();
       discoImageImgView.setImageURI(data.getData());
     }
   }
   ContentResolver cr = this.getContentResolver();
   Bitmap bit = null;
   try {
     bit = android.provider.MediaStore.Images.Media.getBitmap(cr, imageUri);
     ExifInterface exif = new ExifInterface(file.getAbsolutePath());
     Matrix matrix = new Matrix();
     bit = Bitmap.createBitmap(bit, 0, 0, bit.getWidth(), bit.getHeight(), matrix, true);
   } catch (Exception e) {
     e.printStackTrace();
   }
   discoImageImgView.setImageBitmap(bit);
 }
コード例 #29
0
ファイル: TextTool.java プロジェクト: tloyd/SecondApp
  public static SpannableString getWeiboContent(
      final Context context, final TextView tv, String source) {
    String regexEmoji = "\\[[^\\[\\]]+\\]";

    String regex = regexEmoji;

    SpannableString spannableString = new SpannableString(source);
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(spannableString);

    if (matcher.find()) {
      tv.setMovementMethod(LinkMovementMethod.getInstance());
      matcher.reset();
    }

    while (matcher.find()) {
      String emojiStr = matcher.group();
      if (emojiStr != null) {
        int start = matcher.start();
        String pathName = emojiStr.substring(1, emojiStr.length() - 1);
        Uri uri = Uri.parse(pathName);
        Bitmap bitmap = null;
        try {
          bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (bitmap != null) {
          int size = (int) tv.getTextSize();
          float scale = (float) bitmap.getHeight() / bitmap.getWidth();
          int screenWidthPixels = ScreenTool.getScreenWidthPixels((Activity) context);
          int height = (int) (screenWidthPixels * scale);

          bitmap = Bitmap.createScaledBitmap(bitmap, screenWidthPixels, height, true);
          ImageSpan imageSpan = new ImageSpan(context, bitmap);
          spannableString.setSpan(
              imageSpan, start, start + emojiStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
      }
    }
    return spannableString;
  }
コード例 #30
-1
ファイル: ToolPhone.java プロジェクト: ykbjson/SMTCompat
  /**
   * 获得选中相册的图片
   *
   * @param mContext 上下文
   * @param data onActivityResult返回的Intent
   * @return
   */
  public static Bitmap getChoosedImage(Activity mContext, Intent data) {
    if (data == null) {
      return null;
    }

    Bitmap bm = null;

    // 外界的程序访问ContentProvider所提供数据 可以通过ContentResolver接口
    ContentResolver resolver = mContext.getContentResolver();

    // 此处的用于判断接收的Activity是不是你想要的那个
    try {
      Uri originalUri = data.getData(); // 获得图片的uri
      bm = MediaStore.Images.Media.getBitmap(resolver, originalUri); // 显得到bitmap图片
      // 这里开始的第二部分,获取图片的路径:
      String[] proj = {MediaStore.Images.Media.DATA};
      // 好像是android多媒体数据库的封装接口,具体的看Android文档
      Cursor cursor = mContext.managedQuery(originalUri, proj, null, null, null);
      // 按我个人理解 这个是获得用户选择的图片的索引值
      int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      // 将光标移至开头 ,这个很重要,不小心很容易引起越界
      cursor.moveToFirst();
      // 最后根据索引值获取图片路径
      String path = cursor.getString(column_index);
      // 不用了关闭游标
      cursor.close();
    } catch (Exception e) {
      Log.e("ToolPhone", e.getMessage());
    }

    return bm;
  }