Java Code Examples for android.graphics.NinePatch#isNinePatchChunk()

The following examples show how to use android.graphics.NinePatch#isNinePatchChunk() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackGroudSeletor.java    From FloatBall with Apache License 2.0 6 votes vote down vote up
/**
 * 获取asset下面的.9 png
 *
 * @param imagename 图片名
 * @param context   上下文对象
 */
public static NinePatchDrawable get9png(String imagename, Context context) {
    Bitmap toast_bitmap;
    try {
        toast_bitmap = BitmapFactory.decodeStream(context.getAssets().open("image/" + imagename + ".9.png"));
        byte[] temp = toast_bitmap.getNinePatchChunk();
        boolean is_nine = NinePatch.isNinePatchChunk(temp);
        if (is_nine) {
            NinePatchDrawable nine_draw = new NinePatchDrawable(context.getResources(), toast_bitmap, temp, new Rect(), null);
            return nine_draw;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 2
Source File: AuthAgent.java    From letv with Apache License 2.0 5 votes vote down vote up
private Drawable a(String str, Context context) {
    Drawable createFromStream;
    IOException e;
    try {
        InputStream open = context.getApplicationContext().getAssets().open(str);
        if (open == null) {
            return null;
        }
        if (str.endsWith(".9.png")) {
            Bitmap decodeStream = BitmapFactory.decodeStream(open);
            if (decodeStream == null) {
                return null;
            }
            byte[] ninePatchChunk = decodeStream.getNinePatchChunk();
            NinePatch.isNinePatchChunk(ninePatchChunk);
            return new NinePatchDrawable(decodeStream, ninePatchChunk, new Rect(), null);
        }
        createFromStream = Drawable.createFromStream(open, str);
        try {
            open.close();
            return createFromStream;
        } catch (IOException e2) {
            e = e2;
            e.printStackTrace();
            return createFromStream;
        }
    } catch (IOException e3) {
        IOException iOException = e3;
        createFromStream = null;
        e = iOException;
        e.printStackTrace();
        return createFromStream;
    }
}
 
Example 3
Source File: TaskGuide.java    From letv with Apache License 2.0 5 votes vote down vote up
private Drawable a(String str, Context context) {
    Drawable createFromStream;
    IOException e;
    try {
        InputStream open = context.getApplicationContext().getAssets().open(str);
        if (open == null) {
            return null;
        }
        if (str.endsWith(".9.png")) {
            Bitmap decodeStream = BitmapFactory.decodeStream(open);
            if (decodeStream == null) {
                return null;
            }
            byte[] ninePatchChunk = decodeStream.getNinePatchChunk();
            NinePatch.isNinePatchChunk(ninePatchChunk);
            return new NinePatchDrawable(decodeStream, ninePatchChunk, new Rect(), null);
        }
        createFromStream = Drawable.createFromStream(open, str);
        try {
            open.close();
            return createFromStream;
        } catch (IOException e2) {
            e = e2;
            e.printStackTrace();
            return createFromStream;
        }
    } catch (IOException e3) {
        IOException iOException = e3;
        createFromStream = null;
        e = iOException;
        e.printStackTrace();
        return createFromStream;
    }
}
 
Example 4
Source File: Utils.java    From RangeSeekBar with Apache License 2.0 5 votes vote down vote up
public static void drawBitmap(Canvas canvas, Paint paint, Bitmap bmp, Rect rect) {
    try {
        if (NinePatch.isNinePatchChunk(bmp.getNinePatchChunk())) {
            drawNinePath(canvas, bmp, rect);
            return;
        }
    } catch (Exception e) {
    }
    canvas.drawBitmap(bmp, rect.left, rect.top, paint);
}
 
Example 5
Source File: ChatImageView.java    From ChatImageView with MIT License 5 votes vote down vote up
private void init() {
    mMatrix = new Matrix();
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    if (mMaskResId <= 0) {
        return;
    }
    mMaskBmp = BitmapFactory.decodeResource(getResources(), mMaskResId);
    byte[] ninePatchChunk = mMaskBmp.getNinePatchChunk();
    if (ninePatchChunk != null && NinePatch.isNinePatchChunk(ninePatchChunk)) {
        mMaskDrawable = new NinePatchDrawable(getResources(), mMaskBmp, ninePatchChunk, new Rect(), null);
    }
    internalSetImage();
}
 
Example 6
Source File: NinePatchData.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Attempts to decode 9-patch data from a {@link Bitmap}.
 * @param bitmap The {@link Bitmap} to check.
 * @return       An instance of {@link NinePatchData} representing the 9-patch information
 *               encoded in {@code bitmap} or {@code null} if the {@link Bitmap} wasn't a
 *               9-patch.
 */
public static NinePatchData create(Bitmap bitmap) {
    if (bitmap == null) return null;

    try {
        byte[] chunk = bitmap.getNinePatchChunk();
        if (chunk == null || !NinePatch.isNinePatchChunk(chunk)) return null;

        ByteBuffer buffer = ByteBuffer.wrap(chunk).order(ByteOrder.nativeOrder());

        // int8_t wasDeserialized
        if (buffer.get() == 0) return null;

        // int8_t numXDivs
        int numDivX = buffer.get();
        if (numDivX == 0 || (numDivX & 0x01) != 0) return null;

        // int8_t numYDivs
        int numDivY = buffer.get();
        if (numDivY == 0 || (numDivY & 0x01) != 0) return null;

        // int8_t numColors
        buffer.get();

        // uint32_t xDivsOffset
        buffer.getInt();

        // uint32_t yDivsOffset
        buffer.getInt();

        Rect padding = new Rect();

        // uint32_t paddingLeft
        padding.left = buffer.getInt();

        // uint32_t paddingRight
        padding.right = buffer.getInt();

        // uint32_t paddingTop
        padding.top = buffer.getInt();

        // uint32_t paddingBottom
        padding.bottom = buffer.getInt();

        // uint32_t colorsOffset
        buffer.getInt();

        // uint32_t uint32_t uint32_t ...
        int[] divX = new int[numDivX];
        for (int i = 0; i < numDivX; i++) divX[i] = buffer.getInt();

        // uint32_t uint32_t uint32_t ...
        int[] divY = new int[numDivY];
        for (int i = 0; i < numDivY; i++) divY[i] = buffer.getInt();

        return new NinePatchData(bitmap.getWidth(), bitmap.getHeight(), padding, divX, divY);
    } catch (BufferUnderflowException ex) {
        return null;
    }
}
 
Example 7
Source File: Utils.java    From RangeSeekBar with Apache License 2.0 2 votes vote down vote up
/**
 * draw 9Path
 *
 * @param canvas Canvas
 * @param bmp    9path bitmap
 * @param rect   9path rect
 */
public static void drawNinePath(Canvas canvas, Bitmap bmp, Rect rect) {
    NinePatch.isNinePatchChunk(bmp.getNinePatchChunk());
    NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
    patch.draw(canvas, rect);
}