Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid not showing any JPEG images
    primarykey
    data
    text
    <p>Android Emulator shows blank screen, images still opens up (assuming that 150,150 pics are there). In another word, my 150,150 thumbs are behind the blank screen</p> <p>My images are larger than 150*150, I followed the link below to load large bitmap efficiently, but it still doesnt work.</p> <p><a href="http://developer.android.com/training/displaying-bitmaps/load-bitmap.html" rel="nofollow">http://developer.android.com/training/displaying-bitmaps/load-bitmap.html</a></p> <p>These is my code in imageAdapter</p> <pre><code>public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if(reqHeight + reqWidth == 0){ return inSampleSize; } else if (height &gt; reqHeight || width &gt; reqWidth) { // Calculate ratios of height and width to requested height and width final int heightRatio = Math.round((float) height / (float) reqHeight); final int widthRatio = Math.round((float) width / (float) reqWidth); // Choose the smallest ratio as inSampleSize value, this will guarantee // a final image with both dimensions larger than or equal to the // requested height and width. inSampleSize = heightRatio &lt; widthRatio ? heightRatio : widthRatio; } return inSampleSize; } public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(res, resId, options); } </code></pre> <p>I have also added my full imageAdapter class for more information.</p> <pre><code>package com.example.first; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; import android.util.Log; public class ImageAdapter extends BaseAdapter{ private Context mContext; public Integer[] mThumbIds = { R.drawable.h18, R.drawable.h17, R.drawable.h16, R.drawable.h15, }; public ImageAdapter(Context c) { mContext = c; } @Override public int getCount() { return mThumbIds.length; } @Override public Object getItem(int position) { return mThumbIds[position]; } @Override public long getItemId(int position) { return 0; } public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if(reqHeight + reqWidth == 0){ return inSampleSize; } else if (height &gt; reqHeight || width &gt; reqWidth) { // Calculate ratios of height and width to requested height and width final int heightRatio = Math.round((float) height / (float) reqHeight); final int widthRatio = Math.round((float) width / (float) reqWidth); // Choose the smallest ratio as inSampleSize value, this will guarantee // a final image with both dimensions larger than or equal to the // requested height and width. inSampleSize = heightRatio &lt; widthRatio ? heightRatio : widthRatio; } return inSampleSize; } public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(res, resId, options); } @Override public View getView(int position, View convertView, ViewGroup parent) { ImageView imageview; if(convertView == null){ imageview = new ImageView(mContext); imageview.setScaleType(ImageView.ScaleType.FIT_XY); imageview.setLayoutParams(new GridView.LayoutParams(150,150)); imageview.setPadding(8, 8, 8, 8); }else{ imageview = (ImageView) convertView; } imageview.setImageBitmap(decodeSampledBitmapFromResource( null, mThumbIds[position], 150, 150)); return imageview; } private Resources getResources() { // TODO Auto-generated method stub return null; } } </code></pre> <p>Any help with this appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload