【问题标题】:Glide takes lot of time to load image in Image viewGlide 需要大量时间在图像视图中加载图像
【发布时间】: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


【解决方案1】:

感谢 Belzebub。好吧,我犯了一个严重的错误,我忘了删除代码的前 3 行:

    bitmap_image = BitmapFactory.decodeByteArray(data, 0, data.length); 
    ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
bitmap_image.compress(Bitmap.CompressFormat.JPEG, 70, stream);

没有它们,一切正常,我正在以更快的速度在图像视图中加载图像,现在我保留这篇文章,以便任何想要在 Camera.PictureCallback 上的图像视图中加载图像的人都可以在没有前 3 行的情况下使用此代码。

【讨论】:

    猜你喜欢
    • 2019-06-17
    • 2019-03-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 2017-10-18
    • 2016-06-23
    • 2021-08-17
    • 2013-11-30
    相关资源
    最近更新 更多