【发布时间】:2017-06-02 11:28:47
【问题描述】:
我正在使用 glide 在图像视图中加载图像,但在图像视图中显示图像需要很多时间。我正在图像视图中从我的自定义相机加载图片。一切正常,但是加载图像需要很长时间,这里是代码:
private void show_image_from_custom_camera(byte[] data) {
bitmap_image = BitmapFactory.decodeByteArray(data, 0, data.length);
ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap_image.compress(Bitmap.CompressFormat.JPEG, 70, stream);
int screenWidth = width;
int screenHeight = height;
Glide.with(this)
.load(data)
.asBitmap().centerCrop()
.into(new SimpleTarget<Bitmap>(width,height) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
// you can do something with loaded bitmap here
// .....
int w = resource.getWidth();
int h = resource.getHeight();
// Setting post rotate to 90
Matrix mtx = new Matrix();
mtx.postRotate(90);
// Rotating Bitmap
Bitmap realImage = Bitmap.createBitmap(resource, 0, 0, w, h, mtx, true);
photo_setter.setImageBitmap(realImage); //setting the image in image-view
}
});
}
有什么可以减少这个时间的吗?我想以更快的速度在图像视图中显示图像。
【问题讨论】:
-
不旋转位图是否显示得足够快?
-
不,它需要相同的时间。
-
你的位图分辨率是多少?
-
well glide 在这种情况下似乎没用,因为您已经解码了位图,保存并使用 glide 再次解码。我的建议是运行此代码
bitmap_image = BitmapFactory.decodeByteArray(data, 0, data.length); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap_image.compress(Bitmap.CompressFormat.JPEG, 70, stream);async -
我已经编辑了代码,现在你建议的所有这些行都被删除了我忘记删除它们@Belzebub
标签: android android-imageview android-bitmap android-glide