- 浏览: 50224 次
- 性别:
- 来自: 深圳
-
最新评论
package com.example.android.apis.graphics; import android.app.Activity; import android.content.Context; import android.graphics.*; import android.os.Bundle; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.*; public class Patterns extends GraphicsActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SampleView(this)); } private static Bitmap makeBitmap1() { Bitmap bm = Bitmap.createBitmap(40, 40, Bitmap.Config.RGB_565); Canvas c = new Canvas(bm); c.drawColor(Color.RED); Paint p = new Paint(); p.setColor(Color.BLUE); c.drawRect(5, 5, 35, 35, p); return bm; } private static Bitmap makeBitmap2() { Bitmap bm = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bm); Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); p.setColor(Color.GREEN); p.setAlpha(0xCC); c.drawCircle(32, 32, 27, p); return bm; } private static class SampleView extends View { private final Shader mShader1; private final Shader mShader2; private final Paint mPaint; private final DrawFilter mFastDF; private float mTouchStartX; private float mTouchStartY; private float mTouchCurrX; private float mTouchCurrY; private DrawFilter mDF; public SampleView(Context context) { super(context); setFocusable(true); setFocusableInTouchMode(true); mFastDF = new PaintFlagsDrawFilter(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG, 0);//不方便给画笔加过滤效果的,可以DrawFilter直接作用于canvas, 这里是增强bitmap效果 mShader1 = new BitmapShader(makeBitmap1(), Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);//图形阴影(要填充的图形,X方向填充模式,Y方向填充模式。 mShader2 = new BitmapShader(makeBitmap2(), Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); Matrix m = new Matrix(); m.setRotate(30); mShader2.setLocalMatrix(m);//给shader应用形变 mPaint = new Paint(Paint.FILTER_BITMAP_FLAG); } @Override protected void onDraw(Canvas canvas) { canvas.setDrawFilter(mDF);//给画布增效过滤。 mPaint.setShader(mShader1); canvas.drawPaint(mPaint);//绘制底层方格 canvas.translate(mTouchCurrX - mTouchStartX, mTouchCurrY - mTouchStartY);//移动画布,然后绘制,达到拖动效果 mPaint.setShader(mShader2);//上层圆形 canvas.drawPaint(mPaint); } @Override public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mTouchStartX = mTouchCurrX = x; mTouchStartY = mTouchCurrY = y; mDF = mFastDF; invalidate(); break; case MotionEvent.ACTION_MOVE: mTouchCurrX = x; mTouchCurrY = y; invalidate(); break; case MotionEvent.ACTION_UP: mDF = null; invalidate(); break; } return true; } } }
发表评论
-
图片处理
2012-11-28 02:48 0http://www.linuxidc.com/Linux/2 ... -
Api Demo - .graphics(24)>>Cube
2012-08-03 15:18 1273package com.example.android.api ... -
Api Demo - .graphics(24)>>TouchRotateActivity
2012-08-03 15:07 1154package com.example.android.api ... -
Api Demo - .graphics(23)>>CubeMapActivity
2012-07-31 16:31 1486package com.opengl.test; imp ... -
opengles 学习关键字
2012-07-24 09:35 724主动渲染、平面着色、透视投影、near、索引法、glLight ... -
Api Demo - .graphics(21)>>StaticTriangleRenderer
2012-07-23 17:51 1284package com.example.android.api ... -
Api Demo - .graphics(20)>>CompressedTextureActivity
2012-07-23 16:50 1409/* * Copyright (C) 2008 The A ... -
Api Demo - .graphics(18)
2012-07-20 10:32 855package com.example.android.api ... -
Api Demo - .graphics(17)
2012-07-19 11:43 985/* package com.example.andro ... -
Api Demo - .graphics(16)
2012-07-18 14:54 647package com.example.android.api ... -
Api Demo - .graphics(15)
2012-07-18 12:55 869package com.example.android.api ... -
Api Demo - .graphics(14)
2012-07-18 11:50 861package com.example.android.api ... -
Api Demo - .graphics(13)
2012-07-17 11:38 940//关键字 Paint,MaskFilte,Path,Xfer ... -
Api Demo - .graphics(12)
2012-07-17 10:44 701<?xml version="1.0" ... -
Api Demo - .graphics(11)
2012-07-17 09:53 823//关键字:Shader ,ShapeDrawable pa ... -
Api Demo - .graphics(10)
2012-07-16 17:59 1079/* * Copyright (C) 2008 The A ... -
Api Demo - .graphics(9)
2012-07-16 11:26 787//关键字:颜色合成,JPEG,PNG图片解压,Bitmap压 ... -
Api Demo - .graphics(8)
2012-07-16 10:43 680//关键字:ColorMatrixColorFilter; ... -
Api Demo - .graphics(7)
2012-07-16 09:53 832// 关键字:Porter-Duff package c ... -
Api Demo - .graphics(6)
2012-07-16 08:57 817//关键字:截取画布 p ...
相关推荐
3.8.2 Patrolling a square using SMACH..........................................................................19 3.8.3 Testing SMACH navigation in the ArbotiX simulator..................................
in the demo directory. Installing JavaMail 1.2 To use the JavaMail 1.2 API, download the JavaMail 1.2 implementation, unbundle the javamail-1_2.zip file, and add the mail.jar file to your ...
9.4. Zend_Date API Overview 9.4.1. Zend_Date Options 9.4.1.1. Selecting the date format type 9.4.1.2. DST and Date Math 9.4.1.3. Month Calculations 9.4.1.4. Speed up date localization and ...
This is an excellent example.<END><br>18 , savepos.zip This will show you how to save and load the last recorded position of your form.<END><br>19 , shapeform.zip This will change the shape of ...
- Added support for VGA graphics mode with 400 lines (partial fix for SF bug #2948724) - NE2K: Fixed "send buffer" command issue on big endian hosts - USB - converted common USB code plus devices ...
The implementation relies on bezier curves instead of SVG graphics, and is compatible below API 19. DEMO APK How? The library provides a few implementations like SearchArrowDrawable, ...
16.zip Comment / Uncomment macros 命令/反命令宏(5KB)<END><br>17,17.zip Custom built files 自定义生成的文件(5KB)<END><br>18,18.zip Define Method 定义方法(5KB)<END><br>19,19.zip ...
19.zip Apply a 3D bitmap pattern on text or other shapes 将文字上色(3维的位图模板)(6KB)<END><br>20,20.zip Encapsulated Dib API 压缩设备无关位图的API(5KB)<END><br>21,21.zip An enhanced ...