Google TV devices have higher display resolution. If you provide low resolution or small p_w_picpaths in your layouts, they will appear pixelated, fuzzy, or grainy. This is not a good experience for the user. Instead, use high resolution p_w_picpaths. Remember, though, that downloading and storing high-resolution p_w_picpaths may cause "out of memory" errors. To avoid these errors, follow these tips:
GridView
, ListView
or Gallery
, only load an p_w_picpath when its getView() is called. recycle()
on Bitmaps that are no longer needed.
- // Get the source p_w_picpath's dimensions
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true; // this does not download the actual p_w_picpath, just downloads headers.
- BitmapFactory.decodeFile(IMAGE_FILE_URL, options);
- int srcWidth = options.outWidth; // actual width of the p_w_picpath.
- int srcHeight = options.outHeight; // actual height of the p_w_picpath.
- // Only scale if the source is big enough. This code is just trying to fit a p_w_picpath into a certain width.
- if(desiredWidth > srcWidth)
- desiredWidth = srcWidth;
- // Calculate the correct inSampleSize/scale value. This helps reduce memory use. It should be a power of 2.
- int inSampleSize = 1;
- while(srcWidth / 2 > desiredWidth){
- srcWidth /= 2;
- srcHeight /= 2;
- inSampleSize *= 2;
- }
- float desiredScale = (float) desiredWidth / srcWidth;
- // Decode with inSampleSize
- options.inJustDecodeBounds = false; // now download the actual p_w_picpath.
- options.inDither = false;
- options.inSampleSize = inSampleSize;
- options.inScaled = false;
- options.inPreferredConfig = Bitmap.Config.ARGB_8888; // ensures the p_w_picpath stays as a 32-bit ARGB_8888 p_w_picpath.
- // This preserves p_w_picpath quality.
- Bitmap sampledSrcBitmap = BitmapFactory.decodeFile(IMAGE_FILE_URL, options);
- // Resize
- Matrix matrix = new Matrix();
- matrix.postScale(desiredScale, desiredScale);
- Bitmap scaledBitmap = Bitmap.createBitmap(sampledSrcBitmap, 0, 0,
- sampledSrcBitmap.getWidth(), sampledSrcBitmap.getHeight(), matrix, true);
- sampledSrcBitmap = null;
- // Save
- FileOutputStream out = new FileOutputStream(LOCAL_PATH_TO_STORE_IMAGE);
- scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
- scaledBitmap = null;