Bitmap getWidth - 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 getWidth method.

This code example shows how to use the following methods:getHeight, getWidth
    @Override 
    public void draw(Canvas canvas) {
        if (mNeedRebuild) {
 
            if (mMapPin == null) {
                mMapPin = Bitmap.createBitmap(mBase.getWidth(), mBase.getHeight(), Bitmap.Config.ARGB_8888);
            } 
            Canvas c = new Canvas(mMapPin);
            c.drawRect(0, 0, mMapPin.getWidth(), mMapPin.getHeight(), sClearerPaint);
 
            // 1 - Draw the base 
            c.drawBitmap(mBase, 0, 0, null);
            // 2 - Draw the pin on top of it 
            mPaint.setColorFilter(new LightingColorFilter(Color.BLACK, mCurrentPinColor));
            c.drawBitmap(mPin, 0, 0, mPaint);
            // 3 - Draw the dot on top of everything 
            mPaint.setColorFilter(new LightingColorFilter(Color.BLACK, mCurrentDotColor));
            c.drawBitmap(mDot, 0, 0, mPaint);
 
            mNeedRebuild = false;
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:copyPixelsToBuffer, getHeight, getRowBytes, getWidth
        } 
        return bmp;
    } 
     
    private static void compareImages(Bitmap bmp1, Bitmap bmp2) {
        assertTrue(bmp1.getHeight() == bmp2.getHeight());
        assertTrue(bmp1.getWidth() == bmp1.getWidth());
        ByteBuffer buffer1 = ByteBuffer.allocate(bmp1.getHeight() * bmp1.getRowBytes());
        bmp1.copyPixelsToBuffer(buffer1);
 
        ByteBuffer buffer2 = ByteBuffer.allocate(bmp2.getHeight() * bmp2.getRowBytes());
        bmp2.copyPixelsToBuffer(buffer2);
 
        assertTrue(Arrays.equals(buffer1.array(), buffer2.array()));
    } 
 
    private Context safeGetContext() {
        for (;;) { 
            if ((getContext() != null) && (getContext().getApplicationContext() != null)) {
                return getContext();
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getHeight, getWidth
        mHighlightColor = highlightColor;
 
        mBitmap = Bitmap.createBitmap(mSize, mSize, Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(mBitmap);
 
        final int width = bitmap.getWidth();
        final int height = bitmap.getHeight();
        final int square = Math.min(width, height);
 
        final Rect cropRect = new Rect((width - square) / 2, (height - square) / 2, square, square);
        final RectF circleRect = new RectF(0f, 0f, mSize, mSize);
        circleRect.inset(mStrokeWidth / 2f, mStrokeWidth / 2f);
        circleRect.inset(mShadowRadius, mShadowRadius);
 
        final Path fillPath = new Path();
        fillPath.addArc(circleRect, 0f, 360f);
 
        canvas.drawColor(0, PorterDuff.Mode.CLEAR);
 
        // opaque circle matte 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getHeight, getWidth, recycle
     * @param source 
     * @param radius 
     * @return rounded corner bitmap 
     */ 
    public static Bitmap roundCorners(final Bitmap source, final float radius) {
        int width = source.getWidth();
        int height = source.getHeight();
 
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(WHITE);
 
        Bitmap clipped = Bitmap.createBitmap(width, height, ARGB_8888);
        Canvas canvas = new Canvas(clipped);
        canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius,
                paint);
        paint.setXfermode(new PorterDuffXfermode(DST_IN));
 
        Bitmap rounded = Bitmap.createBitmap(width, height, ARGB_8888);
        canvas = new Canvas(rounded);

9
CodeRank
Connect your IDE to all the code out there  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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:createScaledBitmap, getHeight, getWidth
	 * @return Bitmap A new Bitmap object of the same bitmap after scaling. 
	 */ 
	public Bitmap scaleBitmap(Bitmap bitmap) {
		int newWidth = this.targetWidth;
		int newHeight = this.targetHeight;
		int origWidth = bitmap.getWidth();
		int origHeight = bitmap.getHeight();
 
		// If no new width or height were specified return the original bitmap 
		if (newWidth <= 0 && newHeight <= 0) {
			return bitmap;
		} 
		// Only the width was specified 
		else if (newWidth > 0 && newHeight <= 0) {
			newHeight = (newWidth * origHeight) / origWidth;
		} 
		// only the height was specified 
		else if (newWidth <= 0 && newHeight > 0) {
			newWidth = (newHeight * origWidth) / origHeight;
		} 

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:createBitmap, getHeight, getWidth, recycle
    Matrix matrixMirrorY=new Matrix();
 
    matrixMirrorY.setValues(mirrorY);
    matrix.postConcat(matrixMirrorY);
 
    Bitmap mirrored=
        Bitmap.createBitmap(workingCopy, 0, 0, workingCopy.getWidth(),
                            workingCopy.getHeight(), matrix, true);
 
    workingCopy.recycle();
    workingCopy=mirrored;
    data=null;
  } 
 
  void applyFlip() { 
    synchronizeModels(true, false); 
 
    float[] mirrorY= { -1, 0, 0, 0, 1, 0, 0, 0, 1 };
    Matrix matrix=new Matrix();
    Matrix matrixMirrorY=new Matrix();
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getWidth
            canvas.scale(0.3f, 0.3f);
            canvas.drawBitmap(mBitmap1, 0, 0, mBitmapPaint);
            canvas.restore();
 
            canvas.save();
            canvas.translate(mBitmap1.getWidth() * 0.3f + 96.0f, 0.0f);
            canvas.scale(0.3f, 0.3f);
            canvas.drawBitmap(mBitmap2, 0, 0, mBitmapPaint);
            canvas.restore();
        } 
    } 
} 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getHeight, getWidth
    } 
 
    private void setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
        if (bitmap != null) {
            setIntrinsicWidth(bitmap.getWidth());
            setIntrinsicHeight(bitmap.getHeight());
        } 
    } 
 
    /** 
     * Draws the contained bitmap onto the canvas at 0,0 with a default {@code Paint} 
     * 
     * @param canvas the canvas to draw on 
     */ 
    @Implementation 
    public void draw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColorFilter(colorFilter);
        canvas.drawBitmap(realBitmapDrawable.getBitmap(), 0, 0, paint);
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Bitmap getWidth Questions & Answers:

getWidth Method Overview
Returns the bitmap's width
See Code Examples for other Android Bitmap Methods: