BitmapShader将图片转化为圆形图片
来源:互联网 发布:2016网络作家排名 编辑:程序博客网 时间:2024/04/30 14:10
转载请注明出处,谢谢!
今天用BitmapShader实现圆形图片
package com.example.bitmap_porterduffxfermode;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.BitmapShader;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.Shader;import android.util.AttributeSet;import android.view.View;import android.view.View.MeasureSpec;public class RoundRectShaderView extends View {private int mMeasureHeigth;private int mMeasureWidth;private BitmapShader mBitmapShader;private Bitmap mBitmap;private Paint mPaint;public RoundRectShaderView(Context context) {super(context);}public RoundRectShaderView(Context context, AttributeSet attrs) {super(context, attrs);}public RoundRectShaderView(Context context, AttributeSet attrs,int defStyleAttr) {super(context, attrs, defStyleAttr);}@Overrideprotected void onMeasure(int widthMeasureSpec,int heightMeasureSpec) {mMeasureWidth = MeasureSpec.getSize(widthMeasureSpec);mMeasureHeigth = MeasureSpec.getSize(heightMeasureSpec);setMeasuredDimension(mMeasureWidth, mMeasureHeigth);}@Overrideprotected void onDraw(Canvas canvas) {float length = 0;if (mMeasureHeigth >= mMeasureWidth) {length = mMeasureWidth;} else {length = mMeasureHeigth;}mBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.zhongyu);mBitmapShader = new BitmapShader(mBitmap,Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);mPaint = new Paint();mPaint.setShader(mBitmapShader);canvas.drawCircle(length/2, length/2, length/2, mPaint);}}
<com.example.bitmap_porterduffxfermode.RoundRectShaderView android:layout_width="200dp" android:layout_height="200dp" android:layout_gravity="center_horizontal" > </com.example.bitmap_porterduffxfermode.RoundRectShaderView>
测量一下View的高度,根据测量的高度设置遮罩层的大小,情况是这样,如果绘制的圆形小于图像大小,之会显示部分图像
弄清原理就明白了.
到底如何才能实现缩放图像大小呢?
0 0
- BitmapShader将图片转化为圆形图片
- BitmapShader绘制圆形图片
- android之将图片转化为圆形图片
- android之将图片转化为圆形图片
- 用BitmapShader实现圆形图片
- 将图片剪裁为圆形
- android将图片转换为圆形图片
- 使用BitmapShader实现图片的圆形、圆角
- 使用BitmapShader实现圆形,圆角图片
- Android BitmapShader 实现圆形、圆角图片
- BitmapShader渲染器:实现圆形图片
- 将PDF转化为图片
- 将图片转化为字符串
- 将颜色转化为图片
- 将图片转化为PDF
- 将Markdown转化为图片
- 将canvas转化为图片
- android 将图片处理为圆形
- JavaScript中数组和字符串的方法以及互相转换
- Warning C4819
- C++作业3
- windows/linux进程控制实验
- PSobj [2] 图片动漫处理 及 速写处理
- BitmapShader将图片转化为圆形图片
- VS2012通过makefile编译OpenGL红宝书的示例代码
- 固定屏幕代码
- 山东省第一届ACM省赛 J SDUT 2160 Jerry Mouse
- java中的条件语句switch……case
- 码农小汪-spring框架学习之7-spring的零配置 @Component @Controller @Service
- 算法学习之动态规划(一)
- Python
- Android 官方教程-相机操作