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

查看:145
本文介绍了有没有一种方法可以将图像作为位图加载到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天全站免登陆