
ziyiwangchen05-24 15:26
等级
2楼
当时我们用三星手机照出来相片也是旋转的,用得这个方法,不知道和你们用的一样不一样三星手机相片存储位置,我先贴出来你看看。
/**
*图片按比例大小压缩方法(根据路径获取图片并压缩):
*
*@paramsrcPath
*@return
*/
publicstaticbyte[]getImageBytes(StringsrcPath){
BitmapFactory.OptionsnewOpts=newBitmapFactory.Options();
//开始读入图片,此时把options.inJustDecodeBounds设回true了
newOpts.inJustDecodeBounds=true;
Bitmapbitmap=BitmapFactory.decodeFile(srcPath,newOpts);//此时返回bm为空
newOpts.inJustDecodeBounds=false;
intw=newOpts.outWidth;
inth=newOpts.outHeight;
//设置固定分辨率三星手机相片存储位置,所以高和宽我们设置为

floathh=800f;//这里设置高度为800f
floatww=600f;//这里设置宽度为480f
//缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
intbe=1;//be=1表示不缩放
if(w>h&&w>ww){//如果宽度大的话根据宽度固定大小缩放
be=(int)(newOpts.outWidth/ww);
在该界面中可以设置该窗口是否采用固定的宽度和高度(填入的数字代表像素数,如800*600),窗口的大小就不会随着游戏的分辨率的改变而改变了,将“固定宽度”和“固定高度”设置成 0 便可以设置不使用固定的窗口大小了。在该界面中可以设置该窗口是否采用固定的宽度和高度(填入的数字代表像素数,如800*600),这样,窗口的大小就不会随着游戏的分辨率的改变而改变了,将“固定宽度”和“固定高度”设置成 0 便可以设置不使用固定的窗口大小了。用a4的宽度除以八, 得到水平宽度, 高度除以九, 得到垂直高度,使用矩形选框工具,固定大小(即得到的高度和宽度.)。
be=(int)(newOpts.outHeight/hh);
}elseif(w==h){//如果高度高的话根据宽度固定大小缩放
be=(int)(newOpts.outHeight/hh);
}
if(be<=0)
be=1;
newOpts.inSampleSize=be;//设置缩放比例
//重新读入图片,注意此时已经把options.inJustDecodeBounds设回false了
bitmap=BitmapFactory.decodeFile(srcPath,newOpts);
intdegree=readPictureDegree(srcPath);
BitmapnewBitmap=rotatingImageView(degree,bitmap);

bytearrayoutputstream arrayoutputstream = newbytearrayoutputstream()。bytearrayoutputstreamostream=newbytearrayoutputstream()。 //fill bytearrayoutputstream outstream = newbytearrayoutputstream()。
newBitmap.compress(Bitmap.CompressFormat.JPEG,100,baos);
if(newBitmap!=null){
newBitmap.recycle();
System.gc();
}
returnbaos.toByteArray();//压缩好比例大小后再进行质量压缩
}
/**
*获取图片旋转的角度
*
*@parampath图片的路径
*@return返回旋转的角度值
*/
publicstaticintreadPictureDegree(Stringpath){
intdegree=0;
try{
ExifInterfaceexifInterface=newExifInterface(path);

intorientation=exifInterface.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch(orientation){
caseExifInterface.ORIENTATION_ROTATE_90:
degree=90;
break;
caseExifInterface.ORIENTATION_ROTATE_180:
degree=180;
break;
caseExifInterface.ORIENTATION_ROTATE_270:
degree=270;
break;
}
}catch(IOExceptione){
e.printStackTrace();
}
returndegree;

}
/*
*旋转图片
*
*@paramangle图片旋转的角度
*
*@parambitmap
*/
因为 ew=41 mm, tw=8 mm,所以,nt2 2 2 =89.57 n/mm if(angle==0) returnbitmap; //旋转图片动作 Matrixmatrix=newMatrix(); matrix.postRotate(angle); //创建新的图片 BitmapresizedBitmap=null; if(bitmap!=null){ resizedBitmap=Bitmap.createBitmap(bitmap,0,0, bitmap.getWidth(),bitmap.getHeight(),matrix,true); } returnresizedBitmap; }
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/sanxing/article-114473-1.html
绝不手软