Code example for Bitmap

Methods: createBitmapgetHeightgetWidthrecycle

0
					} 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;
				} 
			} 
		} 
		return null; 
	} 
 
	public static Bitmap getCameraPhoto(Activity activity, Uri uri) {
		if (uri != null) {
			final BitmapFactory.Options options = new BitmapFactory.Options();
			options.inJustDecodeBounds = true;
			BitmapFactory.decodeFile(uri.getPath(), options);
 
			if (options != null) {
				new Util().log(String.format("ORIGINAL %dx%d",
						options.outWidth, options.outHeight));
				Bitmap scaled = scaleBitmap(options, uri.getPath());
				if (scaled != null) {
					new Util().log(String.format("SCALED %dx%d",
							scaled.getWidth(), scaled.getHeight()));
					if (getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT
							&& scaled.getWidth() > scaled.getHeight()) {
						Bitmap rotated = rotatePhoto(scaled, 90);
						scaled.recycle();
						return rotated;
					} 
					return scaled;
				} 
			} 
		} 
		return null; 
	} 
 
	public static boolean savePhoto(Activity activity, Bitmap bitmap,
			String fileName) {
		try { 
			ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
			bitmap.compress(Bitmap.CompressFormat.JPEG, 75, byteArray);
			bitmap.recycle();
			ImageManager.writeImage(byteArray.toByteArray(), fileName,
					getPhotoPath(activity));
			byteArray.flush();
			return true; 
		} catch (IOException e) {
			e.printStackTrace();
		} 
		return false; 
	} 
 
	public static Bitmap rotatePhoto(Bitmap bitmap, int rotate) {
		Matrix matrix = new Matrix();
		matrix.postRotate(rotate);
		return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
				bitmap.getHeight(), matrix, true);
	} 
 
	public static synchronized Bitmap scaleBitmap(
			BitmapFactory.Options options, String filePath) {