2017-12-22 2 views
-1
gestreckt

Ich wollte so etwas wie dieseBild nicht so gut bekommen Unschärfe als nicht

enter image description here

ich versuchte, mit Picaso aber nicht immer jede wert Lösung

Hier meinen Code

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

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"; 
    } 
} 

Ich bin nicht in der Lage mein gewünschtes Ergebnis auf dieser Größe des Bildes ich diese verschwimmen bekam enter image description here

+1

Könnten Sie das Bild zeigt, Ihre tatsächliche Ergebnis posten? –

+0

@Hai Hack Bitte überprüfen Sie meine bearbeitete Antwort –

+0

Fügen Sie die XML-Datei, bitte –

Antwort

1

Bild ist. Es ist Ihre Bildansicht, die nicht den perfekten Skalentyp hat. Verwenden Sie android:scaleType="centerCrop" für die Bildansicht.

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

Ich benutze Centercrop als ich bekomme kein perfektes Bild der Kopfteil des Bildes wird versteckt –

+0

So funktioniert Centercrop. – ADM

1

Wenn Sie nicht möchten, dass der Kopfteil verdeckt ist, setzen Sie fitStart wie folgt.

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

prüfen weitere Optionen für Scaletype hier: enter image description here

+0

Bitte beziehen Sie sich auf mein Bild Ich möchte Bild gestreckt zu horizontal und horizontal in der Mitte passen. weil die Breite meines Bildes ist nicht viel verglichen mit Höhe –

+0

@ NiravJoshi In diesem Fall verwenden Sie fitXY –

Verwandte Themen