@Override protected Bitmap onGetBitmap() { if (mBitmap != null) return mBitmap; BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), mResId, options); mBitmap = bitmap; setSize(bitmap.getWidth(), bitmap.getHeight()); byte[] chunkData = bitmap.getNinePatchChunk(); mChunk = chunkData == null ? null : NinePatchChunk.deserialize(bitmap.getNinePatchChunk()); if (mChunk == null) { throw new RuntimeException("invalid nine-patch image: " + mResId); } return bitmap; }
/** * LEGACY METHOD to run older versions of Android Layoutlib. ==== DO NOT CHANGE ==== * * @param graphics2D * @param x * @param y * @param scaledWidth * @param scaledHeight */ public void draw(Graphics2D graphics2D, int x, int y, int scaledWidth, int scaledHeight) { mChunk.draw(mImage, graphics2D, x, y, scaledWidth, scaledHeight, 0, 0); }
private NinePatch(BufferedImage image) { mChunk = NinePatchChunk.create(image); mImage = extractBitmapContent(image); }
/** * LEGACY METHOD to run older versions of Android Layoutlib. ==== DO NOT CHANGE ==== * * @param padding array of left, top, right, bottom padding * @return */ public boolean getPadding(int[] padding) { mChunk.getPadding(padding); return true; }