GithubHelp home page GithubHelp logo

Bitmaps from sdcard about lazylist HOT 2 OPEN

thest1 avatar thest1 commented on August 29, 2024
Bitmaps from sdcard

from lazylist.

Comments (2)

thest1 avatar thest1 commented on August 29, 2024

Unfortunately I can't tell you what's wrong. You should just debug and find
where exactly it goes wrong.

Also if you have images on SD you don't need to cache them to SD once
again. So you could remove everything related to SD cache.

2012/10/22 kormateusz [email protected]

Hi, I was trying to change this code to show bitmaps from sdcard instead
of the internet. I've changed this part of the code:

private Bitmap getBitmap(String url)
{
File f=fileCache.getFile(url);

//from SD cache
Bitmap b = decodeFile(f);
if(b!=null)
    return b;

//from web
try {
    Bitmap bitmap=null;
    URL imageUrl = new URL(url);
    HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
    conn.setConnectTimeout(30000);
    conn.setReadTimeout(30000);
    conn.setInstanceFollowRedirects(true);
    InputStream is=conn.getInputStream();
    OutputStream os = new FileOutputStream(f);
    Utils.CopyStream(is, os);
    os.close();
    bitmap = decodeFile(f);
    return bitmap;
} catch (Throwable ex){
   ex.printStackTrace();
   if(ex instanceof OutOfMemoryError)
       memoryCache.clear();
   return null;
}

}

to this:

private Bitmap getBitmap(String url)
{
File f=fileCache.getFile(url);

//from SD cache
Bitmap b = decodeFile(f);
if(b!=null)
    return b;

//from sdcard
try {
    Bitmap bitmap=null;
    InputStream is=new FileInputStream(url);
    OutputStream os = new FileOutputStream(f);
    Utils.CopyStream(is, os);
    os.close();
    bitmap = decodeFile(f);
    return bitmap;
} catch (Throwable ex){
   ex.printStackTrace();
   if(ex instanceof OutOfMemoryError)
       memoryCache.clear();
   return null;
}

}

And I've used my ArrayAdapter:

public class AdapterFiles extends ArrayAdapter{
private int resource;

private String item;
private ViewHolder viewHolder;

public ImageLoader imageLoader;

public AdapterFiles(Context context, int textViewResourceId, int label, List objects) {
super(context, textViewResourceId, objects);

resource = textViewResourceId;
imageLoader=new ImageLoader(getContext());

}

static class ViewHolder {
TextView label;
ImageView ikonka;

}

@OverRide
public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout RowView;
item = getItem(position);

    if(convertView == null) {
    RowView = new RelativeLayout(getContext());
    LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(resource, RowView, true);
    viewHolder = new ViewHolder();
    viewHolder.label = (TextView)RowView.findViewById(R.id.label);
    viewHolder.ikonka = (ImageView)RowView.findViewById(R.id.icon);
    …
    RowView.setTag(viewHolder);
    } else {
        RowView = (RelativeLayout)convertView;
        viewHolder = (ViewHolder) RowView.getTag();
    }


        …

    File file = new File(item);
    if (file.isDirectory()){
        if(file.canRead()){
        viewHolder.ikonka.setImageResource(R.drawable.folder);
        }
        else{
        viewHolder.ikonka.setImageResource(R.drawable.foldernoway);
        }
    …

    else if(item.endsWith(".jpg") || item.endsWith(".JPG") || item.endsWith(".png") || item.endsWith(".jpeg")){



        if(thumbnails == false){
        viewHolder.ikonka.setImageResource(R.drawable.image);
        }else{


            imageLoader.DisplayImage(item, viewHolder.ikonka);


        }
        }
    …



    viewHolder.label.setText(file.getName());

    …

    return RowView;

}

And now, I have two problems..

  1. Images don't appear when I scroll listview down. I have to scroll down,
    up and again down to view images. How can I fix it?
  2. How to resize bitmaps in the cache folder?


Reply to this email directly or view it on GitHubhttps://github.com//issues/23.

from lazylist.

karthickkumar avatar karthickkumar commented on August 29, 2024

@kormateusz @thest1 Yeah its working correctly as per @kormateusz change.Nothing need to change,its enough to load the image from sdcard. May be problem in adapter getview method,@kormateusz need to debug.

from lazylist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.