Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Glide在图像视图中加载图像需要很多时间_Android_Android Imageview_Android Bitmap_Android Glide - Fatal编程技术网

Android Glide在图像视图中加载图像需要很多时间

Android Glide在图像视图中加载图像需要很多时间,android,android-imageview,android-bitmap,android-glide,Android,Android Imageview,Android Bitmap,Android Glide,我正在使用glide在图像视图中加载图像,但在图像视图中显示图像需要很多时间。我正在图像视图中从自定义相机加载图片。每件事都在工作,但加载图像需要很多时间。下面是代码: private void show_image_from_custom_camera(byte[] data) { bitmap_image = BitmapFactory.decodeByteArray(data, 0, data.length); ByteArrayOutputStream stream

我正在使用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
                            }
                        });



            }
private void显示来自自定义摄像机的图像(字节[]数据){
位图_image=BitmapFactory.decodeByteArray(数据,0,数据.长度);
ByteArrayOutputStream=新建ByteArrayOutputStream();位图_image.compress(bitmap.CompressFormat.JPEG,70,流);
int屏幕宽度=宽度;
int屏幕高度=高度;
用(这个)滑翔
.加载(数据)
.asBitmap().centerCrop()
.into(新的SimpleTarget(宽度、高度){
@凌驾

public void onResourceReady(位图资源,GlideAnimation多亏了Belzebub。很抱歉,我犯了一个严重的错误,忘记删除代码的前3行:

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

没有它们,一切都很好,我正在以更快的速度在图像视图中加载图像,现在我保留此帖子,以便任何人都想在相机上在图像视图中加载图像。PictureCallback可以使用此代码,而无需使用前3行。

多亏了Belzebub。很遗憾,我犯了一个严重错误,忘了删除图像的前3行这些代码是:

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

没有它们,一切正常,我正在以更快的速度在图像视图中加载图像,现在我保留此帖子,以便任何人都想在相机上在图像视图中加载图像。PictureCallback可以使用此代码,而无需前3行。

如果不旋转位图,它是否显示得足够快?不,它需要相同的时间。分辨率是多少n您的位图?在这种情况下,glide似乎没有用,因为您已经解码了位图,保存它并使用glide再次解码。我的建议是运行以下代码
bitmap\u image=BitmapFactory.decodebytarray(data,0,data.length);ByteArrayOutputStream=newbytearrayoutputstream();bitmap\u image.compress(位图.CompressFormat.JPEG,70,流)
async我已经编辑了代码现在所有这些行都被删除了我忘了删除@belzebub如果你不旋转位图,它是否显示得足够快?不,它需要相同的时间。你的位图的分辨率是多少?在这种情况下,滑动似乎是无用的,因为你已经解码了位图,保存它并再次解码在使用glide时,我的建议是运行以下代码
bitmap\u image=BitmapFactory.decodeByteArray(data,0,data.length);ByteArrayOutputStream-stream=new ByteArrayOutputStream();bitmap\u image.compress(bitmap.CompressFormat.JPEG,70,stream);
async我已经编辑了代码,现在所有这些行都按照您的建议删除了,我忘记删除它们@Belzebub