如果你有一个开放的,你需要的位图,你可能做到这一点
If you have a Uri and you need the Bitmap, you "could" do this
Bitmap troublinglyLargeBmp =
MediaStore.Images.Media.getBitmap(
State.mainActivity.getContentResolver(), theUri );
但它会崩溃每次,
but it will crash every time,
让你做到这一点.........
so you do this .........
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
AssetFileDescriptor fileDescriptor =null;
fileDescriptor =
State.mainActivity.getContentResolver().openAssetFileDescriptor( theUri, "r");
Bitmap actuallyUsableBitmap
= BitmapFactory.decodeFileDescriptor(
fileDescriptor.getFileDescriptor(), null, options);
Utils.Log("'4-sample' method bitmap ... "
+actuallyUsableBitmap.getWidth() +" "
+actuallyUsableBitmap.getHeight() );
这是梦幻般的,然后是工作的解决方案。
that's fantastic and is the working solution.
的通知四个一这往往因素很好地工作,在目前的条件下(2014年),具有典型的摄像头规格等。
Notice the factor of "four" which tends to work well, in current conditions (2014) with typical camera sizes, etc.
不过,这将是最好的猜测或学习的图像数据完全相同的尺寸为theUri
,然后利用这些信息,明智选择系数
and then using that information, intelligently choose that factor.
因此,因子可能只有2或甚至1,如果由于某种原因,该文件是非常小的。在另一方面,troublingly,太快了(说2015年车型年),你就需要有6个甚至8。
So, the factor might be only 2 or even 1 if for some reason the file is very small. On the other hand, troublingly, quite soon (say 2015 model year) you would need to have 6 or even 8.
总之,如何正确地选择比例系数时,加载一个URI?
In short, how to correctly choose that scale factor when you load a Uri ?
例如,你能简单地得到某种方式的磁盘上的文件的大小(比如,39.3兆字节),然后从那里(我猜?)采取刺在最好的比例因子?
For example, can you simply get the "size of the file on disk" somehow (say, "39.3 megabytes") and then from there (I guess?) take a stab at the best scaling factor?
Android的专家介绍,这是一个众所周知的问题,有没有解决方案?感谢您的iOS-> Android的朋友! :)
Android experts, is this a well-known problem, is there a solution? Thanks from your iOS->Android friends! :)
看到Android指导处理大量位图的。
See the Android guide to handling large bitmaps.
具体本节:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
String imageType = options.outMimeType;
修改
在你的情况,你会替换为德codeResource
行:
In your case, you'll replace the decodeResource
line with:
BitmapFactory.decodeFileDescriptor(fileDescriptor.getFileDescriptor(), null, options);
上一篇:System.EnterpriseServices.RegistrationHelper不释放文件文件、System、EnterpriseServices、RegistrationHelper
下一篇:测试失败之后居preSSO 2升级(失败:仪器仪表运行失败,原因是“java.lang.IllegalAccessError”)仪器仪表、原因、测试、preSSO