Code example for Bitmap

Methods: copyPixelsToBuffergetConfiggetHeightgetWidth

0
	private RandomAccessFile tempRandomAccessFile;
	private FileChannel channel;
	 
	public Bitmap convertToMutable(Bitmap bmp) {
		try { 
			Buffer cache = createMappedBuffer(bmp.getWidth() * bmp.getHeight() * 4);
			bmp.copyPixelsToBuffer(cache);
			 
			bmp = clearBitmap(bmp);
			 
			cache.position(0);
			bmp.copyPixelsFromBuffer(cache);
			 
			cleanUp(); 
		} 
		catch (Exception e) {
			return null; 
		} 
 
		return bmp;
	} 
	 
	private Buffer createMappedBuffer(int size) throws IOException {
		tempFile = File.createTempFile(".bmp", null);
		tempRandomAccessFile = new RandomAccessFile(tempFile, "rw");
		channel = tempRandomAccessFile.getChannel();
		return channel.map(MapMode.READ_WRITE, 0, size);
	} 
	 
	private Bitmap clearBitmap(Bitmap bmp) {
		int width = bmp.getWidth();
		int height = bmp.getHeight();
		Config config = bmp.getConfig();
		bmp.recycle();
		return Bitmap.createBitmap(width, height, config);
	} 
 
	private void cleanUp() throws IOException {