Code example for Canvas

Methods: clipPathdrawBitmap

0
			int height = (int)(image.getHeight() / scale);
			Bitmap tempBitmap = Bitmap.createScaledBitmap(image, width, height, true);
			 
			// Create a new bitmap that is the thumbnail size 
			Bitmap resultBitmap = Bitmap.createBitmap(size + borderSize * 2, size + borderSize * 2, Bitmap.Config.ARGB_8888);
			Canvas canvas = new Canvas(resultBitmap);
			 
			// Create a clipping path with rounded corners 
			if (cornerRadius > 0) {
		        final Rect rect = new Rect(borderSize, borderSize, size + borderSize, size + borderSize);
		        final RectF rectF = new RectF(rect);
				Path path = new Path();
				path.addRoundRect(rectF, (float)cornerRadius, (float)cornerRadius, Path.Direction.CCW);
				canvas.clipPath(path);
			} 
			 
			// Draw the image to the canvas (clipped to the path) and centered 
			int x = borderSize - (tempBitmap.getWidth() - size) / 2;
			int y = borderSize - (tempBitmap.getHeight() - size) / 2;	
			Paint paint = new Paint();
			paint.setDither(dither);
			canvas.drawBitmap(tempBitmap, (float)x, (float)y, paint);
			 
			// We're done with the tempBitmap 
			tempBitmap.recycle();
			tempBitmap = null;