BitmapShader图片渲染
2012-08-14 16:28
267 查看
import org.apache.http.client.CircularRedirectException; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Shader; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.OvalShape; import android.view.View; /** * @version 2012-8-14 上午10:45:28 **/ public class BitGameView extends View implements Runnable { Bitmap mBitmap = null; int bitwidth = 0; int bitheight = 0; Paint mPaint = null; // bitmap渲染 Shader mBitmapShader = null; ShapeDrawable mShapeDrawable = null; public BitGameView(Context context) { super(context); // 装载资源 mBitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.abc)) .getBitmap(); // 得到宽高 bitwidth = mBitmap.getWidth(); bitheight = mBitmap.getHeight(); // 创建BitmapShader对象 已何种方式重复 mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mPaint = new Paint(); new Thread(this).start(); } @Override protected void onDraw(Canvas canvas) { // 自定义为椭圆形 mShapeDrawable = new ShapeDrawable(new OvalShape()); // RectShape矩形 // ArcShape弧形 // PathShape任意多边形 // RoundRectShape圆角矩形 // OvalShape椭圆 // 设置要绘制的椭圆形的图片 mShapeDrawable.getPaint().setShader(mBitmapShader); // 设置显示区域 mShapeDrawable.setBounds(0, 0, bitwidth * 2, bitheight * 2); // 绘制图片 mShapeDrawable.draw(canvas); } @Override public void run() { while(!Thread.currentThread().isInterrupted()) { try { Thread.sleep(100); } catch(Exception e) { Thread.currentThread().interrupt(); } postInvalidate(); } } }
相关文章推荐
- Android Shader渲染器:BitmapShader图片渲染
- Android Shader渲染器:BitmapShader图片渲染
- Android 图片特效处理:Shader着色器、渲染
- bitmapshader的clamp模式(绘制Bitmap渲染的椭圆)
- Bitmap位图渲染与操作(图片移动,放大,缩小,旋转,镜像发转)
- Android 图片渲染之Shader渲染器
- Android自定义view实现圆形、圆角和椭圆图片(BitmapShader图形渲染)
- Android 自定义View修炼-Android实现圆形、圆角和椭圆自定义图片View(使用BitmapShader图形渲染方法)
- Android使用BitmapShader图形渲染实现圆形、圆角和椭圆自定义图片View
- Bitmap位图渲染与操作(图片移动,放大,缩小,旋转,镜像发转)--android游戏开发
- Android bitmap图片处理
- Android学习笔记进阶15之Shader渲染
- bitmap大图片内存溢出问题
- android 怎么把网络图片生成一个Bitmap显示在ImageView中
- Android之Glide获取图片Path和Glide获取图片Bitmap
- Unity Shader入门精要学习笔记 - 第16章 Unity中的渲染优化技术
- Bitmap 实现对图片压缩的2种方法小结
- Android使用BitmapFactory.Options解决加载大图片内存溢出问题
- Android Bitmap 全面解析(二)加载多张图片的缓存处理 ...
- inSampleSize Matrix 组合缩放图片(bitmap size exceeds 32 bits???)