带Glide的GPUImageView

时间:2017-08-10 17:20:04

标签: java android gpuimage

我正在尝试实现一个名为GPUImageView的Android图像过滤器库。

我尝试使用它,如下面的代码所示:

 public static GPUImageView img_bg;
 img_bg = (GPUImageView) findViewById(R.id.img_bg);
 categoryAdapter1.setOnClickLIstner(new OnClickLIstner() {
                        @Override
                        public void onClick(View v, Image image, int pos) {
                            Glide.with(NameArt.this)
                                    .load(image.getDrawableId())
                                    .centerCrop()
                                    .dontAnimate()
                                    .into(img_bg);
                            img_bg.setVisibility(View.VISIBLE);
                        }
                    });

但是我收到了一个错误:

  

无法解决方法'into'(jp.co.cyberagent.android.gpuimage.GPUImageView

有谁知道如何解决这个问题?感谢

3 个答案:

答案 0 :(得分:0)

GPUImageView不是ImageView的子类。编写com.bumptech.glide.request.target.Target的自定义子类,其覆盖onResourceReady以调用GPUImageView::setImage(Bitmap)

答案 1 :(得分:0)

这将帮助您解决这个问题。

  Glide.with(getApplicationContext()).load( IMAGE )
            .asBitmap()
            .into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                    BITMAP= resource;
                }
            });

并在下面编译glide版本。

    compile 'com.github.bumptech.glide:glide:3.7.0'

答案 2 :(得分:0)

如前所述,GPUImageView不是ImageView的子类。使用Glide 4.9.0和GPUImage 2.0.4,

添加您的布局

    <jp.co.cyberagent.android.gpuimage.GPUImageView
    android:id="@+id/picture_player"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:gpuimage_show_loading="false"
    app:gpuimage_surface_type="texture_view"
    />

以及您的代码中

            val pp = findViewById<GPUImageView>(R.id.picture_player)

        Glide.with(this).asBitmap()
            .load(uri)
            .into(object : CustomViewTarget<GPUImageView, Bitmap>(pp) {
                override fun onResourceReady(
                    resource: Bitmap,
                    transition: Transition<in Bitmap>?
                ) {
                    pp.setImage(resource)
                }

                override fun onLoadFailed(errorDrawable: Drawable?) {
                    //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
                }

                override fun onResourceCleared(placeholder: Drawable?) {
                    //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
                }
            })
相关问题