通过内置的图片程序来选择图片
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent,
0);
创建一个空的Bitmap,然后把一个已经存在的Bitmap放进去
/*
* 将原来的bitmap画到新的易变的alteredBitmap对象中
*/
Bitmap alteredBitmap = Bitmap.createBitmap(bmp.getWidth(),
bmp.getHeight(), bmp.getConfig());
Canvas canvas = new
Canvas(alteredBitmap);
Paint paint = new Paint();
canvas.drawBitmap(bmp, 0, 0, paint);
图片缩放和翻转
Matrix matrix = new Matrix();
//matrix.setRotate(15);
matrix.setRotate(15,
bmp.getWidth()/2, bmp.getHeight()/2); //从图片中心点开始旋转
canvas.drawBitmap(bmp, matrix, paint);
matrix.setScale(1.5f, 1);
第一个参数是x轴上的缩放,第二个参数是y轴上的缩放
Translate:图片在x轴或y轴移动
setTranslate方法接收两个参数,分别是x、y轴上的移动
matrix.setTranslate(15, 10);
以上的方法都有pre和post版本,可以使我们在一次时间序列中执行多于一次的变换
matrix.setScale(1.5f, 1.5f);
matrix.postRotate(15, bmp.getWidth()/2,
bmp.getHeight()/2);
实现镜面翻转效果
matrix.setScale(-1, 1);
matrix.postTranslate(bmp.getWidth(),
0);
matrix.setScale(1, -1);
matrix.postTranslate(0,
bmp.getHeight());
//It is initialized with the same density
as the original bitmap.
//变换后的图片与原图片同样大小
Matrix matrix = new Matrix();
matrix.setRotate(15,bmp.getWidth()/2,bmp.getHeight()/2);
Bitmap alteredBitmap = Bitmap.createBitmap(bmp,
0, 0, bmp.getWidth(), bmp.getHeight(), matrix, false);
alteredImageView.setImageBitmap(alteredBitmap);
package com.liang.imageTest;
import java.io.FileNotFoundException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class ChoosePictureActivity1 extends Activity implements OnClickListener{
ImageView choseImageView;
ImageView alteredImageView;
Button choosePicture;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.choosepicture1);
choseImageView = (ImageView)findViewById(R.id.chosenImageView);
alteredImageView = (ImageView)findViewById(R.id.alteredImageView);
choosePicture = (Button)findViewById(R.id.choosePictureButton);
choosePicture.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK){
Uri imageFileUri = data.getData();
Display currentDisplay = getWindowManager().getDefaultDisplay();
int dw = currentDisplay.getWidth();
int dh = currentDisplay.getHeight();
try{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri),
null,options);
/*
* 图片得尺寸比屏幕大小大,按照图片尺寸与屏幕高、宽最大的比例来缩小图片
*/
int heightRatio = (int)Math.ceil(options.outHeight/(float)dh);
int widthRatio = (int)Math.ceil(options.outWidth/(float)dw);
if(heightRatio > 1 && widthRatio > 1){
if(heightRatio > widthRatio)
options.inSampleSize = heightRatio;
else
options.inSampleSize = widthRatio;
}
options.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null, options);
choseImageView.setImageBitmap(bmp);
/*
* 将原来的bitmap画到新的易变的alteredBitmap对象中
*/
Bitmap alteredBitmap = Bitmap.createBitmap(bmp.getWidth()*2, bmp.getHeight()*2, bmp.getConfig());
Canvas canvas = new Canvas(alteredBitmap);
Paint paint = new Paint();
/*
* 1.
*/
// canvas.drawBitmap(bmp, 0, 0, paint);
/*
* 2.旋转
*/
Matrix matrix = new Matrix();
// matrix.setRotate(15);
// matrix.setRotate(15, bmp.getWidth()/2, bmp.getHeight()/2);//从图片中心点开始旋转
/*
* 3.缩放
*/
// matrix.setScale(1.5f, 1);//x轴1.5倍,y轴1倍
/*
* 3-1.翻转
*/
// matrix.setScale(-1, 1);
// matrix.postTranslate(bmp.getWidth(), 0);
/*
* 3-2.翻转
*/
// matrix.setScale(1, -1);
// matrix.postTranslate(0, bmp.getHeight());
/*
* 4.移动
*/
// matrix.setTranslate(15, 10);
/*
* 5.序列
*/
// matrix.setScale(1.5f, 1.5f);
// matrix.postRotate(15, bmp.getWidth()/2, bmp.getHeight()/2);
canvas.drawBitmap(bmp, matrix, paint);
alteredImageView.setImageBitmap(alteredBitmap);
/*
* 图片与原图片大小一样
*/
/*
Matrix matrix = new Matrix();
matrix.setRotate(15,bmp.getWidth()/2,bmp.getHeight()/2);
Bitmap alteredBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, false);
alteredImageView.setImageBitmap(alteredBitmap);
*/
}catch(FileNotFoundException e){
Log.v("ERROR",e.toString());
}
}
}
}
- 大小: 8.3 KB
- 大小: 7.9 KB
- 大小: 8.8 KB
- 大小: 7.5 KB
- 大小: 7.5 KB
- 大小: 8.2 KB
分享到:
相关推荐
Android图片处理效果demo, 圆角,倒影
Android图片处理源码,
android图片处理工具
这个里面是图片处理系列的一个集合demo,里面包含了图片处理系列的所有代码,写的比较乱,没有整理,希望对大家有帮助。
Android图片处理矩阵
android资源参考代码,关于对图片的处理,用代码动态分割图片,使其形成动画
Android图片处理.pdf Android图片处理.pdf
android图片处理(压缩,保存,截屏,view转化为bitmap)相关函数 ImageUtils
android图片处理,缩放、压缩、剪切、水印、黑白、旋转等10多种特效
base64的图片转化工具类,用于Android中的base64格式图片操作。图片转化成base64和base64字符串转化成图片
android图片处理总结,总结了一些关于安装的图片处理方法,欢迎借鉴
加载本地图片,优化图片加载,避免内存移除
本人的博客:android图片处理:让图片一直匀速旋转的demo
NULL 博文链接:https://fonter.iteye.com/blog/753063
图片处理sdk(just for eclipse) Note: 新的项目(for studio)转移到https://github.com/jarlen/PhotoEdit (包括jni本地源码) cn.ffmpeg gif mp4 互转 com.js.photosdk.bodywarp 图片变形 com.js.photosdk.crop ...
android中的图片处理技术。。实现android中的ps效果
Android中图片处理(压缩 显示 保存)
Android中图片处理(放大缩小,去色,转换格式,增加水印等
Android图片处理的一个示例代码