Android 将带有壁画的位图加载到抽屉视图
有没有办法将带有壁画的位图加载到抽屉视图中? 有点像你可以用滑翔来做的:Android 将带有壁画的位图加载到抽屉视图,android,bitmap,fresco,Android,Bitmap,Fresco,有没有办法将带有壁画的位图加载到抽屉视图中? 有点像你可以用滑翔来做的: Glide.with(context) .load(bitmap) .into(imageView); Fresco可以为您执行这些操作。从评论中,我看到您希望以一种有效的方式处理位图,因此可以让Fresco这样做。 至于您正在进行的裁剪,有多种方法可以使用湿壁画进行裁剪: 如果不需要位图,请使用“缩放”类型:Fresco具有多个ImageView,包括将焦点裁剪到图像中的给定点,还可以实现自己的缩放,
Glide.with(context)
.load(bitmap)
.into(imageView);
Fresco可以为您执行这些操作。从评论中,我看到您希望以一种有效的方式处理位图,因此可以让Fresco这样做。 至于您正在进行的裁剪,有多种方法可以使用湿壁画进行裁剪:
- 如果不需要位图,请使用“缩放”类型:Fresco具有多个ImageView,包括将焦点裁剪到图像中的给定点,还可以实现自己的缩放,请参见
- 如果需要裁剪的位图,可以通过后处理器实现裁剪逻辑(如果需要还可以缓存位图),请参阅
@Override
public void getTransformImpl(
Matrix outTransform,
Rect parentRect,
int childWidth,
int childHeight,
float focusX,
float focusY,
float scaleX,
float scaleY) {
// Your computations, such as for example a fit bottom implementation:
float scale = Math.min(scaleX, scaleY);
float dx = parentRect.left;
float dy = parentRect.top + (parentRect.height() - childHeight * scale);
outTransform.setScale(scale, scale);
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
}
可进行缩放和模糊的后处理器示例:
公共类缩放BlurPostProcessor扩展了BasePostprocessor{
专用最终油漆mPaint=新油漆();
私人的最终决定;
私人最终国际会议;
/**
*比例比为4意味着我们将要处理的像素总数减少了16倍。
*/
私人最终收入比率;
公共缩放模糊后处理器(整数迭代、整数模糊半径、整数缩放){
先决条件.checkArgument(scaleRatio>0);
斜接=迭代;
mBlurRadius=模糊半径;
mScaleRatio=比例;
}
@凌驾
公共可关闭参考流程(
位图源位图,平台位图工厂位图工厂){
最终可关闭参考位图参考=
bitmapFactory.createBitmap(
sourceBitmap.getWidth()/mScaleRatio,sourceBitmap.getHeight()/mScaleRatio);
试一试{
最终位图destBitmap=bitmapRef.get();
最终画布=新画布(位图);
canvas.draw位图(
源位图,
无效的
新的Rect(0,0,destBitmap.getWidth(),destBitmap.getHeight()),
mPaint);
NativeBlurFilter.iterativeBoxBlur(
删除位图、斜接、数学最大值(1,mBlurRadius/mScaleRatio);
返回CloseableReference.cloneOrNull(bitmapRef);
}最后{
CloseableReference.CloseSafety(位图参考);
}
}
}
此位图来自何处?存储设备?你的资产文件夹?因为如果它来自设备存储,您可以简单地使用ImageView
,因为drayeview
不适合这样做。那么,您使用抽屉查看
的原因是什么呢?位图
是从相机拍摄的裁剪图像创建的ImageView
方法不足以加载大图像。同意我的观点,我想我的观点是为什么选择Fresco这样唯一一个不容易处理位图的库,如果你使用ImageRequest
和DrawController
等,它可以做到,但像毕加索和Glide这样的库要容易得多。那么,为什么要使用一个没有目的的库呢?或者很容易达到目的。我建议毕加索我已经用过很多了,Glide和项目要求一样好。。。我完全同意。无论如何谢谢你!
public class ScalingBlurPostprocessor extends BasePostprocessor {
private final Paint mPaint = new Paint();
private final int mIterations;
private final int mBlurRadius;
/**
* A scale ration of 4 means that we reduce the total number of pixels to process by factor 16.
*/
private final int mScaleRatio;
public ScalingBlurPostprocessor(int iterations, int blurRadius, int scaleRatio) {
Preconditions.checkArgument(scaleRatio > 0);
mIterations = iterations;
mBlurRadius = blurRadius;
mScaleRatio = scaleRatio;
}
@Override
public CloseableReference<Bitmap> process(
Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) {
final CloseableReference<Bitmap> bitmapRef =
bitmapFactory.createBitmap(
sourceBitmap.getWidth() / mScaleRatio, sourceBitmap.getHeight() / mScaleRatio);
try {
final Bitmap destBitmap = bitmapRef.get();
final Canvas canvas = new Canvas(destBitmap);
canvas.drawBitmap(
sourceBitmap,
null,
new Rect(0, 0, destBitmap.getWidth(), destBitmap.getHeight()),
mPaint);
NativeBlurFilter.iterativeBoxBlur(
destBitmap, mIterations, Math.max(1, mBlurRadius / mScaleRatio));
return CloseableReference.cloneOrNull(bitmapRef);
} finally {
CloseableReference.closeSafely(bitmapRef);
}
}
}