有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用Glide的java图像比较模糊

我尝试使用Glide在Recyclerview中显示图像,但图像模糊(图像为jpg格式)

我曾尝试用毕加索来展示它们,但我得到了完全相同的问题:图像模糊。作为一个测试,我也有10个抽屉,这些似乎显示刚刚好。有人知道为什么图像模糊吗

**编辑**

我只是在(Genymotion仿真器)Google Galaxy Nexus 4.2.2上运行了我的代码;API 17和图像都很好!所以下一个问题是为什么在(Genymotion仿真器)摩托罗拉MOTOX4.3上图像模糊;API 18

**编辑**

我想我已经找到了我的图像模糊的原因: 在我的主要片段中,我通过自定义内容提供者将图像的URL写入数据库。我的初始图像分辨率较低,因此当我显示它们时,由于调整大小和格式,它们变得模糊。因此,我使用了更高分辨率的图像,希望这能解决这个问题。起初,它没有(沮丧!!),直到我更改了数据库版本号。然后将新图像写入数据库,问题就解决了

package demo.example.com.customarrayadapter;

import 安卓.content.Context;
import 安卓.database.Cursor;
import 安卓.support.v7.widget.RecyclerView;
import 安卓.util.Log;
import 安卓.view.LayoutInflater;
import 安卓.view.View;
import 安卓.view.ViewGroup;
import 安卓.widget.ImageView;
import 安卓.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import demo.example.com.customarrayadapter.data.FlavorsContract;

/**
 * Created by richard on 03/01/16.
 */
public class AndroidFlavorCursorRecyclerViewAdapter extends
        CursorRecyclerAdapter<AndroidFlavorCursorRecyclerViewAdapter
        .DataObjectHolder> {
    private static String LOG_TAG = AndroidFlavorCursorRecyclerViewAdapter.class.getSimpleName();
    private List<AndroidFlavor> mDataset;
    private static MyClickListener myClickListener;
    private Cursor mCursor;
    private int posterHeight;
    private int posterWidth;

    public static class DataObjectHolder extends RecyclerView.ViewHolder
            implements View
            .OnClickListener {
        TextView label;
        ImageView image;

        public DataObjectHolder(View itemView) {
            super(itemView);
            //label = (TextView) itemView.findViewById(R.id.flavor_text);
            image = (ImageView) itemView.findViewById(R.id.flavor_image);
            Log.i(LOG_TAG, "Adding Listener");
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            myClickListener.onItemClick(getPosition(), v);
        }
    }

    public void setOnItemClickListener(MyClickListener myClickListener) {
        this.myClickListener = myClickListener;
    }

    public AndroidFlavorCursorRecyclerViewAdapter(Cursor cursor, int w, int h) {
        super(cursor);
        //mCursor = cursor;
        posterHeight = h;
        posterWidth = w;
    }

    @Override
    public DataObjectHolder onCreateViewHolder(ViewGroup parent,
                                               int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.flavor_item, parent, false);

        DataObjectHolder dataObjectHolder = new DataObjectHolder(view);
        return dataObjectHolder;
    }


    @Override
    public void onBindViewHolderCursor(DataObjectHolder holder, Cursor cursor) {
        Context context = holder.image.getContext();

        //Log.i(LOG_TAG,"image:" + cursor.getString(
        //        cursor.getColumnIndex(FlavorsContract.FlavorEntry.COLUMN_FILM_POSTER)));

        //holder.label.setText(cursor.getString(
        //        cursor.getColumnIndex(FlavorsContract.FlavorEntry.COLUMN_VERSION_NAME)));
        String url = cursor.getString(
                cursor.getColumnIndex(FlavorsContract.FlavorEntry.COLUMN_FILM_POSTER));
        Glide.with(context.getApplicationContext()).load(url)
                .into(holder.image);

        //Picasso.with(context).load("http://i.imgur.com/DvpvklR.png")
        //        .into(holder.image);

        Log.v(LOG_TAG, "onBindViewHolderCursor() " + cursor.getCount());
    }

    //    public void addItem(AndroidFlavor dataObj, int index) {
    //    mDataset.add(dataObj);
    //    notifyItemInserted(index);
    //}

    //public void deleteItem(int index) {
    //    mDataset.remove(index);
    //    notifyItemRemoved(index);
    //}

    //@Override
    //public int getItemCount() {
    //    return mDataset.size();
    //}

    public interface MyClickListener {
        public void onItemClick(int position, View v);
    }

}

我想把我的imageview放在这里可能是个好主意:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
   >

        <demo.example.com.customarrayadapter.SquareImageView
            安卓:id="@+id/flavor_image"
            安卓:layout_width="match_parent"
            安卓:layout_height="wrap_content"
            安卓:layout_gravity="center_vertical"
            安卓:scaleType="centerCrop"
            />

</FrameLayout>

SquareImageView类:

import 安卓.content.Context;
import 安卓.util.AttributeSet;
import 安卓.widget.ImageView;

public class SquareImageView extends ImageView
{
    public SquareImageView(Context context)
    {
        super(context);
    }

    public SquareImageView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public SquareImageView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()*2); //Snap to width

    }
}

共 (2) 个答案

  1. # 1 楼答案

    您的问题很清楚,但您是否只尝试了那些模拟器? 为什么我没有找到那个。哪里都没有

    您确定您的图片已经调整大小,并且没有格式化,只是为了完全被看到吗

    如果是,请查看您的控制台。你看到这样的错误了吗

    W/OpenGLRenderer: Bitmap too large to be uploaded into a texture
    
  2. # 2 楼答案

    我的错!我是一个年轻人。超越

    加载图片后,请确保图片已正确调整大小,然后再将其发送到布局容器中:

    public Bitmap loadFormattedImage(Context c ,int imv_icone){
       Glide.with(c)
                .load(imv_icone)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .override(300, 200);
    
        return  BitmapFactory.decodeResource(c.getResources(), imv_icone);
    }
    

    你已经试过这个了吗