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

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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:createBitmap, postScale
			int bmpHeight = bitmap.getHeight();
 
			scaleWidth = (float) (scaleWidth * ZOOM_IN_SCALE);
			scaleHeight = (float) (scaleHeight * ZOOM_IN_SCALE);
 
			Matrix matrix = new Matrix();
			matrix.postScale(scaleWidth, scaleHeight);
			zoomedBMP = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight,
					matrix, true);
			imgView.setImageBitmap(zoomedBMP);
		} catch (Exception e) {
			// can't zoom because of memory issue, just ignore, no big deal 
		} 
	} 
} 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:createBitmap, getHeight, getWidth
public class ImageFactory { 
	 
	public static Bitmap imageCrop(Bitmap image, KrollDict args)
	{ 
		if (image != null) {
			int width = args.optInt("width", image.getWidth());
			int height = args.optInt("height", image.getHeight());
			int x = args.optInt("x", (image.getWidth() - width) / 2);
			int y = args.optInt("y", (image.getHeight() - height) / 2);
			 
			return Bitmap.createBitmap(image, x, y, width, height);
		} 
		 
		return null; 
	} 
 
	public static Bitmap imageResize(Bitmap image, KrollDict args)
	{ 
		if (image != null) {
			int width = args.optInt("width", image.getWidth());
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:createBitmap, postRotate, postScale
 
	public static Bitmap decode(final InputStream is, final BitmapFactory.Options opts) {
		if (is == null) return null;
		final int orientation = Exif.getOrientation(is);
		final Bitmap bm = BitmapFactory.decodeStream(is, null, opts);
		final Matrix m = new Matrix();
		switch (orientation) {
			case 270: 
			case 90: 
				m.postRotate(orientation);
				return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true);
			case 180: 
				m.postRotate(orientation);
				m.postScale(bm.getWidth(), bm.getHeight());
				return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true);
		} 
		return bm;
	} 
 
	public static Bitmap decode(final String path, final BitmapFactory.Options opts) {
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:createBitmap, postRotate, postScale
			Bitmap output;
 
			if ( rotation == 0 ) {
				output = Bitmap.createScaledBitmap( input, dstWidth, dstHeight, true );
			} else { 
				Matrix matrix = new Matrix();
				matrix.postScale( (float) dstWidth / srcWidth, (float) dstHeight / srcHeight );
				matrix.postRotate( rotation );
				output = Bitmap.createBitmap( input, 0, 0, srcWidth, srcHeight, matrix, true );
			} 
			return output;
		} else 
			return input;
	} 
 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:createBitmap, postScale
		int height = bm.getHeight();
		float scaleWidth = ((float) newWidth) / width;
		float scaleHeight = ((float) newHeight) / height;
 
		// create a matrix for the manipulation 
		Matrix matrix = new Matrix();
		// resize the bit map 
		matrix.postScale(scaleWidth, scaleHeight);
 
		// recreate the new Bitmap 
		Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
		return resizedBitmap;
	} 
 
	protected Bitmap getAppIcon(JSONObject app) {
		Bitmap img = BitmapFactory.decodeResource(mact.getResources(), R.drawable.soup);
		try { 
			JSONObject icons = app.getJSONObject("icons");
			switch (icons.length()) {
			case 0: 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:createBitmap, preScale
        final Canvas cv = new Canvas();
        cv.setBitmap(original);
        icon.setBounds(0,0, width, height);
        icon.draw(cv);
        //This will not scale but will flip on the Y axis 
        Matrix matrix = new Matrix();
        matrix.preScale(1, -1);
         
        //Create a Bitmap with the flip matix applied to it. 
        //We only want the bottom half of the image 
        Bitmap reflectionImage;
        try{ 
            reflectionImage= Bitmap.createBitmap(original, 0, height/2, width, height/2, matrix, false);
        } catch (OutOfMemoryError e) {
            return new FastBitmapDrawable(original);
        } 
 
        //Create a new bitmap with same width but taller to fit reflection 
        Bitmap bitmapWithReflection;
        try{ 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:createBitmap, getHeight, getWidth, recycle
					if (orientation == 0
							&& scaled.getWidth() < scaled.getHeight()) {
						new Util().log(String.format(
								"FILE:%s ORIENTATION: LANDSCAPE", filePath));
						Bitmap rotated = rotatePhoto(scaled, -90);
						scaled.recycle();
						return rotated;
					} else if (orientation == 90
							&& scaled.getWidth() > scaled.getHeight()) {
						new Util().log(String.format(
								"FILE:%s ORIENTATION: PORTRAIT", filePath));
						Bitmap rotated = rotatePhoto(scaled, 90);
						scaled.recycle();
						return rotated;
					} else { 
						new Util().log(String.format("FILE:%s ORIENTATION: %d",
								filePath, orientation));
					} 
					return scaled;
				} 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:createBitmap, postScale
			} else { 
				scale = (float) desireWidth / (float) width;
			} 
 
			// Draw resized image 
			Matrix matrix = new Matrix();
			matrix.postScale(scale, scale);
			Bitmap bitmap = Bitmap.createBitmap(drawable, 0, 0, width, height,
					matrix, true);
			Canvas canvas = new Canvas(bitmap);
			canvas.drawBitmap(bitmap, 0, 0, null);
 
			drawable = bitmap;
		} 
 
		return drawable;
	} 
 
	/** 
	 * Resizes specific a Drawable with keeping ratio. 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:compress, createBitmap, getHeight, getWidth
 
	private static int MAX_IMAGE_DIMENSION = 720;
	 
	public byte[] scaleImage(Context context, Bitmap bitmap, Bitmap.CompressFormat format) {
		 
		int width = bitmap.getWidth();
		 
		if(width > MAX_IMAGE_DIMENSION) {
			float ratio = (float) MAX_IMAGE_DIMENSION / (float) width;
			 
			width = MAX_IMAGE_DIMENSION;
			int height = (int)((float)bitmap.getHeight() * ratio);
			bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height);
		} 
 
		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		bitmap.compress(format, 100, stream);
		return stream.toByteArray();
	} 
 

7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Bitmap createBitmap Questions & Answers:

createBitmap Method Overview
Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.
See Code Examples for other Android Bitmap Methods: