0

In my app, I have built a camera function in the Activity B. The selected image will then placed in the imageView B.

Activity B ---> one imageView B, used to place the selected image

The selected image can be displayed on ImageView B, but it looked blur. Please tell me what should I do . Thanks in advance !

Activity B

 private void activeGallery() {
      Intent intent = new Intent(Intent.ACTION_PICK,
      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
      startActivityForResult(intent, RESULT_LOAD_IMAGE);
      }


   @Override
      protected void onActivityResult(int requestCode, int resultCode,Intent data) {
           super.onActivityResult(requestCode, resultCode, data);
           switch (requestCode) {
           case RESULT_LOAD_IMAGE:
          if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK & null != data) {
                  Uri selectedImage = data.getData();
                  String[] filePathColumn = {MediaStore.Images.Media.DATA};
                  Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null,null);
                  cursor.moveToFirst();
                  int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                  String picturePath = cursor.getString(columnIndex);
                  cursor.close();
                  Bitmap a = (BitmapFactory.decodeFile(picturePath));
                  photo=scaleBitmap(a,200,200);
                  imageView.setImageBitmap(photo);
                      }
              }
          }

        public static Bitmap scaleBitmap(Bitmap bitmap, int wantedWidth, int wantedHeight) {
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            float scaleWidth = ((float) wantedWidth) / width;
            float scaleHeight = ((float) wantedHeight) / height;
         // create a matrix for the manipulation
            Matrix matrix = new Matrix();
        // resize the bit map
          matrix.postScale(scaleWidth, scaleHeight);
          // recreate the new Bitmap
            Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, wantedWidth, wantedHeight, false);
        return resizedBitmap;
        }

Original image

enter image description here

Place in ImageView B (looked blur)

enter image description here

Tony
  • 2,515
  • 14
  • 38
  • 71
  • please share to me if you have any solution or example for this :) – Tony Dec 11 '15 at 10:18
  • Question has been asked before, here's the anwer that helped me: http://stackoverflow.com/a/9234895/3044945 – P. Stresow Dec 11 '15 at 10:25
  • Thanks for the link. But if the bitmap image pass to listView, how can I fix the size of the imageView ? – Tony Dec 11 '15 at 10:36
  • This was not part of your question... Anyway. Take a look here [ImageView](http://developer.android.com/reference/android/widget/ImageView.html) and pay attantion to the attributes "android:cropToPadding " and "android:scaleType" Also:You're doing a lot of computing on the main thread (ui thread), please consider an AsyncTask. – P. Stresow Dec 11 '15 at 11:37

1 Answers1

0

how can I fix the size of the imageView ?

You may try this

<ImageView
        android:id="@+id/YourImageViewId"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentRight="true"
        android:scaleType="centerInside"
        android:gravity="right|center_vertical"
        android:padding="10px"
        />

Source get from here

Community
  • 1
  • 1
John Joe
  • 12,412
  • 16
  • 70
  • 135