当前位置: 编程技术>移动开发
本页文章导读:
▪Matrix放大、缩小跟旋转图片 Matrix放大、缩小和旋转图片
一、放大、缩小图片
private LinearLayout imageLayout;
private ImageView imageView;
private Button bt_big;
private Button bt_small;
private float scaleWidth = 1;
private float scaleHeight = 1;
priv.........
▪ 状态栏通报Notification用法 状态栏通知Notification用法
Notification的简单理解:http://blog.csdn.net/manymore13/article/details/6801471Android 状态栏通知Notification用法:http://www.pocketdigi.com/20100905/89.htmlAndroid Notification 传递参数:http://r.........
▪ gluPerspective跟gluLookAt的关系 gluPerspective和gluLookAt的关系
具体的可以请看:GL学习笔记(2) - 终于搞明白gluPerspective和gluLookAt的关系了
函数原型
gluLookAt(GLdoble eyex,GLdouble eyey,GLdouble eyez,GLdouble centerx,GLdouble centery,GLdouble cent.........
[1]Matrix放大、缩小跟旋转图片
来源: 互联网 发布时间: 2014-02-18
Matrix放大、缩小和旋转图片
一、放大、缩小图片
private LinearLayout imageLayout;
private ImageView imageView;
private Button bt_big;
private Button bt_small;
private float scaleWidth = 1;
private float scaleHeight = 1;
private int id = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.big_small);
imageLayout = (LinearLayout) findViewById(R.id.imageLayout);
imageView = (ImageView) findViewById(R.id.imageView1);
bt_big = (Button) findViewById(R.id.button1);
bt_small = (Button) findViewById(R.id.button2);
bt_big.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
big(imageView);
}
});
bt_small.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
small(imageView);
}
});
}
/* 图片放大的method */
private void big(ImageView mImageView) {
// ImageView对象(iv_photo)必须做如下设置后,才能获取其中的图像
mImageView.setDrawingCacheEnabled(true);
// 获取ImageView中的图像
Bitmap bmp = Bitmap.createBitmap(mImageView.getDrawingCache());
// 从ImaggeView对象(iv_photo)中获取图像后,要记得调用setDrawingCacheEnabled(false)
// 清空画图缓冲区
mImageView.setDrawingCacheEnabled(false);
int bmpWidth = bmp.getWidth();
int bmpHeight = bmp.getHeight();
/* 设定图片放大的比例 */
double scale = 1.25;
/* 计算这次要放大的比例 */
scaleWidth = (float) (scaleWidth * scale);
scaleHeight = (float) (scaleHeight * scale);
/* 产生reSize后的Bitmap对象 */
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizeBmp = Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight,
matrix, true);
if(id == 0){
imageLayout.removeView(mImageView);
}
else{
imageLayout.removeView((ImageView)findViewById(id));
}
id = id + 1;
ImageView imageView = new ImageView(BigAndSmall.this);
imageView.setId(id);
imageView.setImageBitmap(resizeBmp);
imageLayout.addView(imageView);
}
/* 图片缩小的method */
private void small(ImageView mImageView) {
// ImageView对象(iv_photo)必须做如下设置后,才能获取其中的图像
mImageView.setDrawingCacheEnabled(true);
// 获取ImageView中的图像
Bitmap bmp = Bitmap.createBitmap(mImageView.getDrawingCache());
// 从ImaggeView对象(iv_photo)中获取图像后,要记得调用setDrawingCacheEnabled(false)
// 清空画图缓冲区
mImageView.setDrawingCacheEnabled(false);
int bmpWidth = bmp.getWidth();
int bmpHeight = bmp.getHeight();
/* 设定图片放大的比例 */
double scale = 0.8;
/* 计算这次要放大的比例 */
scaleWidth = (float) (scaleWidth * scale);
scaleHeight = (float) (scaleHeight * scale);
/* 产生reSize后的Bitmap对象 */
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizeBmp = Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight,
matrix, true);
if(id == 0){
imageLayout.removeView(mImageView);
}
else{
imageLayout.removeView((ImageView)findViewById(id));
}
id = id + 1;
ImageView imageView = new ImageView(BigAndSmall.this);
imageView.setId(id);
imageView.setImageBitmap(resizeBmp);
imageLayout.addView(imageView);
}
big_small.xml
<?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:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/imageLayout"> <ImageView android:layout_width="wrap_content" android:src="/blog_article/@drawable/img2/index.html" android:layout_height="wrap_content" android:id="@+id/imageView1"></ImageView> </LinearLayout> <Button android:text="放大" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> <Button android:text="缩小" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> </LinearLayout>
二、旋转图片
private ImageView imageView;
private Button bt_left;
private Button bt_right;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rotate);
imageView = (ImageView) findViewById(R.id.imageView1);
bt_left = (Button) findViewById(R.id.button1);
bt_right = (Button) findViewById(R.id.button2);
bt_left.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
rotate(imageView , 90);
}
});
bt_right.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
rotate(imageView , -90);
}
});
}
public void rotate(ImageView imageView, int scaleAngle) {
Bitmap bitmap = getBitmapFromImage(imageView);
int widthOrig = bitmap.getWidth();
int heightOrig = bitmap.getHeight();
/* ScaleTimes=1,维持1:1的宽高比例 */
int scaleTimes = 1;
int newWidth = widthOrig * scaleTimes;
int newHeight = heightOrig * scaleTimes;
/* 计算旋转的Matrix比例 */
float scaleWidth = ((float) newWidth) / widthOrig;
float scaleHeight = ((float) newHeight) / heightOrig;
Matrix matrix = new Matrix();
/* 使用Matrix.postScale设定维度 */
matrix.postScale(scaleWidth, scaleHeight);
/* 使用Matrix.postRotate方法旋转Bitmap */
// matrix.postRotate(5*ScaleAngle);
matrix.setRotate(5 * scaleAngle);
/* 建立新的Bitmap对象 */
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, widthOrig,
heightOrig, matrix, true);
BitmapDrawable myNewBitmapDrawable = new BitmapDrawable(resizedBitmap);
imageView.setImageDrawable(myNewBitmapDrawable);
}
public Bitmap getBitmapFromImage(ImageView mImageView) {
// ImageView对象(iv_photo)必须做如下设置后,才能获取其中的图像
mImageView.setDrawingCacheEnabled(true);
// 获取ImageView中的图像
Bitmap bmp = Bitmap.createBitmap(mImageView.getDrawingCache());
// 从ImaggeView对象(iv_photo)中获取图像后,要记得调用setDrawingCacheEnabled(false)
// 清空画图缓冲区
mImageView.setDrawingCacheEnabled(false);
return bmp;
}
[2] 状态栏通报Notification用法
来源: 互联网 发布时间: 2014-02-18
状态栏通知Notification用法
Notification的简单理解:http://blog.csdn.net/manymore13/article/details/6801471
Android 状态栏通知Notification用法:http://www.pocketdigi.com/20100905/89.html
Android Notification 传递参数:http://renzhen.iteye.com/blog/1176746
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pandy.notifi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".NotificationDemoActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Notification的简单理解:http://blog.csdn.net/manymore13/article/details/6801471
Android 状态栏通知Notification用法:http://www.pocketdigi.com/20100905/89.html
Android Notification 传递参数:http://renzhen.iteye.com/blog/1176746
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pandy.notifi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".NotificationDemoActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?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:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示Notification" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="删除Notification" />
</LinearLayout>package com.pandy.notifi;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class NotificationDemoActivity extends Activity {
/** Called when the activity is first created. */
private Button button1, button2;
NotificationManager nm;
int notification_id=19172439;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Notification nf = new Notification(R.drawable.ic_launcher,"我就是发个通知到状态栏来显示而已.",System.currentTimeMillis());
//后面的参数分别是显示在顶部通知栏的小图标,小图标旁的文字(短暂显示,自动消失)系统当前时间(不明白这个有什么用)
nf.defaults=Notification.DEFAULT_ALL;
//这是设置通知是否同时播放声音或振动,声音为Notification.DEFAULT_SOUND
//振动为Notification.DEFAULT_VIBRATE;
//Light为Notification.DEFAULT_LIGHTS,在我的Milestone上好像没什么反应
//全部为Notification.DEFAULT_ALL
//如果是振动或者全部,必须在AndroidManifest.xml加入振动权限
PendingIntent pt=PendingIntent.getActivity(NotificationDemoActivity.this, 0, new Intent(NotificationDemoActivity.this,NotificationDemoActivity.class), 0);
//点击通知后的动作,这里是转回main 这个Acticity
//往下拖动后,看见列表里面的内容
nf.setLatestEventInfo(NotificationDemoActivity.this,"往下拖动后的列表标题","点击查看内容",pt);
nm.notify(notification_id, nf);
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//取消状态栏的通知
nm.cancel(notification_id);
}
});
}
}
[3] gluPerspective跟gluLookAt的关系
来源: 互联网 发布时间: 2014-02-18
gluPerspective和gluLookAt的关系
具体的可以请看:GL学习笔记(2) - 终于搞明白gluPerspective和gluLookAt的关系了
函数原型
gluLookAt(GLdoble eyex,GLdouble eyey,GLdouble eyez,GLdouble centerx,GLdouble centery,GLdouble centerz,GLdouble upx,GLdouble upy,GLdouble upz); gluPerspective(GLdouble fovy,GLdouble aspect,GLdouble zNear,GLdouble zFar)
我的理解:
拿拍照来看:
一:gluPerspective相当于调整照相机与景物的距离
1. 如果想把物体拍全,把景物都拍进去,就要远离物体(即调整zNear的值)
二:gluLookAt相当于调整相机的焦距
1. 如果想拍全景物,就要把焦距调小,等于是减小放大倍数(即调整center与eye之间的距离)
2. 如果想拍倒立的景物,只要把相机反过来就行(即调整up的向量的方向)
总结:所以这个方法的调整是相互作用的,要结合起来调整。另外,如果想模拟人眼,那视角就要小于45度,只有这样成的像,才不会变形。
最新技术文章: