【发布时间】:2013-12-29 16:53:08
【问题描述】:
我有大尺寸的图像,我需要切割 60% 的高度和 60% 的宽度,并以圆角显示结果图像。
我已应用此代码
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
它工作正常,但我必须设置大约 50 个这样的图像。所以它减慢了这个过程,我必须等待大约 4 秒才能打开整个过程的 Activity。
我也试过了
android:adjustViewBounds="true"
但正因为如此,我的图像已设置,但问题是因为大图像会在小区域内缩小。它看起来不太好。
有没有人有其他方法来完成这项工作?是否可以在 xml 中完成整个工作,以便在运行时我们可以减少 Activity 打开的一些时间。请帮助..
【问题讨论】:
-
如果您的图像在大多数情况下都是固定的,那么我建议您使用图像缓存,它只需要一次时间,从下一次它将从缓存中获取这些图像而无需整个计算,您的将节省 cpu 时间和内存。
-
+1 为你的建议。你能给我一些示例链接来实现它。
标签: android image shape rounding clip