2017-12-22 30 views
-1

을 뻗어하지 흐림을받지 나는이이미지뿐만 아니라

enter image description here

같은 것을하고 싶었다

String url ="http://static.tvtropes.org/pmwiki/pub/images/stephen_amell.png"; 
     Picasso.with(getActivity()).load(url) 
         .transform(new BlurTransformation(getActivity())) 
         .into(imgBlurImage); 

blurtransformation.java

public class BlurTransformation implements Transformation { 

    RenderScript rs; 
    private static final int RADIUS = 10; 

    public BlurTransformation(Context context) { 
     super(); 
     rs = RenderScript.create(context); 
    } 

    @Override 
    public Bitmap transform(Bitmap bitmap) { 
     // Create another bitmap that will hold the results of the filter. 
     Bitmap blurredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); 

     // Allocate memory for Renderscript to work with 
     Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL, 
       Allocation.USAGE_SHARED); 
     Allocation output = Allocation.createTyped(rs, input.getType()); 

     // Load up an instance of the specific script that we want to use. 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 
      ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); 
      script.setInput(input); 
      // Set the blur radius 
      script.setRadius(RADIUS); 
      // Start the ScriptIntrinisicBlur 
      script.forEach(output); 
     } 
     // Copy the output to the blurred bitmap 
     output.copyTo(blurredBitmap); 
     bitmap.recycle(); 
     return blurredBitmap; 
    } 

    @Override 
    public String key() { 
     return "blur"; 
    } 
} 

는 나는이 enter image description here

+1

당신이 당신의 실제 결과를 보여주는 이미지를 게시 할 수 있을까요? –

+0

@ 해이 해킹 내 편집 된 답변을 확인하십시오 –

+0

xml 파일 포함 –

답변

1

이미지가 흐려있어 이미지 의 크기에 내 원하는 결과를 얻을 수 아니에요. 완벽한 스케일 유형이없는 이미지 뷰입니다. 이미지보기에 android:scaleType="centerCrop"을 사용하십시오.

<ImageView 
     android:id="@+id/img_2" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:scaleType="centerCrop" /> 
+0

나는 완벽한 이미지를 얻지 못하는 것보다 centercrop을 사용합니다. 이미지의 머리 부분이 숨겨집니다. –

+0

이것이 센터 크롭의 작동 방식입니다. – ADM

1

머리 부분을 숨기지 않으려면 다음과 같이 fitStart를 설정하십시오.

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:scaleType="fitStart" /> 

확인 여기 scaleType에 대한 또 다른 옵션 : enter image description here

+0

제발 내 이미지를 참조하십시오 이미지를 가로로 늘리고 가로로 가운데에 맞춰주세요. 내 이미지 너비가 높이와 많이 비교되지 않기 때문에 –

+0

@NiravJoshi이 경우 fitXY를 사용하십시오 –