Code example for Bitmap

Methods: compressrecycle

0
			String name = message.getData().getString("name");
			int quality = message.arg1;
			Bitmap b = (Bitmap)message.obj;
			if(b != null) {
				saveFile(name, b, quality);
				b.recycle();
			} 
			else { 
				Log.d(LOG_TAG, "NULL BITMAP!!");
			} 
		} 
 
		/** 
		 * Saves a file. 
		 *  
		 * @param name the name of the file 
		 * @param b the bitmap to save 
		 * @param quality the compression rate. From 0 (compress for lowest size) to 100 (compress for maximum quality). 
		 *  
		 */ 
		private void saveFile(String name, Bitmap b, int quality){
			FileOutputStream fos = null;
			String fileName = getFileName(name);
 
			File directory = new File(Environment.getExternalStorageDirectory() + "/Robotium-Screenshots/");
			directory.mkdir();
 
			File fileToSave = new File(directory,fileName);
			try { 
				fos = new FileOutputStream(fileToSave);
				if (b.compress(Bitmap.CompressFormat.JPEG, quality, fos) == false)
					Log.d(LOG_TAG, "Compress/Write failed");
				fos.flush();
				fos.close();
			} catch (Exception e) {
				Log.d(LOG_TAG, "Can't save the screenshot! Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.");