我有一个很大的 jpeg 文件,大小为 10000 x 150000 像素。我想在图像底部添加一个小 Logo 而不调整大小。
如果我对原始图像进行下采样并使用 Canvas 绘制 Logo ,我就可以做到这一点。但是当我最终将其保存到文件时,图像原始尺寸将在我采样时减小。
如果我将原始图像加载到位图中而不进行下采样,则它超出了VM。
最佳答案
下面的代码对我有用:-
public static Bitmap mark(Bitmap src, String watermark, Point location, Color color, int alpha, int size, boolean underline) {
int w = src.getWidth();
int h = src.getHeight();
Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());
Canvas canvas = new Canvas(result);
canvas.drawBitmap(src, 0, 0, null);
Paint paint = new Paint();
paint.setColor(color);
paint.setAlpha(alpha);
paint.setTextSize(size);
paint.setAntiAlias(true);
paint.setUnderlineText(underline);
canvas.drawText(watermark, location.x, location.y, paint);
return result;
}
关于java - Android向非常大的jpg文件添加水印 Logo (例如10000 x 150000),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28062510/