问题描述
我具有使用可疑行为创建位图的功能,有时会旋转创建的位图,有什么方法可以在将位图发送到服务器之前知道位图是否旋转了?
我测试比率的值,但并非总是问题的根源
private static Bitmap decodeImageFromFiles(String path,Context context) throws FileNotFoundException {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(
context.getContentResolver().openInputStream(Uri.fromFile(new File(path))),null,options);
int height = options.outHeight;
int width = options.outWidth;
float ratio = width / height;
Log.e("TAG","ratio :" + ratio);
int widthLimit = (int) ((MainActivity) context).getimageWidthValue();
if (ratio > 0.0)
options.inSampleSize = calculateInSampleSize(options,widthLimit,(int) (widthLimit / ratio));
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(path,options);
Matrix matrix = new Matrix();
if (ratio >= 1.0) {
Log.e("TAG","image is Rotated !");
matrix.postRotate(90);
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
return rotatedBitmap;
} else return bitmap;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)