Code example for Bitmap

Methods: compresscreateBitmapgetHeightgetRowBytesgetWidth

0
		/* Rotate 90 degree */ 
		Matrix m = new Matrix();
		m.setRotate(90);
		Bitmap bmp = null;
		try { 
			bmp = Bitmap.createBitmap(capturedBmp, 0, 0, capturedBmp.getWidth(),
				capturedBmp.getHeight(), m, false);	
		} catch(OutOfMemoryError oom) {
			/* 
			 *  If bitmap rotation is failed, 
			 *  we just use captured bitmap. 
			 */ 
			Toast.makeText(this, "Unable to rotate bitmap", Toast.LENGTH_SHORT);
			bmp = capturedBmp;
		} 
		 
		/* Check storage card availability */ 
		final String TEMP_FILE_NAME = "temp_capture_image.jpg";
		File outputFile = new File(mImgStg.getBasePath(), TEMP_FILE_NAME);
		 
		boolean saveResult = false;
		String absPath = "";
		try { 
			/* Create new file */ 
			/* outputFile.createNewFile();*/ 
//			FileOutputStream stm = new FileOutputStream(outputFile.getAbsolutePath()); 
			 
//			FileOutputStream stm = this.openFileOutput(TEMP_FILE_NAME, MODE_WORLD_READABLE); 
//			FileOutputStream stm = this.openFileOutput(outputFile.getAbsolutePath(), MODE_WORLD_READABLE); 
			FileOutputStream stm = RRUtil.openFileOutputStream(this, outputFile.getAbsolutePath());
			if(null == stm) {
				this.finish();
				return; 
			} 
			saveResult = bmp.compress(CompressFormat.JPEG, 100, stm);			
			stm.flush();
			stm.close();
			 
			/* Get absolute path */ 
			absPath = outputFile.getAbsolutePath();
		} catch(Exception e) {
			e.printStackTrace();
			Log.e(TAG, "Unable to save temporary image: " + e.toString());
			/* Show error message */ 
			Toast.makeText(this, "Unable to save captured file", Toast.LENGTH_SHORT).show();
			/* Finish activity */ 
			this.finish();
			return; 
		} 
		 
		if(saveResult == false) {
			Log.e(TAG, "unable to save image to file");
			return; 
		} 
		 
		 
		/** Go to RRCaptured activity. 
		 *  Pass captured file name. 
		 */ 
		Intent i = new Intent(this, RRCaptureConfirmActivity.class);
		i.putExtra("PARAM_IMAGE_FILE", absPath);
		 
		this.startActivity(i);
//		this.finish(); 
		 
	} 
 
 
	private void dumpBitmapInfo(Bitmap capturedBmp) {
		StringBuilder builder = new StringBuilder();
		builder.append(capturedBmp.getWidth());
		builder.append(capturedBmp.getHeight());
		builder.append(capturedBmp.getRowBytes());
		Log.d(TAG, "Captured image size: " + builder.toString());
	} 
 
}