I want to make my image blurry. I am trying to do that but I can't achieve it. When I am using the renderscript it is working(the image has blurred) but it doesn't support the lower version API, only it supports from Android 4.2. So, I don't want to us renderscript, (for the lower API's. Please give insight into the solution friends.
Here is my code:
public class MainActivity extends Activity {
Button btnLoadImage;
ImageView imageResult;
final int RQS_IMAGE1 = 1;
Uri source;
Bitmap bitmapMaster;
Canvas canvasMaster;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnLoadImage = (Button) findViewById(R.id.loadimage);
imageResult = (ImageView) findViewById(R.id.result);
btnLoadImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RQS_IMAGE1);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case RQS_IMAGE1:
source = data.getData();
try {
bitmapMaster = BitmapFactory
.decodeStream(getContentResolver().openInputStream(
source));
loadGrayBitmap(bitmapMaster);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
}
private void loadGrayBitmap(Bitmap bitmap) {
if (bitmap != null) {
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
RenderScript rs = RenderScript.create(getApplicationContext());
ScriptIntrinsicBlur blurscript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation in = Allocation.createFromBitmap(rs, bitmap);
Allocation out = Allocation.createFromBitmap(rs, outBitmap);
blurscript.setRadius(25.f);
blurscript.setInput(in);
blurscript.forEach(out);
out.copyTo(outBitmap);
bitmap.recycle();
imageResult.setImageBitmap(outBitmap);
// return outBitmap;
}
}
}