Bitmap getConfig - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Bitmap getConfig method.

This code example shows how to use the following methods:getConfig, getHeight, getWidth
	 * new Bitmap using default return statement + original texture coordinates 
	 * are stored into RectF. 
	 */ 
	private Bitmap getTexture(Bitmap bitmap, RectF textureRect) {
		// Bitmap original size. 
		int w = bitmap.getWidth();
		int h = bitmap.getHeight();
		// Bitmap size expanded to next power of two. This is done due to 
		// the requirement on many devices, texture width and height should 
		// be power of two. 
		int newW = getNextHighestPO2(w);
		int newH = getNextHighestPO2(h);
 
		// TODO: Is there another way to create a bigger Bitmap and copy 
		// original Bitmap to it more efficiently? Immutable bitmap anyone? 
		Bitmap bitmapTex = Bitmap.createBitmap(newW, newH, bitmap.getConfig());
		Canvas c = new Canvas(bitmapTex);
		c.drawBitmap(bitmap, 0, 0, null);
 
		// Calculate final texture coordinates. 
		float texX = (float) w / newW;
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConfig, getHeight, getWidth
			try { 
				// As pointed out by kbielenberg, Bitmap.sameAs() was only added in level 12/Android 3.1/Honeycomb MR1 
				Method sameAs = Bitmap.class.getMethod("sameAs", Bitmap.class);
				return (Boolean)sameAs.invoke( expectedBitmap, actualBitmap );
			} catch (Exception e) {
				if( expectedBitmap.getWidth() != actualBitmap.getWidth() ) { return false; }
				if( expectedBitmap.getHeight() != actualBitmap.getHeight() ) { return false; }
				if( expectedBitmap.getConfig() != actualBitmap.getConfig() ) { return false; }
				boolean bitmapsEqual = expectedBitmap.equals(actualBitmap);
				if( !bitmapsEqual ) {
					Log.i(TAG, "Bitmaps are not equal");
				} 
				boolean drawablesEqual = expected.equals(actual);
				if( !drawablesEqual ) {
					Log.i(TAG, "Drawables are not equal");
				} 
				return bitmapsEqual && drawablesEqual;
			} 
		} 
		return false; 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConfig
	// =========================================================== 
	// Methods 
	// =========================================================== 
 
	protected Bitmap swapColor(final Bitmap pBitmap) {
		final Config config = pBitmap.getConfig();
		switch (config) {
			case ARGB_8888:
				return ColorSwapBitmapTextureAtlasSource.swapColorARGB_8888(pBitmap, this.mColorKeyColorARGBPackedInt, this.mTolerance, this.mColorSwapColorARGBPackedInt);
			default: 
				Debug.w("Unexpected " + Bitmap.Config.class.getSimpleName() + ": '" + config + "'.");
				return pBitmap;
		} 
	} 
 
	protected static final Bitmap swapColorARGB_8888(final Bitmap pBitmap, final int pColorKeyColorARGBPackedInt, final int pTolerance, final int pColorSwapColorARGBPackedInt) {
		final int[] pixelsARGB_8888 = GLHelper.getPixelsARGB_8888(pBitmap);
		pBitmap.recycle();
 
		final int keyRed = (pColorKeyColorARGBPackedInt >> Color.ARGB_PACKED_RED_SHIFT) & 0xFF;
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:copyPixelsFromBuffer, copyPixelsToBuffer, getConfig, getHeight, getRowBytes
			// android:name="android.permission.WRITE_EXTERNAL_STORAGE" 
			// into AndroidManifest.xml file 
			RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
 
			// get the width and height of the source bitmap. 
			int width = imgIn.getWidth();
			int height = imgIn.getHeight();
			Config type = imgIn.getConfig();
 
			// Copy the byte to the file 
			// Assume source bitmap loaded using options.inPreferredConfig = 
			// Config.ARGB_8888; 
			FileChannel channel = randomAccessFile.getChannel();
			MappedByteBuffer map = channel.map(MapMode.READ_WRITE, 0,
					imgIn.getRowBytes() * height);
			imgIn.copyPixelsToBuffer(map);
			// recycle the source bitmap, this will be no longer used. 
			imgIn.recycle();
			System.gc();// try to force the bytes from the imgIn to be released
 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConfig, getHeight, getWidth, createFromBitmap
        if (input_image < BITMAP_LOW || input_image > BITMAP_HI) {
            Log.e(TAG, "Invalid slot " + input_image + " for HDR input");
            return; 
        } 
 
        mInBitmapAlloc[input_image] = Allocation.createFromBitmap(mRS, input, 
                                          Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
 
        // Bind our allocations to our script 
        switch (input_image) {
        case BITMAP_LOW:
            mScript.bind_gInputLow(mInBitmapAlloc[BITMAP_LOW]);
            break; 
 
        case BITMAP_MID:
            mScript.bind_gInputMid(mInBitmapAlloc[BITMAP_MID]);
            break; 
 
        case BITMAP_HI:
            mScript.bind_gInputHi(mInBitmapAlloc[BITMAP_HI]);

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:copy, getConfig, recycle
 
	// TODO: This function should not be called directly from 
	// DecodeUtils.requestDecode(...), since we don't have the knowledge 
	// if the bitmap will be uploaded to GL. 
	public static Bitmap ensureGLCompatibleBitmap(final Bitmap bitmap) {
		if (bitmap == null || bitmap.getConfig() != null) return bitmap;
		final Bitmap newBitmap = bitmap.copy(Config.ARGB_8888, false);
		bitmap.recycle();
		return newBitmap;
	} 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConfig, getHeight, getWidth
	} 
 
	public static Bitmap blackWhiteBmp(Bitmap bmp) {
		// black and white 
 
		int width = bmp.getWidth();
		int height = bmp.getHeight();
 
		ColorMatrix matrix = new ColorMatrix();
		float[] src = { 0.308F, 0.609F, 0.082F, 0, 0, 0.308F, 0.609F, 0.082F,
				0, 0, 0.308F, 0.609F, 0.082F, 0, 0, 0, 0, 0, 1, 0 }; 
		matrix.set(src);
		ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
		Paint p = new Paint();
		p.setColorFilter(filter);
		Bitmap colorBmp = Bitmap.createBitmap(width, height, bmp.getConfig());
		Canvas c = new Canvas(colorBmp);
		c.drawBitmap(bmp, 0, 0, p);
		return colorBmp;
	} 
 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConfig, getHeight, getWidth, hasAlpha
package org.ebookdroid.common.bitmaps; 
 
import android.graphics.Bitmap; 
import android.graphics.Canvas; 
 
class BitmapRef extends AbstractBitmapRef { 
 
    private volatile Bitmap bitmap;
 
    BitmapRef(final Bitmap bitmap, final long generation) {
        super(bitmap.getConfig(), bitmap.hasAlpha(), bitmap.getWidth(), bitmap.getHeight(), generation);
        this.bitmap = bitmap;
    } 
 
    @Override 
    public Canvas getCanvas() {
        return new Canvas(bitmap);
    } 
 
    @Override 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConfig
        if (recycle) bitmap.recycle();
        return target;
    } 
 
    private static Bitmap.Config getConfig(Bitmap bitmap) {
        Bitmap.Config config = bitmap.getConfig();
        if (config == null) {
            config = Bitmap.Config.ARGB_8888;
        } 
        return config;
    } 
 
    public static Bitmap resizeDownBySideLength(
            Bitmap bitmap, int maxLength, boolean recycle) {
        int srcWidth = bitmap.getWidth();
        int srcHeight = bitmap.getHeight();
        float scale = Math.min(
                (float) maxLength / srcWidth, (float) maxLength / srcHeight);
        if (scale >= 1.0f) return bitmap;
        return resizeBitmapByScale(bitmap, scale, recycle);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConfig, getHeight, getWidth
				bmp2 = loadBitmap(imageFileUri);
				twoPicked = true;
			} 
 
			if (onePicked && twoPicked) {
				Bitmap drawingBitmap = Bitmap.createBitmap(bmp1.getWidth(),
						bmp1.getHeight(), bmp1.getConfig());
				canvas = new Canvas(drawingBitmap);
				paint = new Paint();
				canvas.drawBitmap(bmp1, 0, 0, paint);
				paint.setXfermode(new PorterDuffXfermode(
						android.graphics.PorterDuff.Mode.MULTIPLY));
				canvas.drawBitmap(bmp2, 0, 0, paint);
 
				compositeImageView.setImageBitmap(drawingBitmap);
			} 
		} 
	} 
 
	private Bitmap loadBitmap(Uri imageFileUri) {
8
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Bitmap getConfig Questions & Answers:

getConfig Method Overview
If the bitmap's internal config is in one of the public formats, return that config, otherwise return null.
See Code Examples for other Android Bitmap Methods: