Android图形处理专题

Load图形到内存

1.数码相机照片特别大3m以上,内存吃不消,只显示原图的1/8

通过BitmapFactory.Options 来实现

BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();

bmpFactoryOptions.inSampleSize = 8;

Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);

imv.setImageBitmap(bmp);


Load图形到内存

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);


Load图形到内存2

//判断是否要进行缩放

if (heightRatio > 1 && widthRatio > 1)

{

if (heightRatio > widthRatio)

{

//高度变化大,按高度缩放

bmpFactoryOptions.inSampleSize = heightRatio;

}

else

{

// 宽度变化大,按宽度缩放

bmpFactoryOptions.inSampleSize = widthRatio;

}

}

bmpFactoryOptions.inJustDecodeBounds = false;

bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);


获取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");


从gallery获取一个图片

Intent intent = new Intent(Intent.ACTION_PICK);

intent.setType(“image/*”);

intent.getData() 获取image的uri

Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().?

openInputStream(imageFileUri), null, bmpFactoryOptions);

创建bitmap拷贝

Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().?

openInputStream(imageFileUri), null, bmpFactoryOptions);

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.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

图形旋转

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);

图形平移

setTranslate(1.5f,-10);

镜子效果

matrix.setScale(-1, 1);

matrix.postTranslate(bmp.getWidth(),0);

倒影效果

matrix.setScale(1, -1);

matrix.postTranslate(0, bmp.getHeight());

图像颜色处理

颜色矩阵  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));

变换图像的亮度

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));

更改图片饱和度

ColorMatrix cm = new ColorMatrix();

cm.setSaturation(.5f);

paint.setColorFilter(new ColorMatrixColorFilter(cm));

图片合成

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);

按指定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);

图片编辑画画板

人脸识别

 FaceDetector detector = new FaceDetector(faceBitmap.getWidth(),

    faceBitmap.getHeight(), 3); // 创建识别器

 mNumFaces = detector.findFaces(faceBitmap, mFaces);    

    // 识别

  if (mNumFaces > 0) {

         for (int i = 0; i < mNumFaces; i++) {

         handleFace(mFaces[i]);      

  // 调用函数对人脸画面进行处理

                                }

            }

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

热门产品

php编程基础教程.pptx|php编程培训,php,编程,基础,教程,pptx
php编程基础教程.pptx

历史上的今天:04月29日

热门专题

APP开发|app开发_app开发公司_app软件开发_专业app开发_云南app开发公司_app定制_原生app开发定制
APP开发
云南高职单招|云南单招,云南单招网,云南高职单招网,云南高职单招,云南单招学校,云南单招培训
云南高职单招
自考本科|自考本科有用吗,自考文凭,自考本科文凭,自考文凭有用吗,自考本科文凭有用吗,自考文凭承认吗
自考本科
小程序开发|微信小程序,小程序开发,小程序,小程序制作,微信小程序开发,小程序公司,小程序开发公司,分销,三级分销系统,分销系统
小程序开发
安徽中源管业有限公司|安徽中源管业有限公司,安徽中源管业有限公司介绍,安徽中源管业有限公司电话,安徽中源管业有限公司地址,安徽中源管业有限公司厂家,安徽中源管业有限公司电力管,安徽中源管业有限公司管材
安徽中源管业有限公司
昆明综合高中|昆明综合高中
昆明综合高中
一年制中专|中专学历,中专是什么学历,中专是什么,中专有什么专业,中专升大专,一年制中专
一年制中专
开放大学|开放大学报名,开放大学报考,开放大学,什么是开放大学,开放大学学历,开放大学学费,开放大学报名条件,开放大学报名时间,开放大学学历,开放大学专业
开放大学

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部