, 나는 그것을 알아 냈다. ImageLoaderConfiguration
에는 이미지 디코더를 전달할 수있는 옵션이 있습니다. 이 info.getImageKey()
는하지만,와, 원래의 URI이 이미지에 지정된 반환 것이라고 말했다 UIL의 문서에서
public class SmartUriDecoder implements ImageDecoder {
private final ContentResolver m_contentResolver;
private final BaseImageDecoder m_imageUriDecoder;
public SmartUriDecoder(ContentResolver contentResolver, BaseImageDecoder imageUriDecoder) {
if (imageUriDecoder == null) {
throw new NullPointerException("Image decoder can't be null");
}
m_contentResolver = contentResolver;
m_imageUriDecoder = imageUriDecoder;
}
@Override
public Bitmap decode(ImageDecodingInfo info) throws IOException {
if (TextUtils.isEmpty(info.getImageKey())) {
return null;
}
String cleanedUriString = cleanUriString(info.getImageKey());
Uri uri = Uri.parse(cleanedUriString);
if (isVideoUri(uri)) {
return makeVideoThumbnail(info.getTargetSize().getWidth(), info.getTargetSize().getHeight(), getVideoFilePath(uri));
}
else {
return m_imageUriDecoder.decode(info);
}
}
private Bitmap makeVideoThumbnail(int width, int height, String filePath) {
if (filePath == null) {
return null;
}
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND);
Bitmap scaledThumb = scaleBitmap(thumbnail, width, height);
thumbnail.recycle();
return scaledThumb;
}
private boolean isVideoUri(Uri uri) {
String mimeType = m_contentResolver.getType(uri);
return mimeType.startsWith("video/");
}
private String getVideoFilePath(Uri uri) {
String columnName = MediaStore.Video.VideoColumns.DATA;
Cursor cursor = m_contentResolver.query(uri, new String[] { columnName }, null, null, null);
try {
int dataIndex = cursor.getColumnIndex(columnName);
if (dataIndex != -1 && cursor.moveToFirst()) {
return cursor.getString(dataIndex);
}
}
finally {
cursor.close();
}
return null;
}
private Bitmap scaleBitmap(Bitmap origBitmap, int width, int height) {
float scale = Math.min(
((float)width)/((float)origBitmap.getWidth()),
((float)height)/((float)origBitmap.getHeight())
);
return Bitmap.createScaledBitmap(origBitmap,
(int)(((float)origBitmap.getWidth()) * scale),
(int)(((float)origBitmap.getHeight()) * scale),
false
);
}
private String cleanUriString(String contentUriWithAppendedSize) {
// replace the size at the end of the URI with an empty string.
// the URI will be in the form "content://....._256x256
return contentUriWithAppendedSize.replaceFirst("_\\d+x\\d+$", "");
}
}
:
ImageDecoder smartUriDecoder = new SmartUriDecoder(getContentResolver(), new BaseImageDecoder(false));
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.taskExecutor(ThreadPool.getExecutorService())
.defaultDisplayImageOptions(displayOptions)
.imageDecoder(smartUriDecoder)
.build();
그리고 SmartUriDecoder
클래스 : 여기
내가 초기화를 변경하는 방법입니다 마지막에 추가 된 크기로, 원본 URI를 얻을 수있는 방법을 찾지 못했습니다. 따라서 cleanUriString()
의 코드 냄새의 이유.
헤드 업,이 방법을 사용해 보았지만 여러 미디어 항목의 미리보기 이미지를 생성 할 때 느려지는 것을 느꼈습니다. 그것은 UIL이 많은 처리 시간과 대용량 파일 (50 MB 파일을 보는 것 등)을 의미하는 데이터 디렉토리의 비디오 자체에 대한 캐시 항목을 만드는 것처럼 보입니다. 나는 아직도 그것을보고 있지만, uids와 vids를 통합하는 것에 대한 훌륭한 시작에 감사드립니다. – Core
나는 이것도 알아 차렸지만, 처음으로 일어난다. 나는 비디오의 썸네일이'MediaStore'에 없었기 때문에'ThumbnailUtils.createVideoThumbnail()'을 호출하면 모든 비디오 썸네일을 만들 수밖에 없다고 생각했습니다. 하지만 그 방법이 어떻게 작동하는지 모르겠다. 그래서 나는 여기서 완전히 틀릴 수도있다. –
안녕하세요, 귀하의 작업을 기반으로 내 사용자 지정 ImageDecoder 만들려고했지만 그것을 사용하려고하면 디코더가이 오류와 함께 실패합니다 : E/ImageLoader : null java.lang.NullPointerException? 어떤 단서? – mass441