android.graphics.Camera实现图像的旋转、缩放,配合Matrix...
来源:互联网 发布:mac照片如何导入iphone 编辑:程序博客网 时间:2024/05/29 17:03
原文:http://www.eoeandroid.com/thread-202761-1-1.html
主程序:
package com.example.progressui;import android.R.integer;import android.os.Bundle;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.Camera;import android.graphics.Matrix;import android.graphics.drawable.BitmapDrawable;import android.view.Menu;import android.view.MenuItem;import android.widget.ImageView;import android.widget.SeekBar;import android.widget.SeekBar.OnSeekBarChangeListener;import android.widget.TextView;import android.support.v4.app.NavUtils;public class ProgressActivity extends Activity implements OnSeekBarChangeListener {//声明变量private SeekBar seekbarXRotate;private SeekBar seekbarYRotate;private SeekBar seekbarZRotate;private TextView txtXRotate;private TextView txtYRotate;private TextView txtZRotate;private SeekBar seekbarXSkew;private SeekBar seekbarYSkew;private TextView txtXTranslate;private TextView txtYTranslate;private SeekBar seekbarZTranslate;private TextView txtZTranslate;private int rotateX,rotateY,rotateZ;private float skewX,skewY;private int translateZ;private ImageView imgResult;private Camera camera;private int dx;private int dy; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_progress); camera = new Camera(); seekbarXRotate = (SeekBar)findViewById(R.id.seekbarXRotate); seekbarXRotate.setOnSeekBarChangeListener(this); seekbarYRotate = (SeekBar)findViewById(R.id.seekbarYRotate); seekbarYRotate.setOnSeekBarChangeListener(this); seekbarZRotate = (SeekBar)findViewById(R.id.seekbarZRotate); seekbarZRotate.setOnSeekBarChangeListener(this); txtXRotate = (TextView)findViewById(R.id.txtXRotate); txtYRotate = (TextView)findViewById(R.id.txtYRotate); txtZRotate = (TextView)findViewById(R.id.txtZRotate); seekbarXSkew = (SeekBar)findViewById(R.id.seekbarXSkew); seekbarXSkew.setOnSeekBarChangeListener(this); seekbarYSkew = (SeekBar)findViewById(R.id.seekbarYSkew); seekbarYSkew.setOnSeekBarChangeListener(this); txtXTranslate = (TextView)findViewById(R.id.txtXSkew); txtYTranslate = (TextView)findViewById(R.id.txtYSkew); seekbarZTranslate = (SeekBar)findViewById(R.id.seekbarZTranslate); seekbarZTranslate.setOnSeekBarChangeListener(this); txtZTranslate = (TextView)findViewById(R.id.txtZTranslate); imgResult = (ImageView)findViewById(R.id.imgResult); refreshImage(); BitmapDrawable tmpbitDra = (BitmapDrawable)getResources().getDrawable(R.drawable.img); Bitmap tmpBip = tmpbitDra.getBitmap(); dx = tmpBip.getWidth()/2; dy = tmpBip.getHeight()/2; } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_progress, menu); return true; }@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stubif (seekBar == seekbarXRotate) {txtXRotate.setText(progress + "°");rotateX = progress;}else if (seekBar == seekbarYRotate) {txtYRotate.setText(progress + "゜");rotateY = progress;}else if (seekBar == seekbarZRotate) {txtZRotate.setText(progress + "゜");rotateZ = progress;}else if (seekBar == seekbarXSkew) {skewX = (progress - 100)*1.0f/100;txtXTranslate.setText(String.valueOf(skewX));}else if (seekBar == seekbarYSkew) {skewY = (progress - 100)*1.0f/100;txtYTranslate.setText(String.valueOf(skewY));}else if (seekBar == seekbarZTranslate) {translateZ = progress - 100;txtZTranslate.setText(String.valueOf(translateZ));}refreshImage();}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub} public void refreshImage() {//开始获得待处理的图像 BitmapDrawable tmpBitDra = (BitmapDrawable)getResources().getDrawable(R.drawable.img); Bitmap tmpbit = tmpBitDra.getBitmap(); camera.save(); Matrix matrix = new Matrix(); camera.rotateX(rotateX); camera.rotateY(rotateY); camera.rotateZ(rotateZ); camera.translate(dx, dy, translateZ); camera.getMatrix(matrix); //恢复之前的初始状态。 camera.restore(); matrix.preSkew(skewX, skewY); Bitmap newBitmap = null; try {newBitmap = Bitmap.createBitmap(tmpbit, 0, 0, tmpbit.getWidth(), tmpbit.getHeight(), matrix, true);} catch (Exception e) {// TODO: handle exceptione.printStackTrace();newBitmap = null;} if (newBitmap != null) {imgResult.setImageBitmap(newBitmap);}}}
布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#061D3F" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="XYZ轴旋转( 单位:角度; 范围:0°~360° )" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="X轴" /> <SeekBar android:id="@+id/seekbarXRotate" android:layout_width="200dp" android:layout_height="wrap_content" android:max="360" /> <TextView android:id="@+id/txtXRotate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Y轴" /> <SeekBar android:id="@+id/seekbarYRotate" android:layout_width="200dp" android:layout_height="wrap_content" android:max="360" /> <TextView android:id="@+id/txtYRotate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Z轴" /> <SeekBar android:id="@+id/seekbarZRotate" android:layout_width="200dp" android:layout_height="wrap_content" android:max="360" /> <TextView android:id="@+id/txtZRotate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" /> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="XY轴倾斜" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="X轴" /> <SeekBar android:id="@+id/seekbarXSkew" android:layout_width="200dp" android:layout_height="wrap_content" android:progress="100" android:max="200" /> <TextView android:id="@+id/txtXSkew" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Y轴" /> <SeekBar android:id="@+id/seekbarYSkew" android:layout_width="200dp" android:layout_height="wrap_content" android:progress="100" android:max="200" /> <TextView android:id="@+id/txtYSkew" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" /> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Z轴缩放" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Z轴" /> <SeekBar android:id="@+id/seekbarZTranslate" android:layout_width="200dp" android:layout_height="wrap_content" android:progress="100" android:max="200" /> <TextView android:id="@+id/txtZTranslate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/img" /> <ImageView android:id="@+id/imgResult" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout></LinearLayout>
工程文件:http://download.csdn.net/detail/zhaoshiqing7/4630392
- android.graphics.Camera实现图像的旋转、缩放,配合Matrix...
- [Android]android.graphics.Camera实现图像的旋转、缩放,配合Matrix实现图像的倾斜
- [Android]android.graphics.Camera实现图像的旋转、缩放,配合Matrix实现图像的倾斜
- android.graphics.Camera实现图像的旋转、缩放,配合Matrix实现图像的倾斜
- android.graphics.Camera实现图像的旋转、缩放,配合Matrix实现图像的倾斜
- android.graphics.Camera实现图像的旋转、缩放
- android.graphics.Camera实现图像的旋转、缩放
- android.graphics.Camera实现图像的旋转、缩放
- android.graphics.Camera实现图像的旋转、缩放
- Android 图片处理之-->android.graphics.Camera实现图像的旋转、缩放
- android.graphics包下的Matrix 和Camera
- android旋转图像Matrix
- matlab实现图像的平移、旋转、缩放
- matlab实现图像的平移、旋转、缩放
- Matlab 实现图像的平移,旋转,缩放
- Android中利用Matrix实现图片平移、缩放和旋转
- Android 利用Matrix实现图片随手指平移、旋转、缩放
- Android 利用Matrix实现图片随手指平移、旋转、缩放
- lisp之平方根
- Cookie和Session的区别详解
- hdu 1166 敌兵布阵 (线段树 单点更新 区间求和)
- 支付宝接口程序、文档及解读(ASP.NET)
- MySQL技术内幕:InnoDB存储引擎读书笔记(上)
- android.graphics.Camera实现图像的旋转、缩放,配合Matrix...
- 断想
- thrift之compiler源码详解-总结
- Dos Console test...........(1)
- 面试项目阅览下载
- MySQL技术内幕:InnoDB存储引擎读书笔记(中)
- select 之 top 字句
- 基数排序
- 一些比较重要的算法