Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.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 recyclerView没有';不要显示图像_Java_Android_Android Recyclerview_Bitmap_Display - Fatal编程技术网

Java recyclerView没有';不要显示图像

Java recyclerView没有';不要显示图像,java,android,android-recyclerview,bitmap,display,Java,Android,Android Recyclerview,Bitmap,Display,我试图在recyclerView中显示图像,但它不显示位图。 我不知道怎么了 这是我的适配器: @Override public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) { final byte[] data = arrayList.get(position).getAsByteArray("byteArray"); try { S

我试图在recyclerView中显示图像,但它不显示位图。 我不知道怎么了

这是我的适配器:

@Override
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
    final byte[] data = arrayList.get(position).getAsByteArray("byteArray");

    try {
        String tempImagePath = Environment.getExternalStorageDirectory().getPath() + "/AHOORATempImage";
        FileOutputStream fileOutputStream = new FileOutputStream(tempImagePath);
        fileOutputStream.write(data);
        fileOutputStream.flush();
        fileOutputStream.close();

        holder.image.setImageBitmap(BitmapFactory.decodeStream(new FileInputStream(tempImagePath)));

        new File(tempImagePath).delete();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
这是我的项目的xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.cardview.widget.CardView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:cardCornerRadius="3dp">
    <ImageView
        android:id="@+id/addContentGalleryImage"
        android:layout_width="300dp"
        android:layout_height="300dp"/>
</androidx.cardview.widget.CardView>

谢谢

你可以使用它,它很容易使用,尤其对Url图像非常有帮助。 下面是一个在onBindViewHolder中使用的示例

Picasso.get()
            //Image url or path
            .load(channelImgUrl.get(position))
            //This line optional if you want a circle Image shape
            .transform(new CropCircleTransformation())
            //Image View
            .into(holder.channelImg);

onBindViewHolder
中执行任何计算都不是一个好主意,因为此方法应该只绑定视图和就绪项。尝试将图像保存在内存(但要小心OOM)或文件中,并根据准备好的图像进行渲染,不要将其删除。此外,logcat中是否有任何与RecyclerView相关或与文件/图像处理相关的消息?最后我发现问题在于byteArray,因为我也使用了Glide,但再次没有结果。无法显示byteArray的原因是什么。你能帮忙吗??谢谢,对不起,没用。最后我发现问题在于byteArray,因为我也使用了Glide,但再次没有结果。无法显示byteArray的原因是什么。你能帮忙吗??谢谢