How To Add Border To Bitmap Image Content Instead Of Its Background By Using Canvas?
The feature of a bitmap image is that it has a transparent background and usually has a rectangular shape, so when we try to add a border to the image, instead of its content inside there will be a border, its background will have a border. For example, I have a bitmap image of a dog and I want it to have a border but instead, a rectangular background will have a border. I'm using Canvas to draw a bitmap and am having this problem. Can anyone help me?
Block code to create photo
mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(10); // set stroke width mPaint.setColor(getResources().getColor(R.color.black)); // set stroke color mPaint.setAntiAlias(true); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icons8_bus_36_2); tempBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas tempCanvas = new Canvas(tempBitmap); Rect rect = new Rect( 10 / 2, 10 / 2, tempCanvas.getWidth() - 10 / 2, tempCanvas.getHeight() - 10 / 2); tempCanvas.drawRect(rect,mPaint); tempCanvas.drawBitmap(bitmap, 0, 0, mPaint);
On this part:
Rect rect = new Rect( 10 / 2, 10 / 2, tempCanvas.getWidth() - 10 / 2, tempCanvas.getHeight() - 10 / 2);
Rect rect = new Rect( 10 / 2, 10 / 2, (tempCanvas.getWidth() - 10) / 2, (tempCanvas.getHeight() - 10) / 2);
Thats because 10 is divided by two first
Also, draw bitmap first before you draw rect
you could draw with this:
Path clipPath = new Path(); RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight()); clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW); canvas.clipPath(clipPath);
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View