Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.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
Java 滑动Android编码_Java_Android_Bitmap_Android Glide - Fatal编程技术网

Java 滑动Android编码

Java 滑动Android编码,java,android,bitmap,android-glide,Java,Android,Bitmap,Android Glide,我不知道如何用Glide编码位图。在过去的方式中,我有私有位图全局初始化位图,并设置 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 1 &

我不知道如何用Glide编码位图。在过去的方式中,我有
私有位图全局初始化位图,并设置

    @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);

            if (requestCode == 1 && resultCode == RESULT_OK) {
                Uri filePath = data.getData();
                try {
                    bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
imageView.setImageBitmap(bitmap);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }
但这种方式会消耗太多内存。然后我换成

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == 1 && resultCode == RESULT_OK) {
            Uri filePath = data.getData();
       //   load Glide to imageView  
           Glide.with(this)
                    .load(filePath)
                    .into(imageView);

       //   set bitmap variable
            bitmap = Glide.with(this)
                    .load(filePath)
                    .asBitmap()
                    .into(100,100).get();
        }
    }
一切看起来都很好,加载图像时速度更快。当我必须用

public String getBitmapToString(Bitmap bitmap) {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
        byte[] imageBytes = byteArrayOutputStream.toByteArray();
        String encoded = Base64.encodeToString(imageBytes, Base64.DEFAULT);
        return encoded;
    }
它显示java中的致命异常,以及使用
getBitmapToString()
方法转换位图时出错。有什么解决办法吗?

Glide.with(这个)
  Glide.with(this)
                .load(filePath)
                .asBitmap()
                .override(size, size) //if you want particular size
                .into(new SimpleTarget<Bitmap>() {

                    @Override
                    public void onResourceReady(Bitmap bitmap,   GlideAnimation anim) {
                        imageView.setImage(ImageSource.bitmap(bitmap));
                        thumbView.setImageBitmap(bitmap);
                    }
                });
.load(文件路径) .asBitmap() .override(size,size)//如果需要特定的大小 .into(新的SimpleTarget(){ @凌驾 public void onResourceReady(位图、动画){ setImage(ImageSource.bitmap(位图)); thumbView.setImageBitmap(位图); } });
为什么要投否决票??你试过这个吗?嘿嘿,我没有投你一票。我尝试过那个代码,但没有工作。不过还是谢谢你。