Mohit
Mohit

Reputation: 515

Bluring Part of an Image in Android

is there any way to blur only part of an image in android?

searched a lot but dint find any help.

most of the examples use gaussian blur which blurs full imageview.

i want to allow user to dynamically draw rectangle on imageview & on action up area within rectangle should be blured.

any help will be really appreciated.

Upvotes: 1

Views: 1321

Answers (5)

Thomas Bouron
Thomas Bouron

Reputation: 613

Bluring images on the fly is not an easy task, ask Roman Nurik (The one behind Muzei app) He gave useful tips on this Google+ post but it's for animated images, from focus to blur.

In your case, I would say that you need to (roughly):

  1. Get the bounds of the drawn rectangle
  2. Get the image part that corresponds to the previous bounds
  3. Blur on the fly the previous image part
  4. Draw, into the same canvas, the blurred image part on top of the original image
  5. Set up a onDrag Listener to move the drawn rectangle and do again step 1

EDIT: After re-thinking about it, computing and draw a blurred area each time the drawn rectangle move it too heavy, it won't work. The solution is probably this:

  1. Blur the entire image and keep it into memory
  2. Get the bounds of the drawn rectangle
  3. Get the part of the blurred image that corresponds to the previous bounds
  4. Draw, into the same canvas, the blurred image part on top of the original image
  5. Set up a onDrag Listener to move the drawn rectangle to do again step 2-3-4

Upvotes: 4

Ankur Samarya
Ankur Samarya

Reputation: 229

This is code for blur: http://shaikhhamadali.blogspot.in/2013/07/gaussian-blur-imagebitmap-in-imageview.html

In this code computeConvolution3x3 method is used for computing the blur.For computing blur it convert the bitmap in to pixel array then it apply on those pixel. So you have to just do is get pixels array of that part of the image that you want blur.

Upvotes: 0

CodeWarrior
CodeWarrior

Reputation: 5176

Once you have drawn your rectangle set alpha = 0.5 or as per your need so that your dynamic view that you have drawn will look blurred.

Upvotes: 0

ahmed_khan_89
ahmed_khan_89

Reputation: 2773

put the image view in a relative layout. you detect the touch events of the user. for each rectangle that he is drawing, you add an image view of it is size superposed to the initial one (I mean in the same relative layout) and of course with your blur effect. you will see your image view blured part by part ...

Upvotes: 1

Aditya_Anand
Aditya_Anand

Reputation: 565

put another layout on the half part of the image and set a translucent type background to the layout.

Upvotes: 0

Related Questions