下面列出了android.content.res.Resources#openRawResourceFd() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void getImgInfo(Result successResult, Resources res, int resId) {
HashMap map = new HashMap();
map.put("resId", resId);
try {
if (resId != 0) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
AssetFileDescriptor af = res.openRawResourceFd(resId);
map.put("size", af.getLength());
af.close();
InputStream is = res.openRawResource(resId);
BitmapFactory.decodeStream(is, null, options);
is.close();
map.put("width", options.outWidth);
map.put("height", options.outHeight);
} else {
map.put("error", "resources doesn't exist");
}
successResult.success(map);
} catch (Exception e) {
map.put("error", e.getMessage());
successResult.success(map);
}
}
/**
* Creates drawable from resource.
*
* @param res Resources to read from
* @param id resource id (raw or drawable)
* @throws NotFoundException if the given ID does not exist.
* @throws IOException when opening failed
* @throws NullPointerException if res is null
*/
public GifDrawable(@NonNull Resources res, @RawRes @DrawableRes int id) throws NotFoundException, IOException {
this(res.openRawResourceFd(id));
final float densityScale = GifViewUtils.getDensityScale(res, id);
mScaledHeight = (int) (mNativeInfoHandle.getHeight() * densityScale);
mScaledWidth = (int) (mNativeInfoHandle.getWidth() * densityScale);
}
/**
* Retrieves from resource.
*
* @param res Resources to read from
* @param id resource id
* @throws android.content.res.Resources.NotFoundException if the given ID does not exist.
* @throws java.io.IOException when opening failed
* @throws NullPointerException if res is null
*/
public GifAnimationMetaData(@NonNull Resources res, @DrawableRes @RawRes int id) throws Resources.NotFoundException, IOException {
this(res.openRawResourceFd(id));
}
/**
* Creates drawable from resource.
*
* @param res Resources to read from
* @param id resource id (raw or drawable)
* @throws NotFoundException if the given ID does not exist.
* @throws IOException when opening failed
* @throws NullPointerException if res is null
*/
public GifDrawable(@NonNull Resources res, @DrawableRes @RawRes int id) throws NotFoundException, IOException {
this(res.openRawResourceFd(id));
}
/**
* Creates drawable from resource.
*
* @param res Resources to read from
* @param id resource id
* @throws NotFoundException if the given ID does not exist.
* @throws IOException when opening failed
* @throws NullPointerException if res is null
*/
public GifDrawable(Resources res, int id) throws NotFoundException, IOException {
this(res.openRawResourceFd(id));
}
/**
* Retrieves from resource.
*
* @param res Resources to read from
* @param id resource id
* @throws android.content.res.Resources.NotFoundException if the given ID does not exist.
* @throws java.io.IOException when opening failed
* @throws NullPointerException if res is null
*/
public GifAnimationMetaData(@NonNull Resources res, @RawRes @DrawableRes int id) throws Resources.NotFoundException, IOException {
this(res.openRawResourceFd(id));
}
/**
* Creates drawable from resource.
* @param res Resources to read from
* @param id resource id
* @throws android.content.res.Resources.NotFoundException if the given ID does not exist.
* @throws java.io.IOException when opening failed
* @throws NullPointerException if res is null
*/
public GifDrawable ( Resources res, int id ) throws NotFoundException, IOException
{
this( res.openRawResourceFd( id ) );
}