DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Low-Code Development: Leverage low and no code to streamline your workflow so that you can focus on higher priorities.

DZone Security Research: Tell us your top security strategies in 2024, influence our research, and enter for a chance to win $!

Launch your software development career: Dive head first into the SDLC and learn how to build high-quality software and teams.

Open Source Migration Practices and Patterns: Explore key traits of migrating open-source software and its impact on software development.

Related

  • Dynamic Watermarking of Bitmaps in Databases
  • How To Create a Homescreen Widget in Android
  • How Does WebView Actually Work on Android?
  • How To Integrate Chatbot With an Android App

Trending

  • GBase 8a Implementation Guide: Resource Assessment
  • The Art of Manual Regression Testing
  • A Complete Guide To Implementing GraphQL for Java
  • Linting Excellence: How Black, isort, and Ruff Elevate Python Code Quality
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. How To Create a Bitmap Blur Effect In Android Using RenderScript

How To Create a Bitmap Blur Effect In Android Using RenderScript

Learn how to achieve the popular blur effect on your Android apps

By 
Nilanchala Panigrahy user avatar
Nilanchala Panigrahy
·
Sep. 23, 15 · Tutorial
Like (3)
Save
Tweet
Share
13.7K Views

Join the DZone community and get the full member experience.

Join For Free

Android RenderScript framework API can be used for performing computationally intensive tasks at high performance. RenderScript was primarily developed to use with data-parallel computation, although serial computationally intensive workloads can benefit as well. The RenderScript runtime will parallelize work across all processors available on a device, such as multi-core CPUs, GPUs, or DSPs, allowing you to focus on expressing algorithms rather than scheduling work or load balancing.

RenderScript is especially useful for applications performing image processing, computational photography, or computer vision. There are two ways we can access the Android RenderScript framework APIs:

  • Directly using android.renderscript API classes. These classes are available from Android 3.0 (API level 11) and higher.
  • Alternatively, you can use android.support.v8.renderscript support package classes. The support library classes are available for devices running Android 2.2 (API level 8) and higher.

How To Use RenderScript

In order to use the Support Library RenderScript APIs, you must have Android SDK Tools revision 22.2 or higher and SDK Build-tools revision 18.1.0 or higher.

After you have the above two minimum development tools, you need to update the settings for the Android build process to include the RenderScript APIs. In the Android Studio project add the following configurations to the project build.gradlefile.

defaultConfig {
    applicationId "com.javatechig"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"

    // Add the following two lines
    renderscriptTargetApi 18
    renderscriptSupportModeEnabled true
}


The following code snippets can be used to create a bitmap blur effect in Android using RenderScript API.

//Set the radius of the Blur. Supported range 0 < radius <= 25
private static final float BLUR_RADIUS = 25f;

public Bitmap blur(Bitmap image) {
    if (null == image) return null;

    Bitmap outputBitmap = Bitmap.createBitmap(image);
    final RenderScript renderScript = RenderScript.create(this);
    Allocation tmpIn = Allocation.createFromBitmap(renderScript, image);
    Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap);

    //Intrinsic Gausian blur filter
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);
    return outputBitmap;
}


You can use the above code snippet to blur an ImageView as follows.

ImageView imageView = (ImageView) findViewById(R.id.imageView);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.nature);
Bitmap blurredBitmap = blur(bitmap);
imageView.setImageBitmap(blurredBitmap);

Result:


Android (robot) Bitmap

Published at DZone with permission of Nilanchala Panigrahy, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Dynamic Watermarking of Bitmaps in Databases
  • How To Create a Homescreen Widget in Android
  • How Does WebView Actually Work on Android?
  • How To Integrate Chatbot With an Android App

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: