public static Bitmap createReflectedImage(Context context, Bitmap originalImage) {
//The gap we want between the reflection and the original image
final int reflectionGap = 4;
int width = originalImage.getWidth();
int height = originalImage.getHeight();
//This will not scale but will flip on the Y axis
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
//Create a Bitmap with the flip matrix applied to it.
//We only want the bottom half of the image
Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height/2, width, height/2, matrix, false);
//Create a new bitmap with same width but taller to fit reflection
Bitmap bitmapWithReflection = Bitmap.createBitmap(width
, (height + height/2), Config.ARGB_8888);
//Create a new Canvas with the bitmap that's big enough for
//the image plus gap plus reflection
Canvas canvas = new Canvas(bitmapWithReflection);
//Draw in the original image
canvas.drawBitmap(originalImage, 0, 0, null);
//Draw in the gap
Paint defaultPaint = new Paint();
canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
//Draw in the reflection
canvas.drawBitmap(reflectionImage,0, height + reflectionGap, null);
//Create a shader that is a linear gradient that covers the reflection
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0,
bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff,
TileMode.CLAMP);
//Set the paint to use this shader (linear gradient)
paint.setShader(shader);
//Set the Transfer mode to be porter duff and destination in
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
//Draw a rectangle using the paint with our linear gradient
canvas.drawRect(0, height, width,
bitmapWithReflection.getHeight() + reflectionGap, paint);
return bitmapWithReflection;
}
分享到:
相关推荐
Halcon_Bitmap转换方法 写的文档 开发笔记
一个在VC中将Bitmap转换为Byte[]的小例子。
纯C++代码写文件的形式生成Bitmap。对于理解Bitmap的格式有着非常好的效果。 纯C++代码写文件的形式生成Bitmap。对于理解Bitmap的格式有着非常好的效果。
Android不支持将Bitmap转换成单色的Bmp图片,所以参考Bmp格式说明,自己写了一个转换类。亲测有效!!!
Bitmap 转 txt 源码
将Bitmap转成byte[],进行保存,用到时再取出byte[],转化成Bitmap,进行显示
海康SDK采图 生成BitMap类型的图片
机器视觉技术必备,从位图到halcon图像,bitmap图像转为halcon图像,bitmap to Hobject
主要对于应用NI Vision和C#的,bitmap和Ni图像之间的一个转换(彩色)
输入一串字符串 自动生成bitmap 和exe同一目录下, 几乎包含所有的编码方式
winform下Bitmap转wpf下ImageSource
bitmap转jpeg源码,包括RGB转YCbCr,DCT,Quantization, zig-zag, huffman,jpeg头文件的封装。
改用原始图像数据流回调函数RegisterImageStreamCallback进行抓图 但回调函数帧为YUV420格式 需要转成Bitmap才用用于显示及本地查看 在网上找了好多都是基于R Y+1 4075 V 128 G Y 0 3455 U 128 – 0 7169 V 128 B Y+...
博客配套文件,解决常见的Bitmap转HBITMAP背景变浅,HBITMAP转Bitmap背景变黑的问题,并演示了如何输出HBITMAP和Bitmap的每行像素,所有代码封装成了类,可以直接在生产环境中使用。
Bitmap位图旋转范例 一个完整工程
BMP2H264 Bitmap图像转换为H264
将图片由bitmap类型转换为stream类型再转换为byte[]类型,然后再还原
C#语言下,官方好像没有提供直接的方式把Bitmap转为Mat,但是可以使用我的这个方式转变格式