2020년 5월 26일 화요일

Glide

Glide란?

  • 이미지 로딩 라이브러리이다. 
  • API를 사용하여 쉽게 조작할 수 있다. 

우선 build.gradle 안에 
implementation 'com.github.bumptech.glide:glide:4.9.0'                                                                              annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'


Glide.with(this)
    .load(url)
    .into(imageView);

간단하게 사용하는 방법을 위에 있는 문장을 사용하여 괄호() 안에만 넣어주면 된다.                     자동적으로 다운샘플링 되기 때문에 이미지 사이즈를 줄여서 저장하게 된다. 
여기서 궁금한 점! 대부분의 글이나 이미지를 불러온다면 open 을 명시해주고 close로 닫아준다. 과연 우리의 Glide는 어떤 방법을 써야할까 .
Glide.with(fragment).clear(imageView);
이렇게 사용해야겠지만                                                                    this에 대한 Activity가 destroy 될 때 , 자동으로 clear 된다. 
이 밑에 부터는 제가 필요한 것만 정리해 놓았습니다.

Background Threads

FutureTarget<Bitmap> futureTarget =
  Glide.with(context)
    .asBitmap()
    .load(url)
    .submit(width, height);

Bitmap bitmap = futureTarget.get();

// Do something with the Bitmap and then when you're done with it:
Glide.with(context).clear(futureTarget);

에러처리를 요청으로 

Glide.with(fragment)
  .load(primaryUrl)
  .error(
      Glide.with(fragment)
        .load(fallbackUrl))
  .into(imageView);

Option 적용 

RequestOptions options = 
    new RequestOptions()
      .set(MyCustomModelLoader.TIMEOUT_MS, 1000L);

Glide.with(context)
  .load(url)
  .apply(options)
  .into(imageView);

참고:https://bumptech.github.io/glide/




댓글 없음

댓글 쓰기

© 특히하고 특별한
Maira Gall