3

デバイスから取得した画像とテキストを使用してリストを作成しようとしています。携帯電話のカメラからの画像を携帯電話から取得するのは時間がかかる作業であることが判明したため、ユーザーエクスペリエンスが遅くならないようにできるだけ高速にしようとしています. これから得たのは、すべての画像が1つにロードされ、画像がImageView他のすべてに広がっているように見えることだけです(テクニックとカスタムImageViewsの実装が正しいかどうかは完全にはわかりません)。ViewHolderCursorAdapter

public class MyCustomCurserAdapter extends CursorAdapter {
  static class ViewHolder {
    public TextView nameText;
    public ImageView imageThumbnail;
  }


  Cursor cursor;

  public MyCustomCurserAdapter(Context context, Cursor c, int flags) {
    super(context, c, flags);
    // TODO Auto-generated constructor stub
  }

  @Override
  public void bindView(View view, Context arg1, Cursor cursor) {

    ViewHolder holder = (ViewHolder)view.getTag();


    int pathCol = cursor.getColumnIndex(NewPicSQLiteHelper.COLUMN_PATH);
    String imageInSD = cursor.getString(pathCol);  
    File imgFile = new  File(imageInSD);

    if(imgFile.exists()){

        int nameCol = cursor.getColumnIndex(NewPicSQLiteHelper.COLUMN_PIC_NAME);
        String name = cursor.getString(nameCol);

        if (name != null) 
            holder.nameText.setText(name);

        ImageTask task = new ImageTask(holder.imageThumbnail);
        task.execute(imgFile);
    }

  }

  @Override
  public View newView(Context arg0, Cursor cur, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    View view = inflater.inflate(R.layout.new_pic_item, parent, false);
    ViewHolder holder = new ViewHolder();

    holder = new ViewHolder();
    holder.nameText = (TextView) view.findViewById(R.id.pic_name_entry);
    holder.imageThumbnail = (ImageView) view.findViewById(R.id.pic_thumbnail);

    // The tag can be any Object, this just happens to be the ViewHolder
    view.setTag(holder);


    return view;
  }


  private class ImageTask extends AsyncTask<File, Void, Bitmap>{
    private final WeakReference <ImageView> imageViewReference;

    public ImageTask(ImageView imageView) {
        imageViewReference = new WeakReference <ImageView> (imageView);
    }

    @Override
    protected Bitmap doInBackground(File... params) {
        String path = params[0].getAbsolutePath();

        return decodeSampledBitmapFromResource(path,75,75);
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        if (imageViewReference != null) {
            ImageView imageView = imageViewReference.get();
            if (imageView != null) {
                if (result != null) {
                    imageView.setImageBitmap(result);
                    imageView.setVisibility(ImageView.VISIBLE);
                } else {
                                    imageView.setVisibility(ImageView.INVISIBLE);
                }
            }

        }

    }

    private Bitmap decodeSampledBitmapFromResource(String orgImagePath, int reqWidth, int reqHeight) {


    }

    private int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {

  }
}
4

2 に答える 2

0

ImageTask AsyncTask を削除します ..

GlidePicassoなどのライブラリを使用します。リモート画像を取得、サイズ変更、および表示する必要があるほとんどすべての場合に非常に効果的です。

電話ストレージ uriから画像を読み込むためにグライドを使用しました

上記のいずれかを使用して違いを確認してください

于 2017-01-08T09:41:29.183 に答える
0

時間がかかる理由として考えられるのは、画像のサイズが少なくとも 1 mb 以上になるため、サムネイルに変更して取得することができます。また、まだ時間がかかる場合は、サーバーから画像を取得するときに行われる遅延ダウンロードを行うことができます。 (基本的には、テキストを読み込んで、画像を取得したときに画像を表示することです)

于 2013-10-06T15:49:26.940 に答える