[英]GPUImageView with Glide
我正在嘗試實現一個名為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);
}
});
但我收到一個錯誤:
無法解析方法“進入”(
jp.co.cyberagent.android.gpuimage.GPUImageView
)
有誰知道如何解決這個問題? 謝謝
GPUImageView
不是 ImageView 的子類。 編寫com.bumptech.glide.request.target.Target
的自定義子類,覆蓋onResourceReady
以調用GPUImageView::setImage(Bitmap)
這將幫助您解決該問題。
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'
如前所述,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.
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.