2011-06-27 44 views
3

我從畫廊中縮略圖圖像,尺寸較小並調整爲300 * 300的大小。在android中的圖像模糊

通過這樣做看起來如此模糊的圖像。

從畫廊得到圖像

@Override 
    protected void onActivityResult(int requestCode, int resultCode, 
      Intent imageReturnedIntent) { 
     super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

     switch (requestCode) { 
     case 0: 
      if (resultCode == RESULT_OK) { 
       try { 
        flag = 1; 
        Uri selectedImage = imageReturnedIntent.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 filePath = cursor.getString(columnIndex); // file 
        // path 
        // of 
        // selected 
        // image 
        cursor.close(); 

        // Convert file path into bitmap image using below line. 

        yourSelectedImage = download.getResizedBitmap(
         image.decodeImage(filePath),270,228); 

        // put bitmapimage in your imageview 
        profile_image.setImageBitmap(
          yourSelectedImage); 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 
      } 
     } 
    } 

圖像大小調整

public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) 
    { 
     try 
     { 
      if(bm!=null) 
      { 
      int width = bm.getWidth(); 
      int height = bm.getHeight(); 
      float scaleWidth = ((float) newWidth)/width; 
      float scaleHeight = ((float) newHeight)/height; 
      // create a matrix for the manipulation 
      Matrix matrix = new Matrix(); 
      // resize the bit map 
      matrix.postScale(scaleWidth, scaleHeight); 
      // recreate the new Bitmap 
      resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); 


      } 
      } 
      catch(Exception e) 
      { 
       e.printStackTrace(); 
      } 

     return resizedBitmap; 
    } 
+0

這裏沒有問題!你想知道什麼? – Kenny

+0

如何解決模糊問題。 – Kakey

回答

2

形象得到模糊(除非你使用的是矢量圖像,而你正在使用位圖)。您的getResizedBitmap方法除了拉伸圖像以適應新的尺寸外,沒有其他任何其他方法。你要解決你的問題的唯一方法是選擇更大的圖像(但最終你會遇到高寬比問題,所以你應該重新考慮你的縮放算法)。

0

當然擴大位圖圖像將像素化中。當你放大他們

+0

如何解決這個問題? – Kakey

+0

找到一個更大的替代圖像。對你太糟糕了。 – shernshiou