1. Are you ready for the Galaxy S20? Here is everything we know so far!

Decoding Bitmaps

Discussion in 'Android Development' started by Millamber, Dec 13, 2013.

  1. Millamber

    Millamber Lurker
    Thread Starter

    I am trying to move a set of images currently in the resources/drawable-hdpi folder to the Assets folder.

    These images are copied to the private application directory when the app is installed.

    When I do this the resulting image is smaller than when I had the image in the resources folder. i.e. the baked beans image is smaller than the others. If I load the baked beans images from the drawables folder it is the same size as the other product images.

    I have tried to scale the image but it has no effect.

    Any ideas as to what is causing this would be greatly appreciated.

    public View getView(int position, View convertView, ViewGroup parent)
    {

    ImageView imView = (ImageView)rowView.findViewById(R.id.product_thumbnail);
    ImageView imProduct = (ImageView)rowView.findViewById(R.id.product_icon);
    tvName.setText((CharSequence) values.get(position).getName());

    dirPath = context.getFilesDir().getAbsolutePath() + File.separator + "images" + File.separator + "products" + File.separator;
    projDir = new File(dirPath);
    if (!projDir.exists())
    {
    projDir.mkdirs();
    }

    if(values.get(position).getName().equals("Baked Beans"))
    {
    String imageName = values.get(position).getImageName();


    Bitmap bitmap = BitmapFactory.decodeFile(dirPath + imageName + "_sm.jpg");
    imView.setImageBitmap(bitmap);

    }
    else
    {
    int resID = context.getResources().getIdentifier("packagename:drawable/" + values.get(position).getImageName() + "_sm", null, "packagename");
    imView.setImageResource(resID);
    }

    return rowView;[/SIZE]
    }
     

    Attached Files:




    1. Download the Forums for Android™ app!


      Download

       
  2. GeorgeN

    GeorgeN Well-Known Member

    The default behaviour of BitmapFactory is to scale bitmaps to match your devices screen density. You can pass it a BitmapFactory.Options object to disable this behaviour.
     
    alostpacket likes this.
  3. Millamber

    Millamber Lurker
    Thread Starter

    Thanks George,

    Worked a treat.

    Much appreciated :)
     
  4. alostpacket

    alostpacket Over Macho Grande?

  5. Millamber

    Millamber Lurker
    Thread Starter

    Thanks alostpacket,

    Very useful and helpful.



    Millamber:)
     
Loading...

Share This Page

Loading...