资源描述:
《Android中图片处理(压缩-保存-显示-截屏-视图View转为图片Bitmap)函数工具类.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、示例:voidshareShotScreen(){LinearLayoutlayout=(LinearLayout)findViewById(R.id.plan_layout);Bitmapbitmap=ImageUtils.convertBitmap(layout);Stringpath=ImageUtils.saveImage25(bitmap);ShareUtils.ShareImage(this,"shareplan","slimplan","shareslimplan...........",path);}packagecom.x
2、ikang.android.slimcoach.utils;importjava.io.ByteArrayOutputStream;importjava.io.File;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.IOException;importcom.xikang.android.slimcoach.Conf;importandroid.app.Activity;importandroid.content.Conten
3、tResolver;importandroid.content.Context;importandroid.database.Cursor;importandroid.graphics.Bitmap;importandroid.graphics.BitmapFactory;importandroid.graphics.BitmapFactory.Options;importandroid.graphics.Canvas;importandroid.graphics.Color;importandroid.graphics.Matrix;im
4、portandroid.net.Uri;importandroid.provider.MediaStore;importandroid.text.Layout;importandroid.util.FloatMath;importandroid.util.Log;importandroid.view.Display;importandroid.view.View;importandroid.view.View.MeasureSpec;importandroid.widget.ImageView;importandroid.widget.To
5、ast;publicclassImageUtils{privatestaticfinalStringTAG="ImageUtils";publicstaticBitmaploadImage(Activityactivity,ImageViewimageView,Uriuri){if(Conf.INFO)Log.i(TAG,"loadImage:localuri="+uri);if(uri!=null&&!uri.toString().startsWith("content://")){returnnull;}Bitmapbitmap=nul
6、l;try{//MediaStoreString[]pojo={MediaStore.Images.Media.DATA};Cursorcursor=activity.managedQuery(uri,pojo,null,null,null);if(cursor!=null&&cursor.moveToFirst()){ContentResolvercr=activity.getContentResolver();intcolunm_index=cursor.getColumnIndexOrThrow(MediaStore.Images.M
7、edia.DATA);Stringpath=cursor.getString(colunm_index);if(Conf.INFO)Log.i(TAG,"loadImage:path="+path);if(path.endsWith(".jpg")
8、
9、path.endsWith(".png")){//bitmap=BitmapFactory.decodeStream(cr.openInputStream(uri));bitmap=getCompredBitmap(path);//imageView.setImageBitmap(getBit
10、map(path,100,200));imageView.setImageBitmap(bitmap);}else{Toast.makeText(activity,"Please