기본 콘텐츠로 건너뛰기

안드로이드 앱 만들기 : image blur (이미지 흐리게) 처리 하기


원본출처: 티스토리 바로가기

https://ssaurel.medium.com/create-a-blur-effect-on-android-with-renderscript-aa05dae0bd7d

 

Create a Blur Effect on Android with RenderScript

In image processing, a Blur Effect, also known as Gaussian Blur, is the result of blurring an image by applying a Gaussian function. The…

ssaurel.medium.com

먼저 출처를 밝혀본다... 앱안에 이미지를 넣을껀데... 이미지을 흐릿하게 만들고 싶을 경우가 있을 것 같다. 이걸 구현하는 예제를 찾았다. 그래서 잠시 옮겨 볼까 한다.  먼저 글쓴이분에게 심심한 감사를 표하며... 따라하기를 해 보겠다.

 

gradle 파일에 추가하기...

 

plugins {     id 'com.android.application'     id 'com.google.gms.google-services'     id 'com.google.firebase.crashlytics' }  android {     ...          compileSdkVersion 32     defaultConfig {         applicationId "com.nari.notify2kakao"         minSdkVersion 26         targetSdkVersion 32         versionCode 21         versionName '1.2.4'         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"          renderscriptTargetApi 18         renderscriptSupportModeEnabled true      }     .... }  dependencies {      ... }

renderscript 을 이용하는 것이라고 하는데...  2줄 추가 했다.

 

renderscriptTargetApi 18 renderscriptSupportModeEnabled true 

 

다음은 blur 처리하는 class 을 하나 만들어 보겠다.

 

import android.content.Context; import android.graphics.Bitmap;  import androidx.renderscript.Allocation; import androidx.renderscript.Element; import androidx.renderscript.RenderScript; import androidx.renderscript.ScriptIntrinsicBlur;  public class BlurBuilder {      private static final float BITMAP_SCALE = 0.6f;     private static final float BLUR_RADIUS = 15f;      public static Bitmap blur(Context context, Bitmap image) {         int width = Math.round(image.getWidth() * BITMAP_SCALE);         int height = Math.round(image.getHeight() * BITMAP_SCALE);         Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);         Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);         RenderScript rs = RenderScript.create(context);         ScriptIntrinsicBlur intrinsicBlur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));         Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);         Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);         intrinsicBlur.setRadius(BLUR_RADIUS);         intrinsicBlur.setInput(tmpIn);         intrinsicBlur.forEach(tmpOut);         tmpOut.copyTo(outputBitmap);         return outputBitmap;     } }

이건 뭐 그냥 복붙 이라... ㅋ

 

다음은 나의 activity 에 추가해 본다.  layout 에는 imageview 을 하나 넣었고, activity 에서는 다음과 같이 만들어 이미지를 넣어 보았다.  참 그전에 이미지를 넣을 bitmap 파일을 하나 drawable 밑에 추가해 주어야 한다. 

 

    @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         binding = ActivityWithDrawView2Binding.inflate(getLayoutInflater());         setContentView(binding.getRoot());                  ...          Bitmap mango = BlurBuilder.blur(this, BitmapFactory.decodeResource(getResources(), R.drawable.mango));         ImageView imageView = findViewById(R.id.imageView2);         imageView.setImageBitmap(mango);         ....              }

우히... 이렇게만 코딩을 해 주면 다음과 같은 이미지의 변화를 볼 수 있다. 먼저 원본 이미지...

그 다음은 앱에 들어간 이미지는 어떻게 ???

blur 이미지

깔끔했던 망고(?)가 흐릿하게 보인다...

또 하나의 이미지 새로운 처리 방법을 알게 되어 기쁘다...

 

 

아래 링크는 위 출처의 원본 : 배워야할 것들이 있어서 일단... 링크 keep !!!

 

https://medium.com/sampingan-tech/implementing-glassmorphism-in-android-app-e73a2fd83b80

 

Implementing Glassmorphism in Android App

Glassmorphism getting more popular, but how can we implement it in a real app? Especially on the android app. Let’s talk about it.

medium.com

 

귤탐 당도선별 감귤 로열과, 3kg(S~M), 1박스 삼립 호빵 발효미종 단팥, 92g, 14개입 [엉클컴퍼니] 우리밀 찐빵/흑미찐빵/단호박찐빵/고구마찐빵 국산팥, 우리밀 고구마찐빵(20개입) 1300g 국산팥 우리밀 MORIT 여성용 방한장갑 터치스크린 다용도 고급겨울장갑 에이치머스 스마트폰 터치 방한 장갑
이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

댓글

이 블로그의 인기 게시물

개인정보처리방침 안내

 billcoreaTech('https://billcoreatech.blogspot.com/'이하 'https://billcoreatech.blogspot')은(는) 「개인정보 보호법」 제30조에 따라 정보주체의 개인정보를 보호하고 이와 관련한 고충을 신속하고 원활하게 처리할 수 있도록 하기 위하여 다음과 같이 개인정보 처리방침을 수립·공개합니다. ○ 이 개인정보처리방침은 2021년 8월 26부터 적용됩니다. 제1조(개인정보의 처리 목적) billcoreaTech('https://billcoreatech.blogspot.com/'이하 'https://billcoreatech.blogspot')은(는) 다음의 목적을 위하여 개인정보를 처리합니다. 처리하고 있는 개인정보는 다음의 목적 이외의 용도로는 이용되지 않으며 이용 목적이 변경되는 경우에는 「개인정보 보호법」 제18조에 따라 별도의 동의를 받는 등 필요한 조치를 이행할 예정입니다. 1. 서비스 제공 맞춤서비스 제공을 목적으로 개인정보를 처리합니다. 제2조(개인정보의 처리 및 보유 기간) ① billcoreaTech은(는) 법령에 따른 개인정보 보유·이용기간 또는 정보주체로부터 개인정보를 수집 시에 동의받은 개인정보 보유·이용기간 내에서 개인정보를 처리·보유합니다. ② 각각의 개인정보 처리 및 보유 기간은 다음과 같습니다. 1.<서비스 제공> <서비스 제공>와 관련한 개인정보는 수집.이용에 관한 동의일로부터<사용자의 설정시간>까지 위 이용목적을 위하여 보유.이용됩니다. 보유근거 : 앱의 기본기능 활용에 필요한 위치정보 제3조(개인정보의 제3자 제공) ① billcoreaTech은(는) 개인정보를 제1조(개인정보의 처리 목적)에서 명시한 범위 내에서만 처리하며, 정보주체의 동의, 법률의 특별한 규정 등 「개인정보 보호법」 제17조 및 제18조에 해당하는 경우에만 개인정보를 제3자에게 제공합니다. ② billcoreaTech

안드로이드 앱 만들기 : jetpack compose URL 에서 image 받아와서 보여 주기 (feat coil)

원본출처: 티스토리 바로가기 샘플 이미지 오늘은 앱을 만들면서 이미지를 보여 주어야 하는 경우 중에  URL에서 이미지를 가져와 보는 것에 대해서 기술해 보겠습니다.  URL에서 image를 가져온다는 것은 서버에 저장된 image 일수도 있고, SNS profile의 image 정보일수도 있을 것입니다.    구글에서 찾아보면 다른 것들도 많이 있기는 합니다.  그 중에서 coil 라이브러리를 이용해서 한번 만들어 보도록 하겠습니다.    gradle 설정 그래들 설정은 아래 한 줄입니다. 현재 시점에서 최신 버전인 것으로 보입니다.  이 글을 보시는 시점에 최신 버전이 아니라면 아마도 android studio는 추천을 해 줍니다. // image load from url implementation("io.coil-kt:coil-compose:2.2.2")   manaifest  설정 당연한 이야기 겠지만, url에서 이미지를 받아 와야 하기 때문에 권한 설정을 해야 합니다. 또한 인터넷에서 자료를 받아 오는 것은 지연이 발생할 수 있기 때문에 application에서도 다음 문구의 추가가 필요합니다.  <uses-permission android:name="android.permission.INTERNET" /> <application ... android:networkSecurityConfig="@xml/network_config" ... /> 이 설정을 하게 되면 xml 파일을 하나 추가해 주면 됩니다.  network_config.xml 이라는 이름으로 말입니다.  <?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextT