private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException { File targetFile = this.configuration.diskCache.get(this.uri); if (targetFile == null || !targetFile.exists()) { return false; } Bitmap bmp = this.decoder.decode(new ImageDecodingInfo(this.memoryCacheKey, Scheme.FILE.wrap(targetFile.getAbsolutePath()), this.uri, new ImageSize(maxWidth, maxHeight), ViewScaleType.FIT_INSIDE, getDownloader(), new Builder().cloneFrom(this.options).imageScaleType(ImageScaleType.IN_SAMPLE_INT).build())); if (!(bmp == null || this.configuration.processorForDiskCache == null)) { L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, this.memoryCacheKey); bmp = this.configuration.processorForDiskCache.process(bmp); if (bmp == null) { L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, this.memoryCacheKey); } } if (bmp == null) { return false; } boolean saved = this.configuration.diskCache.save(this.uri, bmp); bmp.recycle(); return saved; }
public InputStream getStream(String imageUri, Object extra) throws IOException { switch (Scheme.ofUri(imageUri)) { case HTTP: case HTTPS: return getStreamFromNetwork(imageUri, extra); case FILE: return getStreamFromFile(imageUri, extra); case CONTENT: return getStreamFromContent(imageUri, extra); case ASSETS: return getStreamFromAssets(imageUri, extra); case DRAWABLE: return getStreamFromDrawable(imageUri, extra); default: return getStreamFromOtherSource(imageUri, extra); } }
private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException { File targetFile = this.configuration.diskCache.get(this.uri); if (targetFile == null || !targetFile.exists()) { return false; } Bitmap bmp = this.decoder.decode(new ImageDecodingInfo(this.memoryCacheKey, Scheme.FILE .wrap(targetFile.getAbsolutePath()), this.uri, new ImageSize(maxWidth, maxHeight) , ViewScaleType.FIT_INSIDE, getDownloader(), new Builder().cloneFrom(this .options).imageScaleType(ImageScaleType.IN_SAMPLE_INT).build())); if (!(bmp == null || this.configuration.processorForDiskCache == null)) { L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, this.memoryCacheKey); bmp = this.configuration.processorForDiskCache.process(bmp); if (bmp == null) { L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, this.memoryCacheKey); } } if (bmp == null) { return false; } boolean saved = this.configuration.diskCache.save(this.uri, bmp); bmp.recycle(); return saved; }
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); setContentView(R.layout.zg_activity_media_camera_preview); findViewById(R.id.iv_left).setOnClickListener(this); findViewById(R.id.tv_right).setOnClickListener(this); ((TextView) findViewById(R.id.title)) .setText(R.string.zg_content_media_pic_preview); mProgress = (ProgressBar) findViewById(R.id.progressBar); mImageView = (ImageView) findViewById(R.id.imageview); mMediaInfo = (MediaInfo) getIntent().getExtras().getSerializable( MediaConstants.MEDIA_REQUEST_DATAS); ViewerImageLoader.getInstance().displayImage( Scheme.FILE.wrap(mMediaInfo.filePath), mImageView, this); }
/** Decodes image file into Bitmap, resize it and save it back */ private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException { // Decode image file, compress and re-save it boolean saved = false; File targetFile = configuration.diskCache.get(uri); if (targetFile != null && targetFile.exists()) { ImageSize targetImageSize = new ImageSize(maxWidth, maxHeight); DisplayImageOptions specialOptions = new DisplayImageOptions.Builder().cloneFrom(options) .imageScaleType(ImageScaleType.IN_SAMPLE_INT).build(); ImageDecodingInfo decodingInfo = new ImageDecodingInfo(memoryCacheKey, Scheme.FILE.wrap(targetFile.getAbsolutePath()), uri, targetImageSize, ViewScaleType.FIT_INSIDE, getDownloader(), specialOptions); Bitmap bmp = decoder.decode(decodingInfo); if (bmp != null && configuration.processorForDiskCache != null) { L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, memoryCacheKey); bmp = configuration.processorForDiskCache.process(bmp); if (bmp == null) { L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, memoryCacheKey); } } if (bmp != null) { saved = configuration.diskCache.save(uri, bmp); bmp.recycle(); } } return saved; }
protected ExifInfo defineExifOrientation(String imageUri) { int rotation = 0; boolean flip = false; try { ExifInterface exif = new ExifInterface(Scheme.FILE.crop(imageUri)); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exifOrientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: flip = true; case ExifInterface.ORIENTATION_NORMAL: rotation = 0; break; case ExifInterface.ORIENTATION_TRANSVERSE: flip = true; case ExifInterface.ORIENTATION_ROTATE_90: rotation = 90; break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: flip = true; case ExifInterface.ORIENTATION_ROTATE_180: rotation = 180; break; case ExifInterface.ORIENTATION_TRANSPOSE: flip = true; case ExifInterface.ORIENTATION_ROTATE_270: rotation = 270; break; } } catch (IOException e) { L.w("Can't read EXIF tags from file [%s]", imageUri); } return new ExifInfo(rotation, flip); }
@Test public void testSchemeHttp() throws Exception { String uri = "http://image.com/1.png"; Scheme result = Scheme.ofUri(uri); Scheme expected = Scheme.HTTP; Assertions.assertThat(result).isEqualTo(expected); }
@Test public void testSchemeHttps() throws Exception { String uri = "https://image.com/1.png"; Scheme result = Scheme.ofUri(uri); Scheme expected = Scheme.HTTPS; Assertions.assertThat(result).isEqualTo(expected); }
@Test public void testSchemeContent() throws Exception { String uri = "content://path/to/content"; Scheme result = Scheme.ofUri(uri); Scheme expected = Scheme.CONTENT; Assertions.assertThat(result).isEqualTo(expected); }
@Test public void testSchemeAssets() throws Exception { String uri = "assets://folder/1.png"; Scheme result = Scheme.ofUri(uri); Scheme expected = Scheme.ASSETS; Assertions.assertThat(result).isEqualTo(expected); }
@Test public void testSchemeDrawables() throws Exception { String uri = "drawable://123456890"; Scheme result = Scheme.ofUri(uri); Scheme expected = Scheme.DRAWABLE; Assertions.assertThat(result).isEqualTo(expected); }
@Test public void testSchemeFile() throws Exception { String uri = "file://path/on/the/device/1.png"; Scheme result = Scheme.ofUri(uri); Scheme expected = Scheme.FILE; Assertions.assertThat(result).isEqualTo(expected); }
@Test public void testSchemeUnknown() throws Exception { String uri = "other://image.com/1.png"; Scheme result = Scheme.ofUri(uri); Scheme expected = Scheme.UNKNOWN; Assertions.assertThat(result).isEqualTo(expected); }
public InputStream getStream(String imageUri, Object extra) throws IOException { switch (Scheme.ofUri(imageUri)) { case HTTP: case HTTPS: throw new IllegalStateException(); default: return this.wrappedDownloader.getStream(imageUri, extra); } }
public InputStream getStream(String imageUri, Object extra) throws IOException { InputStream imageStream = this.wrappedDownloader.getStream(imageUri, extra); switch (Scheme.ofUri(imageUri)) { case HTTP: case HTTPS: return new FlushedInputStream(imageStream); default: return imageStream; } }
/** * Decodes image file into Bitmap, resize it and save it back */ private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException { // Decode image file, compress and re-save it boolean saved = false; File targetFile = configuration.diskCache.get(uri); if (targetFile != null && targetFile.exists()) { ImageSize targetImageSize = new ImageSize(maxWidth, maxHeight); DisplayImageOptions specialOptions = new DisplayImageOptions.Builder().cloneFrom(options) .imageScaleType(ImageScaleType.IN_SAMPLE_INT).build(); ImageDecodingInfo decodingInfo = new ImageDecodingInfo(memoryCacheKey, Scheme.FILE.wrap(targetFile.getAbsolutePath()), uri, targetImageSize, ViewScaleType.FIT_INSIDE, getDownloader(), specialOptions); Bitmap bmp = decoder.decode(decodingInfo); if (bmp != null && configuration.processorForDiskCache != null) { L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, memoryCacheKey); bmp = configuration.processorForDiskCache.process(bmp); if (bmp == null) { L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, memoryCacheKey); } } if (bmp != null) { saved = configuration.diskCache.save(uri, bmp); bmp.recycle(); } } return saved; }
protected InputStream getStreamFromFile(String imageUri, Object extra) throws IOException { String filePath = Scheme.FILE.crop(imageUri); if (isVideoFileUri(imageUri)) { return getVideoThumbnailStream(filePath); } return new ContentLengthInputStream(new BufferedInputStream(new FileInputStream(filePath) , 32768), (int) new File(filePath).length()); }
/** Decodes image file into Bitmap, resize it and save it back */ private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException { // Decode image file, compress and re-save it boolean saved = false; File targetFile = configuration.diskCache.get(memoryCacheKey); if (targetFile != null && targetFile.exists()) { ImageSize targetImageSize = new ImageSize(maxWidth, maxHeight); DisplayImageOptions specialOptions = new DisplayImageOptions.Builder().cloneFrom(options) .imageScaleType(ImageScaleType.IN_SAMPLE_INT).build(); ImageDecodingInfo decodingInfo = new ImageDecodingInfo(memoryCacheKey, Scheme.FILE.wrap(targetFile.getAbsolutePath()), uri, targetImageSize, ViewScaleType.FIT_INSIDE, getDownloader(), specialOptions); Bitmap bmp = decoder.decode(decodingInfo); if (bmp != null && configuration.processorForDiskCache != null) { L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, memoryCacheKey); bmp = configuration.processorForDiskCache.process(bmp); if (bmp == null) { L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, memoryCacheKey); } } if (bmp != null) { saved = configuration.diskCache.save(memoryCacheKey, bmp); bmp.recycle(); } } return saved; }