Displaying Bitmaps Efficiently
来源:互联网 发布:卡通艺术字软件下载 编辑:程序博客网 时间:2024/06/08 16:58
Loading Large Bitmaps Efficiently
- 读取图片的源信息(不创建图片对象,同时分配内存加载图片)
BitmapFactory.Options options = new BitmapFactory.Options();options.inJustDecodeBounds = true;BitmapFactory.decodeResource(getResources(), R.id.myimage, options);int imageHeight = options.outHeight;int imageWidth = options.outWidth;String imageType = options.outMimeType;
- 计算图片缩放比例的方法
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 (height > reqHeight || width > reqWidth) { final int halfHeight = height / 2; final int halfWidth = width / 2; // Calculate the largest inSampleSize value that is a power of 2 and keeps both // height and width larger than the requested height and width. while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth) { inSampleSize *= 2; } } return inSampleSize;}
Processing Bitmaps Off the UI Thread
- 后台请求图片任务
class BitmapWorkerTask extends AsyncTask<Integer, Void, Bitmap> { private final WeakReference<ImageView> imageViewReference; private int data = 0; public BitmapWorkerTask(ImageView imageView) { // Use a WeakReference to ensure the ImageView can be garbage collected imageViewReference = new WeakReference<ImageView>(imageView); } // Decode image in background. @Override protected Bitmap doInBackground(Integer... params) { data = params[0]; return decodeSampledBitmapFromResource(getResources(), data, 100, 100)); } // Once complete, see if ImageView is still around and set bitmap. @Override protected void onPostExecute(Bitmap bitmap) { if (imageViewReference != null && bitmap != null) { final ImageView imageView = imageViewReference.get(); if (imageView != null) { imageView.setImageBitmap(bitmap); } } }}
0 0
- Displaying Bitmaps Efficiently
- Displaying Bitmaps Efficiently
- Displaying Bitmaps Efficiently
- Displaying Bitmaps Efficiently
- Displaying Bitmaps Efficiently
- Displaying Bitmaps Efficiently
- Displaying Bitmaps Efficiently -
- Displaying Bitmaps Efficiently
- Android-Displaying Bitmaps Efficiently
- Displaying Bitmaps Efficiently总结
- Displaying Bitmaps Efficiently
- Displaying Bitmaps Efficiently -Loading Large Bitmaps Efficiently
- Displaying Bitmaps Efficiently(3)-Caching Bitmaps
- Displaying Bitmaps Efficiently之Caching Bitmaps
- Displaying Bitmaps Efficiently(1)-Loading Large Bitmaps Efficiently
- Displaying Bitmaps Efficiently (一)-----Loading Large Bitmaps Efficiently
- Displaying Bitmaps Efficiently (一)-----Loading Large Bitmaps Efficiently(二)
- Displaying Bitmaps Efficiently之Loading Large Bitmaps Efficiently
- android网络编程所涉及到的知识
- Strategy----策略模式
- WOai wojiao
- 鸡啄米vc++2010系列38(文档、视图和框架:概述)
- wireshark抓包dhcp
- Displaying Bitmaps Efficiently
- request中url
- 两种高效的事件处理模式
- 倒序输出你输入的正整数
- C++学习 boost学习之-scoped_array
- HTTP和HTTPS详解
- 给TEXTVIEW添加背景吧
- Windows学习篇之---Skype掉线问题
- linux集群性能测试