我正在尝试将一个图像水印添加到另一个图像。我有以下代码,但我面临一个问题。我不知道这个“资源资源”是什么。
有人能帮上忙吗?
public static Bitmap addWatermark(Resources res, Bitmap source)
{
int w, h;
Canvas c;
Paint paint;
Bitmap bmp, watermark;
Matrix matrix;
float scale;
RectF r;
w = source.getWidth();
h = source.getHeight();
bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG |Paint.FILTER_BITMAP_FLAG);
c = new Canvas(bmp);
c.drawBitmap(source, 0, 0, paint);
watermark = BitmapFactory.decodeResource(res, R.drawable.android_mo);
scale = (float) (((float) h * 0.10) / (float) watermark.getHeight());
matrix = new Matrix();
matrix.postScale(scale, scale);
r = new RectF(0, 0, watermark.getWidth(), watermark.getHeight());
matrix.mapRect(r);
matrix.postTranslate(w - r.width(), h - r.height());
c.drawBitmap(watermark, matrix, paint);
watermark.recycle();
return bmp;
}发布于 2015-11-08 12:12:38
它是您可以通过activity.getResources()或fragment.getResources()获得的资源对象
发布于 2019-03-02 16:31:50
Resources res 是您需要从调用活动/片段传递的资源对象。
假设,如果该方法在Utility类中,则按如下方式调用该方法
//Add watermark to the selected image
Bitmap markedBitmap = Utility.addWatermark(context.getResources(), bitmap);发布于 2016-06-13 22:09:40
主位图为bmp1和bmp2透明位图:
public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);
canvas.drawBitmap(bmp2, 0, 0, null);
return bmOverlay;
}https://stackoverflow.com/questions/33590627
复制相似问题