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

The following are Jave code examples for showing how to use getHeight() 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: androidscan   File: DecodeUtils.java   View Source Code Vote up 6 votes
public String decodeWithZxing(Bitmap bitmap) {
    MultiFormatReader multiFormatReader = new MultiFormatReader();
    multiFormatReader.setHints(changeZXingDecodeDataMode());

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    Result rawResult = null;
    RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);

    if (source != null) {
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
        try {
            rawResult = multiFormatReader.decodeWithState(binaryBitmap);
        } catch (ReaderException re) {
            // continue
        } finally {
            multiFormatReader.reset();
        }
    }

    return rawResult != null ? rawResult.getText() : null;
}
 
Example 2
Project: Android-Practice   File: ImageCache.java   View Source Code Vote up 6 votes
/**
 * @param candidate - Bitmap to check
 * @param targetOptions - Options that have the out* value populated
 * @return true if <code>candidate</code> can be used for inBitmap re-use with
 *      <code>targetOptions</code>
 */
@TargetApi(VERSION_CODES.KITKAT)
private static boolean canUseForInBitmap(
        Bitmap candidate, BitmapFactory.Options targetOptions) {
    //BEGIN_INCLUDE(can_use_for_inbitmap)
    if (!Utils.hasKitKat()) {
        // On earlier versions, the dimensions must match exactly and the inSampleSize must be 1
        return candidate.getWidth() == targetOptions.outWidth
                && candidate.getHeight() == targetOptions.outHeight
                && targetOptions.inSampleSize == 1;
    }

    // From Android 4.4 (KitKat) onward we can re-use if the byte size of the new bitmap
    // is smaller than the reusable bitmap candidate allocation byte count.
    int width = targetOptions.outWidth / targetOptions.inSampleSize;
    int height = targetOptions.outHeight / targetOptions.inSampleSize;
    int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
    return byteCount <= candidate.getAllocationByteCount();
    //END_INCLUDE(can_use_for_inbitmap)
}
 
Example 3
Project: MyDemo   File: GlideCircleTransform.java   View Source Code Vote up 6 votes
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    // TODO this could be acquired from the pool too
    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
 
Example 4
Project: Bigbang   File: CropImage.java   View Source Code Vote up 6 votes
/**
 * Create a new bitmap that has all pixels beyond the oval shape transparent.
 * Old bitmap is recycled.
 */
public static Bitmap toOvalBitmap(@NonNull Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    int color = 0xff424242;
    Paint paint = new Paint();

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);

    RectF rect = new RectF(0, 0, width, height);
    canvas.drawOval(rect, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, 0, 0, paint);

    bitmap.recycle();

    return output;
}
 
Example 5
Project: GankReader   File: GlideCircleTransform.java   View Source Code Vote up 6 votes
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;

    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    float r = size / 2.0f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
 
Example 6
Project: editor-sql   File: FeThumbUtils.java   View Source Code Vote up 6 votes
public static Bitmap extractThumbnail(Bitmap source, int width, int height,
                                      int options) {
    if (source == null) {
        return null;
    }
    float scale;
    if (source.getWidth() < source.getHeight()) {
        scale = width / (float) source.getWidth();
    } else {
        scale = height / (float) source.getHeight();
    }
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    return transform(matrix, source, width, height,
            OPTIONS_SCALE_UP | options);
}
 
Example 7
Project: RLibrary   File: BmpUtil.java   View Source Code Vote up 6 votes
/**
 * Gets square bitmap.
 *
 * @param src  the src
 * @param rate the rate
 * @return the square bitmap
 */
public static Bitmap getSquareBitmap(Bitmap src, float rate) {
    if (src == null || src.isRecycled())
        return null;
    Bitmap ret = src;
    int w = src.getWidth();
    int h = src.getHeight();
    int min = Math.min(w, h);
    int max = Math.max(w, h);
    float r = (float) (max - min) / (float) min;
    if (w != h && r > rate) {
        max = Math.round((1.0f + rate) * min);
        if (w > h) {
            ret = Bitmap.createBitmap(src, (w - max) / 2, 0, max, min);
        } else {
            ret = Bitmap.createBitmap(src, 0, (h - max) / 2, min, max);
        }
    }
    return ret;
}
 
Example 8
Project: Fatigue-Detection   File: STUtils.java   View Source Code Vote up 6 votes
/**
     * Get the pixels by byte[] of Bitmap
     * @param image
	 * @return pixels by byte[]
     */
    public static int[] getBGRAImageByte(Bitmap image) {
        int width = image.getWidth();
        int height = image.getHeight();

		if(image.getConfig().equals(Config.ARGB_8888)) {
	        int[] imgData = new int[width * height];
	        image.getPixels(imgData, 0, width, 0, 0, width, height);
	        return imgData;
	       
//	        byte[] imgPixels = new byte[width * height];
//	        for (int i = 0; i < imgData.length; ++i) {
//	        	int p = 0;
//	        	//p += ((imgData[i] >> 24) & 0xFF);
//	        	p += ((imgData[i] >> 16) & 0xFF);
//	        	p += ((imgData[i] >> 8) & 0xFF);
//	        	p += ((imgData[i] >> 0) & 0xFF);
//	            imgPixels[i] = (byte) (p/3);
//	        }
		} else {
			// TODO
		}

        return null;
    }
 
Example 9
Project: Glide-transformations   File: CropSquareTransformation.java   View Source Code Vote up 6 votes
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();
  int size = Math.min(source.getWidth(), source.getHeight());

  mWidth = (source.getWidth() - size) / 2;
  mHeight = (source.getHeight() - size) / 2;

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
  }

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
 
Example 10
Project: letv   File: RoundImageView.java   View Source Code Vote up 5 votes
public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
    Bitmap squareBitmap;
    Bitmap scaledSrcBmp;
    int diameter = radius * 2;
    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();
    Bitmap bitmap;
    int i;
    if (bmpHeight > bmpWidth) {
        bitmap = bmp;
        i = (bmpHeight - bmpWidth) / 2;
        squareBitmap = Bitmap.createBitmap(bitmap, 0, i, bmpWidth, bmpWidth);
    } else if (bmpHeight < bmpWidth) {
        int x = (bmpWidth - bmpHeight) / 2;
        bitmap = bmp;
        i = 0;
        squareBitmap = Bitmap.createBitmap(bitmap, x, i, bmpHeight, bmpHeight);
    } else {
        squareBitmap = bmp;
    }
    if (squareBitmap.getWidth() == diameter && squareBitmap.getHeight() == diameter) {
        scaledSrcBmp = squareBitmap;
    } else {
        scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter, diameter, true);
    }
    Bitmap output = Bitmap.createBitmap(scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight());
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle((float) (scaledSrcBmp.getWidth() / 2), (float) (scaledSrcBmp.getHeight() / 2), (float) (scaledSrcBmp.getWidth() / 2), paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
    return output;
}
 
Example 11
Project: TaipeiTechRefined   File: OCRUtility.java   View Source Code Vote up 5 votes
public static byte[][] bitmap2grayByteArry(Bitmap bm) {
    byte[][] grayImage = new byte[bm.getHeight()][bm.getWidth()];
    for (int i = 0; i < bm.getWidth(); i++) {
        for (int j = 0; j < bm.getHeight(); j++) {
            if (bm.getPixel(i, j) == Color.WHITE) {
                grayImage[j][i] = 0;
            } else {
                grayImage[j][i] = 1;
            }
        }
    }
    return grayImage;
}
 
Example 12
Project: RetroMusicPlayer   File: ImageUtil.java   View Source Code Vote up 5 votes
/**
 * @param bitmap                the Bitmap to be scaled
 * @param threshold             the maxium dimension (either width or height) of the scaled bitmap
 * @param isNecessaryToKeepOrig is it necessary to keep the original bitmap? If not recycle the original bitmap to prevent memory leak.
 */

public static Bitmap getScaledDownBitmap(Bitmap bitmap, int threshold, boolean isNecessaryToKeepOrig) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int newWidth = width;
    int newHeight = height;

    if (width > height && width > threshold) {
        newWidth = threshold;
        newHeight = (int) (height * (float) newWidth / width);
    }

    if (width > height && width <= threshold) {
        //the bitmap is already smaller than our required dimension, no need to resize it
        return bitmap;
    }

    if (width < height && height > threshold) {
        newHeight = threshold;
        newWidth = (int) (width * (float) newHeight / height);
    }

    if (width < height && height <= threshold) {
        //the bitmap is already smaller than our required dimension, no need to resize it
        return bitmap;
    }

    if (width == height && width > threshold) {
        newWidth = threshold;
        newHeight = newWidth;
    }

    if (width == height && width <= threshold) {
        //the bitmap is already smaller than our required dimension, no need to resize it
        return bitmap;
    }

    return getResizedBitmap(bitmap, newWidth, newHeight, isNecessaryToKeepOrig);
}
 
Example 13
Project: sctalk   File: CircleBitmapDisplayer.java   View Source Code Vote up 5 votes
@Override
public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_4444);

    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);

    //--CROP THE IMAGE
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2 - 1, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    //--ADD BORDER IF NEEDED
    if(this.borderWidth > 0){
        final Paint paint2 = new Paint();
        paint2.setAntiAlias(true);
        paint2.setColor(this.borderColor);
        paint2.setStrokeWidth(this.borderWidth);
        paint2.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, (float) (bitmap.getWidth() / 2 - Math.ceil(this.borderWidth / 2)), paint2);
    }
    imageAware.setImageBitmap(output);
}
 
Example 14
Project: studydemo   File: PicassoUtils.java   View Source Code Vote up 5 votes
@Override
public Bitmap transform(Bitmap source) {
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    Bitmap result = Bitmap.createBitmap(source, x, y, size, size);
    if (result != source) {
        //回收
        source.recycle();
    }
    return result;
}
 
Example 15
Project: GitHub   File: TransformationUtilsTest.java   View Source Code Vote up 5 votes
private static void assertHasOriginalAspectRatio(Bitmap original, Bitmap transformed) {
  double originalAspectRatio = (double) original.getWidth() / (double) original.getHeight();
  double transformedAspectRatio =
      (double) transformed.getWidth() / (double) transformed.getHeight();

  assertThat(transformedAspectRatio)
      .isIn(Range.open(originalAspectRatio - 0.05f, originalAspectRatio + 0.05f));
}
 
Example 16
Project: Blogg   File: Tools.java   View Source Code Vote up 5 votes
public static Bitmap getCroppedBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
            bitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    //Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false);
    //return _bmp;
    return output;
}
 
Example 17
Project: boohee_v5.6   File: a.java   View Source Code Vote up 5 votes
private static Bitmap a(Bitmap bitmap, int i) {
    Matrix matrix = new Matrix();
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (width <= height) {
        width = height;
    }
    float f = ((float) i) / ((float) width);
    matrix.postScale(f, f);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,
            true);
}
 
Example 18
Project: SmartMath   File: OGLChart.java   View Source Code Vote up 5 votes
/**
 * Create a bitmap text based texture.
 * @param text
 * @param color
 * @param dTextSize
 * @return texture id
 */
public int createBmpStrTexture(GL10 gl, String text, com.cyzapps.VisualMFP.Color color, double dTextSize, Rect rectSize, Rect rectOrigTxt)	{
    // initialize textures
    Bitmap bitmapText = createTextBitmap(text, new Paint(), color, dTextSize, rectOrigTxt);
    if (rectSize != null)	{
    	rectSize.top = rectSize.left = 0;
    	rectSize.right = bitmapText.getWidth();
    	rectSize.bottom = bitmapText.getHeight();
    }

    int nTextureId = createBmpTexture(gl, bitmapText);
    bitmapText.recycle();
    return nTextureId;
}
 
Example 19
Project: android-mvvm-architecture   File: RoundedImageView.java   View Source Code Vote up 5 votes
private Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
    Bitmap finalBitmap;

    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) {
        finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
    } else {
        finalBitmap = bitmap;
    }

    Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
            finalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
            finalBitmap.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(finalBitmap.getWidth() / 2,
            finalBitmap.getHeight() / 2,
            finalBitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
}
 
Example 20
Project: FreeStreams-TVLauncher   File: CacheUtils.java   View Source Code Vote up 4 votes
/**
 * 获得bitmap的字节大小.
 */
public static int getBitmapSize(Bitmap bitmap)
{
    return bitmap.getRowBytes() * bitmap.getHeight();
}