2011-12-03 38 views
2

ギャラリーから画像ビューにiamgeを表示したい。 ギャラリーから画像を呼び出すときに、カメラからの画像のサイズを固定したいと思います。 私に手を差し伸べてもらえますか? カメラから選択すると、createScaledBitmapとしてスケーリングされたイメージにすることができます。 setImageURI以外のアイデアがある場合は、アドバイスをいただけますか? URIの代わりにsetImageBitmapを使用できますか? blob型のsqliteに保存するなど、関連するリストでこれらの画像を保存します。 アドバイスをお願いします。ありがとう。拡大縮小画像を表示ギャラリーから見る

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    super.onActivityResult(requestCode, resultCode, data); 
    if (resultCode != RESULT_OK) return; 
     switch (requestCode) 
     { 
     case PICK_FROM_CAMERA: 
      Bundle extras = data.getExtras(); 
      Bitmap selectedImage = (Bitmap) extras.get("data"); 
      selectedImage = Bitmap.createScaledBitmap(selectedImage, 200, 250, false); 
      mImageView.setImageBitmap(selectedImage); 
      break; 

     case PICK_FROM_GALLERY: 
      Uri selectedImageUri = data.getData(); 
      selectedImagePath = getPath(selectedImageUri); 
      System.out.println("Image Path : " + selectedImagePath); 
      mImageView.setImageURI(selectedImageUri); 
     break; 
     } 
} 
+1

は、なぜあなたはBitmap.createScaledBitmapを使用いけないCASE PICK_FROM_GALLERYでこれを試してみてください()はサイズを固定する – Abhi

+0

PICK_FROM_CAMERAと同じ意味ですか?どうやって使うの? – wholee1

答えて

2

Uri selectedImageUri = data.getData(); 
    selectedImagePath = getPath(selectedImageUri); 

Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath); 

    Bitmap bt=Bitmap.createScaledBitmap(bitmap, 150, 150, false); 

    photo_image.setImageBitmap(bt) 
+0

ありがとう!イメージを読み込んでいます。乾杯! – wholee1

+0

:)歓迎歓迎 – Abhi

+0

私のイメージは、これを使用してstrechedになっています。 –

1
Bitmap photobitmap = BitmapFactory.decodeFile(selectedImagePath); 


if(photoBitmap!=null) 
          { 
           // Compressing large image to small one 

           Display display = getWindowManager().getDefaultDisplay(); 

           int width = display.getWidth(); 
           int height = display.getHeight(); 


          int photo_width = photoBitmap.getWidth(); 
          int photo_height = photoBitmap.getHeight(); 

          if(photo_width >width) 
           photo_width = width; 

          if(photo_height > height) 
           photo_height = height; 

            photoBitmap = Bitmap.createScaledBitmap (photoBitmap, photo_width , photo_height , false); 

            photo.setImageBitmap(photoBitmap); 
          } 

//あなたのImageViewの高さとwidhtがそれらを指定する固定されている場合。私はデバイスの高さと幅をより理解のために取った。

+0

imageViewのIDはphoto_imageで、幅と高さは150dpです。あなたはimageViewの固定サイズを設定できますか? – wholee1

0
ImageView imageView = findViewById(R.id.photo_image); 

Bitmap photobitmap = BitmapFactory.decodeFile(selectedImagePath); 


if(photoBitmap!=null) 
          { 

          int photo_width = photoBitmap.getWidth(); 
          int photo_height = photoBitmap.getHeight(); 
    //1dp = 1.5 px 150dp = 225px 

          if(photo_width >225) 
           photo_width = 225; 

          if(photo_height > 225) 
           photo_height = 225; 

            photoBitmap = Bitmap.createScaledBitmap (photoBitmap, photo_width , photo_height , false); 

            photo.setImageBitmap(photoBitmap); 
          } 
0
あなたがしたい場合は、画像の規模のサイズを変更するビットマップ工場オプション&を使用することができます

..

Uri selectedImageUri = data.getData(); 
selectedImagePath = getPath(selectedImageUri); 

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inSampleSize = 8; // your sample size 
Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath,options); 
mImageView.setImageBitmap(bitmap); 
関連する問題