有没有办法将图像作为位图加载到 Glide [英] Is there a way to load image as bitmap to Glide

查看:32
本文介绍了有没有办法将图像作为位图加载到 Glide的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用位图作为 Glide 输入的方法.我什至不确定它是否可能.它用于调整大小.Glide 具有良好的图像增强与比例.问题是我有资源作为位图已经加载到内存中.我能找到的唯一解决方案是将图像存储到临时文件,然后将它们作为 inputStream/file 重新加载回 Glide.. 有没有更好的方法来实现这一点?

Im looking for a way to use bitmap as input to Glide. I am even not sure if its possible. It's for resizing purposes. Glide has a good image enhancement with scale. The problem is that I have resources as bitmap already loaded to memory. The only solution I could find is to store images to temporary file and reload them back to Glide as inputStream/file.. Is there a better way to achieve that ?

请在回答之前.. 我​​不是在谈论 Glide 的输出.. .asBitmap().get() 我知道.我需要输入方面的帮助.

Please before answering .. Im not talking about output from Glide.. .asBitmap().get() I know that.I need help with input.

这是我的解决方法:

 Bitmap bitmapNew=null;
        try {
            //
            ContextWrapper cw = new ContextWrapper(ctx);
            File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
            File file=new File(directory,"temp.jpg");
            FileOutputStream fos = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
            fos.close();
            //
            bitmapNew = Glide
                    .with(ctx)
                    .load(file)
                    .asBitmap()
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .skipMemoryCache(true)
                    .into( mActualWidth, mActualHeight - heightText)
                    .get();

            file.delete();
        } catch (Exception e) {
            Logcat.e( "File not found: " + e.getMessage());
        }

我想避免将图像写入内部并再次加载它们.这就是为什么我问是否有办法将输入作为位图

I'd like to avoid writing images to internal and load them again.That is the reason why Im asking if there is way to to have input as bitmap

谢谢

推荐答案

对于版本 4 你必须在 load()

For version 4 you have to call asBitmap() before load()

GlideApp.with(itemView.getContext())
        .asBitmap()
        .load(data.getImageUrl())
        .into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {}
            });
        }

更多信息:http://bumptech.github.io/glide/doc/targets.html

这篇关于有没有办法将图像作为位图加载到 Glide的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆