图片处理小结

1.数码相机照片特别大3m以上,内存吃不消,只显示原图的1/8
通过BitmapFactory.Options 来实现
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inSampleSize = 8;
Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
imv.setImageBitmap(bmp);


2.根据当前屏幕分辨率的大小,加载图片
Display currentDisplay = getWindowManager().getDefaultDisplay();
int dw = currentDisplay.getWidth();
int dh = currentDisplay.getHeight();

BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)dh);
int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)dw);
Log.v("HEIGHTRATIO",""+heightRatio);
Log.v("WIDTHRATIO",""+widthRatio);




3.获取Exif图片信息
/从文件获取exif信息
ExifInterface ei = new ExifInterface(imageFilePath);
String imageDescription = ei.getAttribute("ImageDescription");
if (imageDescription != null)
{
Log.v("EXIF", imageDescription);
}
//把exif信息写到文件:
ExifInterface ei = new ExifInterface(imageFilePath);
ei.setAttribute("ImageDescription","Something New");


4.从gallery获取一个图片
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(“image/*”);


intent.getData() 获取image的uri


Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().??
openInputStream(imageFileUri), null, bmpFactoryOptions);




5.图形缩放
Matrix matrix = new Matrix();
matrix.setValues(new float[] {
     1, 0, 0,
     0, 1, 0,
     0, 0, 1
});
x = 1x + 0y + 0z
y = 0x + 1y + 0z
z = 0x + 0y + 1z

通过canvas.drawBitmap(bmp, matrix, paint);创建bitmap

1.水平缩放0.5
2.垂直拉扯2倍

matrix.setScale(1.5f,1);//水平点放大到1.5f,垂直1





6.图形旋转
Matrix matrix = new Matrix();
matrix.setRotate(15);
canvas.drawBitmap(bmp, matrix, paint);

消除锯齿
paint.setAntiAlias(true);  

指定圆心的旋转

matrix.setRotate(15,bmp.getWidth()/2,bmp.getHeight()/2);


Matrix matrix = new Matrix();
matrix.setRotate(15,bmp.getWidth()/2,bmp.getHeight()/2);
alteredBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(),??
matrix, false);
alteredImageView.setImageBitmap(alteredBitmap);





7.图形平移
setTranslate(1.5f,-10);


8.镜子效果
matrix.setScale(-1, 1);
matrix.postTranslate(bmp.getWidth(),0);



9.倒影效果
matrix.setScale(1, -1);
matrix.postTranslate(0, bmp.getHeight());


10.图像颜色处理
颜色矩阵  ColorMatrix cm = new ColorMatrix();
paint.setColorFilter(new ColorMatrixColorFilter(cm));
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
New Red Value = 1*128 + 0*128 + 0*128 + 0*0 + 0
New Blue Value = 0*128 + 1*128 + 0*128 + 0*0 + 0
New Green Value = 0*128 + 0*128 + 1*128 + 0*0 + 0
New Alpha Value = 0*128 + 0*128 + 0*128 + 1*0 + 0
ColorMatrix cm = new ColorMatrix();
cm.set(new float[] {
2, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0
});
paint.setColorFilter(new ColorMatrixColorFilter(cm));




11.变换图像的亮度
ColorMatrix cm = new ColorMatrix();
float contrast = 2;
cm.set(new float[] {
contrast, 0, 0, 0, 0,
0, contrast, 0, 0, 0,
0, 0, contrast, 0, 0,
0, 0, 0, 1, 0 });
paint.setColorFilter(new ColorMatrixColorFilter(cm));




12.更改图片饱和度
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(.5f);
paint.setColorFilter(new ColorMatrixColorFilter(cm));



13.图片合成
Bitmap drawingBitmap = Bitmap.createBitmap(bmp1.getWidth(),??
bmp1.getHeight(), bmp1.getConfig());
canvas = new Canvas(drawingBitmap);
paint = new Paint();
canvas.drawBitmap(bmp1, 0, 0, paint);
paint.setXfermode(new PorterDuffXfermode(android.graphics.??
PorterDuff.Mode.MULTIPLY));
canvas.drawBitmap(bmp2, 0, 0, paint);




14.按指定path上绘制文字
Paint paint = new Paint();
paint.setColor(Color.GREEN);
paint.setTextSize(20);
paint.setTypeface(Typeface.DEFAULT);
Path p = new Path();
p.moveTo(20, 20);
p.lineTo(100, 150);
p.lineTo(200, 220);
canvas.drawTextOnPath("Hello this is text on a path", p, 0, 0, paint);




































  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值