How to blur some portion of Image in Android?
do a masked blur few times ....
create mask
0
means blur (black) and>=1
means not blur (white). Init this part by big enough value for examplew=100
pixelscreate masked blur function
just a common convolution with some matrix like
0.0 0.1 0.0
0.1 0.6 0.1
0.0 0.1 0.0but do it only for target pixels where mask is
==0
after image is blurred blur also the mask. This should enlarge the white area a bit (by pixel per iteration but losing magnitude on borders that is whyw>1
).loop bullet #2
N
timesN
determines blur/non-blur gradient depth thew
is only to assure that burred mask will grow... Each time the blur mask will increase its white part
That should do the trick, You can also use dilatation of the mask instead of blurring it.
[edit1] implementation
Have played with this a bit today and found out that the mask is not growing enough with smooth so I change the algo a bit (here mine code C++):
picture pic0,pic1,pic2;
// pic0 - source
// pic1 - output
// pic2 - mask
int x0=400,y0=330,r0=100,dr=200;
// x0,y0,r0 - masked area
// dr - blur gradient size
int i,r;
// init output as sourceimage
pic1=pic0;
// init mask (size of source image) with gradient circles
pic2.resize(pic0.xs,pic0.ys);
pic2.clear(0);
for (i=1;i<=255;i++)
{
r=r0+dr-((dr*i)>>8);
pic2.bmp->Canvas->Brush->Color=TColor(i<<16); // shifted because GDI has inverse channel layout then direct pixel access
pic2.bmp->Canvas->Pen ->Color=TColor(i<<16);
pic2.bmp->Canvas->Ellipse(x0-r,y0-r,x0+r,y0+r);
}
for (i=1;i<255;i+=10) pic1.rgb_smooth_masked(pic2,i);
here the smooth function:
//---------------------------------------------------------------------------
void picture::rgb_smooth_masked(const picture &mask,DWORD treshold)
{
int i,x,y;
color *q0,*q1,*m0,c0,c1,c2;
if ((xs<2)||(ys<2)) return;
for (y=0;y<ys-1;y++)
{
q0=p[y ]; m0=mask.p[y];
q1=p[y+1];
for (x=0;x<xs-1;x++)
if (m0[x].dd<treshold)
{
c0=q0[x];
c1=q0[x+1];
c2=q1[x];
for (i=0;i<4;i++)
q0[x].db[i]=DWORD((DWORD(c0.db[i])+DWORD(c0.db[i])+DWORD(c1.db[i])+DWORD(c2.db[i]))>>2);
}
}
}
//---------------------------------------------------------------------------
create gradient mask with circles increasing in color from
1
to255
rest is black the gradient width is
dr
and determine the smoothing sharpness.create smooth masked with mask and threshold
smooth all pixels where mask pixel is < threshold. See the function
rgb_smooth_masked
. It uses2x2
convolution matrix0.50,0.25
0.25,0.00loop threshold from
1
to255
by some stepthe step determines the image blur strength.
And finally here some visual results this is source image I taken with my camera:
And here the output on the left and mask on the right:
the blue color means values < 256
(B is lowest 8 bits of color)
I use my own picture class for images so some members are:
xs,ys
size of image in pixelsp[y][x].dd
is pixel at(x,y)
position as 32 bit integer typeclear(color)
- clears entire imageresize(xs,ys)
- resizes image to new resolution
Android gaussian blur on part of an image
You can use paint and blur parts of your canvas. There are some links which can be help to you :
Blur on touch. Android application
Is it possible to blur part of image on touch in Android?
Android draw with blur
Hope this helps.
how to blur the image in selected area in android?
I found it by the below link:
http://trickyandroid.com/advanced-blurring-techniques/
Now i am going to develop this link to drag and drop the selected blur area. But i am not getting to drop this blur in other area. please help for this.
How to blur the specific part of image without using Render Script,as my minsdk is 14.
You should first blur the bitmap:
Android: fast bitmap blur?
Then you have to apply image masking to that bitmap by using transparent in the middle.
Masking(crop) image in frame
Then you should put this bitmap as drawale to your movable imageview.
Related Topics
Receiver Not Registered Exception Error
Android Viewpager Get the Current View
Immersive Mode Navigation Becomes Sticky After Volume Press or Minimise-Restore
How to Remove the Top and Bottom Space on Textview of Android
Measuring a View Before Rendering It
How to Simulate Accelerometer in Android Emulator
Whatsapp Like Collapsing Toolbar
Clear Text in Edittext When Entered
How to Get All Child's Data in Firebase Database
Android Xml Rounded Clipped Corners
Android SQLite Database, Why Drop Table and Recreate on Upgrade
Convert Xml to JSON Object in Android
Android: How to Refresh Listview Contents
Android: Running a Background Task Using Alarmmanager
Cannot Find Symbol Databindingcomponent on Android Studio 3.2 Canary 16 Kotlin Project