Java Code Examples for android.graphics.Bitmap.getNinePatchChunk()

The following are Jave code examples for showing how to use getNinePatchChunk() of the android.graphics.Bitmap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: letv   File: AuthAgent.java   View Source Code Vote up 5 votes
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 2
Project: letv   File: TaskGuide.java   View Source Code Vote up 5 votes
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
Project: boohee_v5.6   File: AuthAgent.java   View Source Code Vote up 5 votes
private Drawable a(String str, Context context) {
    IOException e;
    Drawable createFromStream;
    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
Project: aos-MediaLib   File: ArtworkFactory.java   View Source Code Vote up 4 votes
public ArtworkFactory( Context context, int width, int height) {

		mContext = context;
		mRes = mContext.getResources();
		mContentResolver =  context.getContentResolver();
		mLayoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		mWidth = width;
		mHeight = height;

        mContentLabelFontsize = mRes.getDimension(R.dimen.ContentLabel_fontsize);

		mBitmapOptions = new BitmapFactory.Options();
		// RGB565 is OK for the artwork, 888 will be needed only when we add the shadow
		// Also no need for dithering. OpenGL will do a good job at displaying it without.
		//TODO: check if using ARGB888 is not faster since it will be converted after anyway
		mBitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;
		mBitmapOptions.inDither = ARTWORK_BITMAP_DITHERING;
		mBitmapOptions.inSampleSize = 1; // no sub-sampling
		mBitmapOptions.inJustDecodeBounds = false;

		// Prepare a painter and enable filtering if showing large bitmaps to avoid ugly rendering of the rescaled bitmap
		mPaint = new Paint();
		mPaint.setFilterBitmap(ARTWORK_BITMAP_FILTERING);
		mPaint.setDither(ARTWORK_BITMAP_DITHERING);

		// ======== Now prepare the shadow stuff =========

		// Create the destination bitmap and associate a canvas to it
		// Require ARGB for the shadow effect
		mShadowBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888 );
		mShadowBitmap.eraseColor(Color.TRANSPARENT);
		mCanvas = new Canvas(mShadowBitmap);

		// Decode the shadow bitmap
		int shadowId = ArchosFeatures.isAndroidTV(mContext)|| ArchosFeatures.isLUDO()?R.drawable.cover_shadow_512:(mWidth==128) ? R.drawable.cover_shadow_128 : R.drawable.cover_shadow_256;
		InputStream is = context.getResources().openRawResource(shadowId);
		mShadow9patchPadding = new Rect();

		// We must use this version of "decode" in order to get the nine-patch padding
		Bitmap shadowNinePatchBitmap = BitmapFactory.decodeStream(is, mShadow9patchPadding, null);
		try {
			is.close();
		} catch (IOException e) {}
		mShadow9patch = new NinePatch(shadowNinePatchBitmap, shadowNinePatchBitmap.getNinePatchChunk(), null);
	}
 
Example 5
Project: xlight_android_native   File: RangeSeekBar.java   View Source Code Vote up 2 votes
/**
 * 绘制 9Path
 * @param c
 * @param bmp
 * @param rect
 */
public void drawNinePath(Canvas c, Bitmap bmp, Rect rect){
    NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
    patch.draw(c, rect);
}