资源描述:
《Android的基本2D图形处理课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Android的图形处理Android目录2D图形的裁剪2D图形的缩放,旋转裁剪2D的图形裁剪t50=((BitmapDrawable)getResources().getDrawable(R.drawable.wallpaper)).getBitmap();Paint=newPaint();Paint.setAntiAlias(true);Paint.setStrokeWidth(6);Paint.setTextSize(16);Paint.setTextAlign(Paint.Align.RIGHT);裁剪//开启Canvas
2、的save方法,准备进行图片裁剪Canvas.save();//移动原点坐标Canvas.translate(10,10);//封装绘图方法drawScene(canvas);//重置CanvasCanvas.restore();Canvas裁剪//设置裁剪区域Canvas.clipRect(0,0,100,100);Canvas.drawColor(Color.WHITE);//画线Paint.setColor(Color.RED);Canvas.drawLine(0,0,100,100,mPaint);//画圆Paint.se
3、tColor(Color.GREEN);Canvas.drawCircle(30,70,30,mPaint);//画文字Paint.setColor(Color.BLUE);Canvas.drawText("Clipping",100,30,mPaint);图片的旋转//canvas.save();//旋转角度canvas.rotate(15.0f);//移动画笔坐标canvas.translate(20,20);//设置裁剪区域canvas.clipRect(20,20,180,200);//画图canvas.drawBitma
4、p(t50,20,20,mPaint);//重置canvas.restore();图形的缩放//对Matrix矩阵做初始化操作MatrixmMatrix=newMatrix();mMatrix.reset();//设置缩放比例mMatrix.postScale(0.6f,0.5f);//得到缩放后的图片t51=Bitmap.createBitmap(t50,0,0,t50.getWidth(),t50.getHeight(),mMatrix,true);//把缩放后的图片绘制出来canvas.drawBitmap(t51,10,1
5、0,null);缩放的第二种方式图形的渲染BitmapShader—位图渲染LinearGradient—线性渲染ComposeShader—组合渲染RadialGradient—环形渐变渲染SweepGradient—梯度渲染ShapeDrawable—形状处理辅助类渲染//获取图片image=((BitmapDrawable)getResources().getDrawable(R.drawable.t502)).getBitmap();//获取图片宽度和高度imageWidth=image.getWidth();imageH
6、eight=image.getHeight();创建Shader对象//创建BitmapShader对象mBitmapShader=newBitmapShader(image,Shader.TileMode.REPEAT,Shader.TileMode.MIRROR);//创建线性渲染Shader对象mLinearGradient=newLinearGradient(0,0,100,100,newint[]{Color.RED,Color.GREEN,Color.BLUE,Color.WHITE},null,Shader.Tile
7、Mode.REPEAT);//组合两种渲染效果mComposeShader=newComposeShader(mBitmapShader,mLinearGradient,PorterDuff.Mode.DARKEN);生命周期案例//创建环形渲染mRadialGradient=newRadialGradient(50,200,50,newint[]{Color.GREEN,Color.RED,Color.BLUE,Color.WHITE},null,Shader.TileMode.REPEAT);//创建梯度渲染mSweepGra
8、dient=newSweepGradient(30,30,newint[]{Color.GREEN,Color.RED,Color.BLUE,Color.WHITE},null);渲染//位图截取mShapeDrawableQQ=newShapeD