我试过了,createScaledBitmap
但是没有用。这是我的代码:
@Override
public Bitmap transform(Bitmap bitmap) {
// TODO Auto-generated method stub
synchronized (ImageTransform.class) {
if (bitmap == null) {
return null;
}
Bitmap resultBitmap = bitmap.copy(bitmap.getConfig(), true);
Bitmap bitmapImage = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_heart);
Bitmap.createScaledBitmap(
bitmapImage, 1, 1, true);
Canvas canvas = new Canvas(resultBitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.FILL);
paint.setTextSize(40);
paint.setShadowLayer(2.0f, 1.0f, 1.0f, Color.BLACK);
canvas.drawText("$250", 10, 400, paint);
canvas.drawBitmap(bitmapImage, 460, 45, null);
bitmap.recycle();
return resultBitmap;
}
}
图片无法缩放我可以看到非常大的图片。上面的代码在的Transformation
类中Picasso
。
为什么要缩放您的位图图像?
让我们来看一下您的代码:
Bitmap resultBitmap = bitmap.copy(bitmap.getConfig(), true);
好的,这是将添加炉膛的位图
Bitmap bitmapImage = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_heart);
您在此处阅读炉膛图像,以便稍后将其添加到“主”图像中
Bitmap.createScaledBitmap(
bitmapImage, 1, 1, true);
这是多余的调用,因为在此省略了方法调用的结果...
Canvas canvas = new Canvas(resultBitmap);
在这里,我们得到了带有可变位图的新画布进行修改
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.FILL);
paint.setTextSize(40);
paint.setShadowLayer(2.0f, 1.0f, 1.0f, Color.BLACK);
canvas.drawText("$250", 10, 400, paint);
您在这里开价,还可以
canvas.drawBitmap(bitmapImage, 460, 45, null);
您可以在此处绘制从资源中读取而未经修改的位图图像
bitmap.recycle();
这与Android 3.0无关
return resultBitmap;
返回您的图片...
如您所见,您有一个方法调用:Bitmap.createScaledBitmap(bitmapImage, 1, 1, true);
这实际上没有任何作用。替换为:bitmapImage = Bitmap.createScaledBitmap(bitmapImage, 1, 1, true);
并且应该没问题。
如果您想在此处优化内存使用(因为您要在此处创建3个位图而不是1个位图),请阅读本文章。希望能有所帮助:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句