Code example for Bitmap

Methods: compressgetHeightgetRowBytes

    public void validate(View view)
    	// get Bitmap from SignatureView  
    	Bitmap b =;
    	// calculate the number of pixels 
    	int pixels = b.getHeight() * b.getRowBytes();
    	// instanciate an OutputStream to handle the pixels 
    	ByteArrayOutputStream baos = new ByteArrayOutputStream(pixels);
    	// we record it as a PNG (lossless format) 
    	b.compress(CompressFormat.PNG, 0, baos);
    	// we get the bytes array 
    	byte[] bytes = baos.toByteArray();
    	// here we delete the previous recorded signature 
    	getContentResolver().delete(Signature.CONTENT_URI, null, null);
    	// ContentValues is a wrapper class used to insert in db 
    	ContentValues cv = new ContentValues(2);
    	cv.put(Signature.SIGNATURE, bytes);
    	cv.put(Signature.DATE, new Date().toLocaleString());
    	// here we insert in database, and we get the uri of the image 
    	Uri uri = getContentResolver().insert(Signature.CONTENT_URI, cv);