- 浏览: 47185 次
- 性别:
- 来自: 深圳
最新评论
//关键字:drawBitmapMesh,矩阵取逆, package com.example.android.apis.graphics; import com.example.android.apis.R; import android.content.Context; import android.graphics.*; import android.os.Bundle; import android.view.*; import android.util.FloatMath; public class BitmapMesh extends GraphicsActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SampleView(this)); } private static class SampleView extends View { private static final int WIDTH = 20;//横向20个网格 private static final int HEIGHT = 20;//竖向20个网格 private static final int COUNT = (WIDTH + 1) * (HEIGHT + 1);//顶点数 private final Bitmap mBitmap; private final float[] mVerts = new float[COUNT*2]; private final float[] mOrig = new float[COUNT*2]; private final Matrix mMatrix = new Matrix(); private final Matrix mInverse = new Matrix(); private static void setXY(float[] array, int index, float x, float y) {设置定点坐标 array[index*2 + 0] = x; array[index*2 + 1] = y; } public SampleView(Context context) { super(context); setFocusable(true); mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.beach); float w = mBitmap.getWidth(); float h = mBitmap.getHeight(); // construct our mesh int index = 0; for (int y = 0; y <= HEIGHT; y++) {//遍历顶点 float fy = h * y / HEIGHT; for (int x = 0; x <= WIDTH; x++) { float fx = w * x / WIDTH; setXY(mVerts, index, fx, fy); setXY(mOrig, index, fx, fy); index += 1; } } mMatrix.setTranslate(10, 10);// 矩阵平移 mMatrix.invert(mInverse);//矩阵取逆,获取上一步矩阵变换的逆操作,以后将触摸点坐标转换为画布坐标操作要用到。 } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(0xFFCCCCCC); canvas.concat(mMatrix);//应用矩阵变换。 canvas.drawBitmapMesh(mBitmap, WIDTH, HEIGHT, mVerts, 0, null, 0, null);将图片画到格子上 } private void warp(float cx, float cy) { final float K = 10000; float[] src = mOrig; float[] dst = mVerts; for (int i = 0; i < COUNT*2; i += 2) { float x = src[i+0]; float y = src[i+1]; float dx = cx - x; float dy = cy - y; float dd = dx*dx + dy*dy; float d = FloatMath.sqrt(dd);//各顶点到触摸点的距离 float pull = K / (dd + 0.000001f); pull /= (d + 0.000001f); // 距离越近,变化值越大, 距离超过一定范围,做修正处理,将不做变换 if (pull >= 1) { dst[i+0] = cx; dst[i+1] = cy; } else { dst[i+0] = x + dx * pull; dst[i+1] = y + dy * pull; } } } private int mLastWarpX = -9999; // don't match a touch coordinate private int mLastWarpY; @Override public boolean onTouchEvent(MotionEvent event) { float[] pt = { event.getX(), event.getY() }; mInverse.mapPoints(pt); int x = (int)pt[0]; int y = (int)pt[1]; if (mLastWarpX != x || mLastWarpY != y) { mLastWarpX = x; mLastWarpY = y; warp(pt[0], pt[1]); invalidate(); } return true; } } }
发表评论
-
图片处理
2012-11-28 02:48 0http://www.linuxidc.com/Linux/2 ... -
Api Demo - .graphics(24)>>Cube
2012-08-03 15:18 1150package com.example.android.api ... -
Api Demo - .graphics(24)>>TouchRotateActivity
2012-08-03 15:07 1039package com.example.android.api ... -
Api Demo - .graphics(23)>>CubeMapActivity
2012-07-31 16:31 1389package com.opengl.test; imp ... -
opengles 学习关键字
2012-07-24 09:35 638主动渲染、平面着色、透视投影、near、索引法、glLight ... -
Api Demo - .graphics(21)>>StaticTriangleRenderer
2012-07-23 17:51 1235package com.example.android.api ... -
Api Demo - .graphics(20)>>CompressedTextureActivity
2012-07-23 16:50 1367/* * Copyright (C) 2008 The A ... -
Api Demo - .graphics(19)
2012-07-20 22:45 722package com.example.android.api ... -
Api Demo - .graphics(18)
2012-07-20 10:32 818package com.example.android.api ... -
Api Demo - .graphics(17)
2012-07-19 11:43 933/* package com.example.andro ... -
Api Demo - .graphics(16)
2012-07-18 14:54 600package com.example.android.api ... -
Api Demo - .graphics(15)
2012-07-18 12:55 799package com.example.android.api ... -
Api Demo - .graphics(14)
2012-07-18 11:50 810package com.example.android.api ... -
Api Demo - .graphics(13)
2012-07-17 11:38 903//关键字 Paint,MaskFilte,Path,Xfer ... -
Api Demo - .graphics(12)
2012-07-17 10:44 651<?xml version="1.0" ... -
Api Demo - .graphics(11)
2012-07-17 09:53 784//关键字:Shader ,ShapeDrawable pa ... -
Api Demo - .graphics(10)
2012-07-16 17:59 1042/* * Copyright (C) 2008 The A ... -
Api Demo - .graphics(9)
2012-07-16 11:26 749//关键字:颜色合成,JPEG,PNG图片解压,Bitmap压 ... -
Api Demo - .graphics(8)
2012-07-16 10:43 650//关键字:ColorMatrixColorFilter; ... -
Api Demo - .graphics(7)
2012-07-16 09:53 736// 关键字:Porter-Duff package c ...
相关推荐
Microsoft.Maui.Graphics是完全使用C#针对iOS,Android,Windows,macOS,Tizen和Linux的跨平台图形库。 使用此库,您可以使用通用API来定位多个抽象,从而使您可以在平台之间共享绘图代码,或在单个应用程序内混合...
代码很短,但是找jar包找的欲仙欲死,包括commons-io-1.4.jar,commons-logging-1.1.1.jar,docx4j-3.3.3.jar,freemarker.jar,google-collections.jar,log4j-1.2.8....xalan-2.7.0.jar,xmlgraphics-commons-1.3.jar
ArcGIS API for iOS 使您可使用 Objective C 构建多种应用程序(这些应用程序将运用 ArcGIS Server 提供的强大制图、地理编码、地理处理和自定义功能)并将它们部署到 Apple iPhone、iPod Touch 和 iPad 设备。API ...
WebGL Audio API for 3D Graphics in Three.JS by Igor Fortel 6 pages pdf short paper with a small demo
很多的官方demo,api,超值的啊。 animation ApiDemos.java ApiDemosApplication.java app appwidget content graphics media os text view
:示例代码介绍了如何使用API和遮挡剔除的可配置项。 :该示例代码提供了供离线超分辨率插件参考或使用的程序。 :该示例代码提供了可供参考或使用插件的程序。 有关更多信息,您可以在每个样本中检出README...
当前大多数搞机器人开发的用户所装的ROS是indigo版本,而且是基于Ubuntu14.04的。如果你跑别的版本的rbx代码老出错,不用怀疑,就是代码版本问题!ros by example for indigo volume 1很多地方(包括CSDN)都可以...
安卓开发例程,内置图形界面开发 硬件开发 nfc 媒体应用开发等官方demo
5. A couple of simple demo applications. History ------- RX 2.75 (Oct,12,1999). Delphi 5.0 & C++Builder 4.0 compatibility. Bug fixes for RX 2.60. RX 2.60 (Jan,27,1999). New components ...
围绕Unity新的实验性Vector API的简单包装,让您就像在HTML5画布中一样进行绘制。 演示基本的填充,笔触和填充规则。 例如: m_Graphics.MoveTo(900, 150);m_Graphics.BezierCurveTo(910, 250, 940, 250, 950, 250);...
Perform AI and Game Logic ..........................................17 Section 5: Render Next Frame ........................................................18 Section 6: Synchronize Display .......
android API demo 包括accessibility animation app content graphics media nfc os preference ...
API: MovieEvent()和draw()函数的调用速度不同。 因此,最好在MovieEvent()中进行所有帧处理。 或者,您可以首先保存所有帧,然后将它们作为图像文件顺序加载到draw()中。 删除背景的示例:chp16 / example...
Also see demo\tasks\localization. There are the required XML files. - if flag wpDontAddExternalFontLeading is active in property FormatOptionsEx the text will be formatted more like WPTools4/MS-...
Fundamentals of the JavaMail API Page 5 Presented by developerWorks, your source for great tutorials ibm.com/developerWorks Section 4. Installing JavaMail Introduction There are two versions ...
这是一个自己整理的详细的英文Raphael 2.2参考文档,压缩包内包含pdf参考文档《Learning Raphael JS Vector Graphics》和示例demo。
RX Library 2.75 =============== The Set of Native Delphi Components for Borland Delphi versions 1, 2, 3, 4 & 5 and Borland C++ Builder 1, 3 & 4. ...5. A couple of simple demo applications.
7.13.5. 从 0.2.0 或以前的版本移植到 0.6.0 8. Zend_Currency 8.1. Zend_Currency 简介 8.1.1. 为什么使用 Zend_Currency ? 8.2. 如何使用货币 8.2.1. 从货币创建输出 8.2.2. 修改货币格式 8.2.3. Zend_...
- 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 ...
as an interval value), and will provide Up and/or Dn graphics to enable navigation between the menu sections.<END><br>40 , CoolExplorer2.zip The new and improved Cool Explorer: Many new functions....