public
Bitmap createBitmapForWatermark
(Bitmap src, Bitmap watermark) {
if (src == null) {
return null;
}
int w = src.getWidth();
int h = src.getHeight();
int ww = watermark.getWidth();
int wh = watermark.getHeight();
Bitmap newb = Bitmap.createBitmap(ww, wh, Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
Canvas cv = new Canvas(newb);
Matrix m = new Matrix();
m.postScale(1, -1);//上下翻转
m.postRotate(-90);//左右翻转
Bitmap newBitmap = Bitmap.createBitmap(src, 0, 0, w, h, m, true);
cv.drawBitmap(newBitmap, new Rect(0, 0, newBitmap.getWidth(), newBitmap.getHeight()),new Rect(0, 0, ww, wh), null);
cv.drawBitmap(watermark,0,0, null);// 前景图或水印
cv.save(Canvas.ALL_SAVE_FLAG);// 保存
// store
cv.restore();// 存储
return newb;
}
下面的方法则是用像素处理,速度会慢一点。
Bitmap changePixel_180(Bitmap orgBitmap) {
int pixels_width;
int pixels_height;
pixels_width = orgBitmap.getWidth();
pixels_height = orgBitmap.getHeight();
Bitmap newb = Bitmap.createBitmap(pixels_width, pixels_height, Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
for (int i = 0; i < pixels_height; i++) {
for (int j = 0; j < pixels_width; j++) {
newb.setPixel(j, i, orgBitmap.getPixel(j, pixels_height-1-i));
}
}
return newb;
}
Bitmap changePixel_90_r(Bitmap orgBitmap) {
int pixels_width;
int pixels_height;
pixels_width = orgBitmap.getWidth();