2016-02-08 65 views
0

我加載從圖像的URL到我的ImageView像這樣 -與ImageLoader的頂級作物 - Android電子

ImageLoader.getInstance().displayImage(url, imageview, display-options) 

現在我想將圖片裁剪到中心頂部。我嘗試使用https://gist.github.com/arriolac/3843346,但我認爲它期望通過可繪製的圖像,我想使用ImageLoader來設置圖像。

有人可以幫我理解我是否可以將https://code.google.com/archive/p/android-query/(Android Query)與ImageLoader結合使用?

是否有任何方法可以在本地處理Android中的裁剪(除了centerCrop)?

回答

1

與ProfileImageView替換您的ImageView和欣賞美景:)

public class ProfileImageView extends ImageView { 
private Bitmap bm; 

public ProfileImageView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    bm = null; 
} 

@Override 
protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 
    super.onLayout(changed, left, top, right, bottom); 
    if (bm != null) { 
     setImageBitmap(bm); 
     bm = null; 
    } 
} 

@Override 
public void setImageBitmap(Bitmap bm) { 
    int viewWidth = getWidth(); 
    int viewHeight = getHeight(); 
    if (viewWidth == 0 || viewHeight == 0) { 
     this.bm = bm; 
     return; 
    } 
    setScaleType(ScaleType.MATRIX); 

    Matrix m = getImageMatrix(); 
    m.reset(); 
    int min = Math.min(bm.getWidth(), bm.getHeight()); 
    int cut; 
    if (bm.getWidth() > viewWidth && bm.getWidth() > bm.getHeight()) { 
     cut = Math.round((bm.getWidth() - viewWidth)/2.f); 
    } else { 
     cut = 0; 
    } 
    RectF drawableRect = new RectF(cut, 0, min - cut, min); 

    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); 
    m.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.START); 
    setImageMatrix(m); 
    super.setImageBitmap(bm); 
} 

}