/** * 根据Drawable Id生成对应的MImage * * @param drawableId * @param width * @param height * @param angle * @return */ private MImage generateMImage(int drawableId, int width, int height, float angle) { BitmapDrawable drawable = (BitmapDrawable) mPicManager.getViewDrawable(drawableId); MImage img = new MImage(drawable); scaleImage(img, width, height); img.setRotation(angle); return img.getDrawingCache(); }
/** * 获得格式为Drawable的图片 * * @param drawableId * @return */ public Drawable getDrawable(int drawableId) { Drawable img = null; try { if (mPublicResources.containsKey(drawableId)) { // 与主题无关的资源不保存在主题资源管理器中 img = getDrawableFromMainPkg(drawableId); } else { img = mPicManager.getViewDrawable(drawableId); } } catch (OutOfMemoryError e) { Log.d("XViewFrame", "Hoops! Out of Memeory"); e.printStackTrace(); OutOfMemoryHandler.handle(); } return img; }
/** * 将图片资源加入资源管理器 * * @param pic */ public void addToPicManager(int drawableId, Drawable drawable) { mPicManager.putViewDrawable(drawableId, drawable); }
/** * 从主题资源管理器查询并获取图片 * * @param drawableId * @return */ public Drawable getDrawableFromPicManager(int drawableId) { return mPicManager.getDrawable(drawableId); }
public void clearResources() { mPicManager.clearDrawable(); System.gc(); }