资源描述:
《android中图片处理(压缩 显示 保存)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、packagecom.xikang.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;importand
2、roid.content.ContentResolver;importandroid.database.Cursor;importandroid.graphics.Bitmap;importandroid.graphics.BitmapFactory;importandroid.graphics.BitmapFactory.Options;importandroid.graphics.Matrix;importandroid.net.Uri;importandroid.provider.MediaStore;importand
3、roid.util.FloatMath;importandroid.util.Log;importandroid.widget.ImageView;importandroid.widget.Toast;publicclassImageUtils{privatestaticfinalStringTAG="ImageUtils";publicstaticvoidloadImage(Activityactivity,ImageViewimageView,Uriuri){if(Conf.INFO)Log.i(TAG,"loadImag
4、e:localuri="+uri);if(uri!=null&&!uri.toString().startsWith("content://")){return;}try{//MediaStoreString[]pojo={MediaStore.Images.Media.DATA};Cursorcursor=activity.managedQuery(uri,pojo,null,null,null);if(cursor!=null&&cursor.moveToFirst()){ContentResolvercr=activit
5、y.getContentResolver();intcolunm_index=cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);Stringpath=cursor.getString(colunm_index);if(Conf.INFO)Log.i(TAG,"loadImage:path="+path);if(path.endsWith(".jpg")
6、
7、path.endsWith(".png")){Bitmapbitmap=BitmapFactory.dec
8、odeStream(cr.openInputStream(uri));//imageView.setImageBitmap(getBitmap(path,100,200));imageView.setImageBitmap(getCompredBitmap(path));}else{Toast.makeText(activity,"Pleaseselectimage...",Toast.LENGTH_SHORT).show();}}}catch(Exceptione){e.printStackTrace();}}publics
9、taticBitmapgetCompredBitmap(StringsrcPath){returncompressDef(getResizeBitmap(srcPath));}/***getbitmapcompressedto100kb*@parambitmap*@return*/publicstaticBitmapgetCompredDefBitmap(Bitmapbitmap){returngetCompredBitmap(bitmap,100);}/***getbitmapcompressed*@parambitmap*
10、@paramtarget_sizeunitiskb*@return*/publicstaticBitmapgetCompredBitmap(Bitmapbitmap,inttarget_size){returncompress(bitmap,target_size);}pri