Android 毕加索图书馆未在姜饼设备中应用圆变换
我使用下面的代码使用Square的毕加索库将圆形遮罩应用于位图。它在安卓3.0及更高版本的设备上运行良好,但在姜饼上无法运行。运行时不会显示错误或异常,相反,掩码似乎不会应用于原始图像Android 毕加索图书馆未在姜饼设备中应用圆变换,android,android-layout,picasso,Android,Android Layout,Picasso,我使用下面的代码使用Square的毕加索库将圆形遮罩应用于位图。它在安卓3.0及更高版本的设备上运行良好,但在姜饼上无法运行。运行时不会显示错误或异常,相反,掩码似乎不会应用于原始图像 public class CircleTransformation implements Transformation { @Override public Bitmap transform(Bitmap source) { int size = Math.min(source.
public class CircleTransformation implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
Bitmap finalBitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(finalBitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float radius = size / 2f;
canvas.drawCircle(radius, radius, radius, paint);
source.recycle();
return finalBitmap;
}
@Override
public String key() {
return "circle";
}
}
从API级别1开始,我使用的所有方法似乎都是可用的,所以我有点卡住了。你知道会有什么问题吗
警察局。此代码基于:我仍然不知道为什么此代码在姜饼中不起作用,但我能够通过使用圆形遮罩图像使其起作用:
public class PreHoneycombCircleTransformation implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
int dim = Constants.BUBBLE_WIDTH;
Canvas canvas = new Canvas();
// placeholder for final image
Bitmap result = Bitmap.createBitmap(dim, dim, Bitmap.Config.ARGB_8888);
canvas.setBitmap(result);
Paint paint = new Paint();
paint.setFilterBitmap(false);
// resize image fills the whole canvas
canvas.drawBitmap(source, null, new Rect(0, 0, dim, dim), paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
canvas.drawBitmap(Util.getMaskImage(), 0, 0, paint);
paint.setXfermode(null);
if(result != source) {
source.recycle();
}
return result;
}
@Override
public String key() {
return "pre_circle";
}
}
下面的课程是另一种选择,既适用于姜饼,也适用于ICS。CircletTransformation中的代码在ICS中对我不起作用
public class CircleTransform implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
float radius = size / 2f;
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawCircle(radius, radius, radius, paint);
if (source != output) {
source.recycle();
}
return output;
}
@Override
public String key() {
return "circle";
}
}
我刚刚在安卓姜饼设备上进行了测试,测试结果正常。你能告诉我你的android版本吗?这里的Util.getMaskImage()是什么?仅仅是一个位图就证实了这种方法在姜饼和棒棒糖中有效。