Android异步加载网络图片

深入剖析Android之ListView从网络异步加载图片 深入剖析Android之ListView从网络异步加载图片 我写这篇博客参考了许多文章,其中要重点感谢的是Android ListView从网络获取图片及文字显示和他的英文版文章Android Custom ListView with Image and Text 布局篇 先来看一下做出来之后的效果 看看这个布局效果的xml文件 (1)activity_main.xml <Rela 阅读详情

http://blog.csdn.net/geniusxiaoyu/article/details/7470163点击打开链接

Android图片的异步加载,主要原理:

加载图片时先查看缓存中时候存在该图片,如果存在则返回该图片,否则先加载载一个默认的占位图片,同时创建一个通过网络获取图片的任务并添加,任务完成后放松消息给主线程更新界面。

使用方法:

[java]  view plain copy
  1. AsynImageLoader asynImageLoader = new AsynImageLoader();  
  2. asynImageLoader.showImageAsyn(imageView, imageUrl, resId);  


 

 

类代码:

[java]  view plain copy
  1. package com.wangge.uumao.http;  
  2.   
  3. import java.lang.ref.SoftReference;  
  4. import java.util.ArrayList;  
  5. import java.util.HashMap;  
  6. import java.util.List;  
  7. import java.util.Map;  
  8.   
  9. import android.graphics.Bitmap;  
  10. import android.os.Handler;  
  11. import android.os.Message;  
  12. import android.util.Log;  
  13. import android.widget.ImageView;  
  14.   
  15. import com.wangge.uumao.util.PicUtil;  
  16.   
  17. public class AsynImageLoader {  
  18.     private static final String TAG = "AsynImageLoader";  
  19.     // 缓存下载过的图片的Map  
  20.     private Map<String, SoftReference<Bitmap>> caches;  
  21.     // 任务队列  
  22.     private List<Task> taskQueue;  
  23.     private boolean isRunning = false;  
  24.       
  25.     public AsynImageLoader(){  
  26.         // 初始化变量  
  27.         caches = new HashMap<String, SoftReference<Bitmap>>();  
  28.         taskQueue = new ArrayList<AsynImageLoader.Task>();  
  29.         // 启动图片下载线程  
  30.         isRunning = true;  
  31.         new Thread(runnable).start();  
  32.     }  
  33.       
  34.     /** 
  35.      *  
  36.      * @param imageView 需要延迟加载图片的对象 
  37.      * @param url 图片的URL地址 
  38.      * @param resId 图片加载过程中显示的图片资源 
  39.      */  
  40.     public void showImageAsyn(ImageView imageView, String url, int resId){  
  41.         imageView.setTag(url);  
  42.         Bitmap bitmap = loadImageAsyn(url, getImageCallback(imageView, resId));  
  43.           
  44.         if(bitmap == null){  
  45.             imageView.setImageResource(resId);  
  46.         }else{  
  47.             imageView.setImageBitmap(bitmap);  
  48.         }  
  49.     }  
  50.       
  51.     public Bitmap loadImageAsyn(String path, ImageCallback callback){  
  52.         // 判断缓存中是否已经存在该图片  
  53.         if(caches.containsKey(path)){  
  54.             // 取出软引用  
  55.             SoftReference<Bitmap> rf = caches.get(path);  
  56.             // 通过软引用,获取图片  
  57.             Bitmap bitmap = rf.get();  
  58.             // 如果该图片已经被释放,则将该path对应的键从Map中移除掉  
  59.             if(bitmap == null){  
  60.                 caches.remove(path);  
  61.             }else{  
  62.                 // 如果图片未被释放,直接返回该图片  
  63.                 Log.i(TAG, "return image in cache" + path);  
  64.                 return bitmap;  
  65.             }  
  66.         }else{  
  67.             // 如果缓存中不常在该图片,则创建图片下载任务  
  68.             Task task = new Task();  
  69.             task.path = path;  
  70.             task.callback = callback;  
  71.             Log.i(TAG, "new Task ," + path);  
  72.             if(!taskQueue.contains(task)){  
  73.                 taskQueue.add(task);  
  74.                 // 唤醒任务下载队列  
  75.                 synchronized (runnable) {  
  76.                     runnable.notify();  
  77.                 }  
  78.             }  
  79.         }  
  80.           
  81.         // 缓存中没有图片则返回null  
  82.         return null;  
  83.     }  
  84.       
  85.     /** 
  86.      *  
  87.      * @param imageView  
  88.      * @param resId 图片加载完成前显示的图片资源ID 
  89.      * @return 
  90.      */  
  91.     private ImageCallback getImageCallback(final ImageView imageView, final int resId){  
  92.         return new ImageCallback() {  
  93.               
  94.             @Override  
  95.             public void loadImage(String path, Bitmap bitmap) {  
  96.                 if(path.equals(imageView.getTag().toString())){  
  97.                     imageView.setImageBitmap(bitmap);  
  98.                 }else{  
  99.                     imageView.setImageResource(resId);  
  100.                 }  
  101.             }  
  102.         };  
  103.     }  
  104.       
  105.     private Handler handler = new Handler(){  
  106.   
  107.         @Override  
  108.         public void handleMessage(Message msg) {  
  109.             // 子线程中返回的下载完成的任务  
  110.             Task task = (Task)msg.obj;  
  111.             // 调用callback对象的loadImage方法,并将图片路径和图片回传给adapter  
  112.             task.callback.loadImage(task.path, task.bitmap);  
  113.         }  
  114.           
  115.     };  
  116.       
  117.     private Runnable runnable = new Runnable() {  
  118.           
  119.         @Override  
  120.         public void run() {  
  121.             while(isRunning){  
  122.                 // 当队列中还有未处理的任务时,执行下载任务  
  123.                 while(taskQueue.size() > 0){  
  124.                     // 获取第一个任务,并将之从任务队列中删除  
  125.                     Task task = taskQueue.remove(0);  
  126.                     // 将下载的图片添加到缓存  
  127.                     task.bitmap = PicUtil.getbitmap(task.path);  
  128.                     caches.put(task.path, new SoftReference<Bitmap>(task.bitmap));  
  129.                     if(handler != null){  
  130.                         // 创建消息对象,并将完成的任务添加到消息对象中  
  131.                         Message msg = handler.obtainMessage();  
  132.                         msg.obj = task;  
  133.                         // 发送消息回主线程  
  134.                         handler.sendMessage(msg);  
  135.                     }  
  136.                 }  
  137.                   
  138.                 //如果队列为空,则令线程等待  
  139.                 synchronized (this) {  
  140.                     try {  
  141.                         this.wait();  
  142.                     } catch (InterruptedException e) {  
  143.                         e.printStackTrace();  
  144.                     }  
  145.                 }  
  146.             }  
  147.         }  
  148.     };  
  149.       
  150.     //回调接口  
  151.     public interface ImageCallback{  
  152.         void loadImage(String path, Bitmap bitmap);  
  153.     }  
  154.       
  155.     class Task{  
  156.         // 下载任务的下载路径  
  157.         String path;  
  158.         // 下载的图片  
  159.         Bitmap bitmap;  
  160.         // 回调对象  
  161.         ImageCallback callback;  
  162.           
  163.         @Override  
  164.         public boolean equals(Object o) {  
  165.             Task task = (Task)o;  
  166.             return task.path.equals(path);  
  167.         }  
  168.     }  
  169. }  


 最后附上PicUtil类的代码,之前忘了贴这个类的代码,不好意识了~~

[java]  view plain copy
  1. public class PicUtil {  
  2.     private static final String TAG = "PicUtil";  
  3.   
  4.     /** 
  5.      * 根据一个网络连接(URL)获取bitmapDrawable图像 
  6.      *  
  7.      * @param imageUri 
  8.      * @return 
  9.      */  
  10.     public static BitmapDrawable getfriendicon(URL imageUri) {  
  11.   
  12.         BitmapDrawable icon = null;  
  13.         try {  
  14.             HttpURLConnection hp = (HttpURLConnection) imageUri  
  15.                     .openConnection();  
  16.             icon = new BitmapDrawable(hp.getInputStream());// 将输入流转换成bitmap  
  17.             hp.disconnect();// 关闭连接  
  18.         } catch (Exception e) {  
  19.         }  
  20.         return icon;  
  21.     }  
  22.   
  23.     /** 
  24.      * 根据一个网络连接(String)获取bitmapDrawable图像 
  25.      *  
  26.      * @param imageUri 
  27.      * @return 
  28.      */  
  29.     public static BitmapDrawable getcontentPic(String imageUri) {  
  30.         URL imgUrl = null;  
  31.         try {  
  32.             imgUrl = new URL(imageUri);  
  33.         } catch (MalformedURLException e1) {  
  34.             e1.printStackTrace();  
  35.         }  
  36.         BitmapDrawable icon = null;  
  37.         try {  
  38.             HttpURLConnection hp = (HttpURLConnection) imgUrl.openConnection();  
  39.             icon = new BitmapDrawable(hp.getInputStream());// 将输入流转换成bitmap  
  40.             hp.disconnect();// 关闭连接  
  41.         } catch (Exception e) {  
  42.         }  
  43.         return icon;  
  44.     }  
  45.   
  46.     /** 
  47.      * 根据一个网络连接(URL)获取bitmap图像 
  48.      *  
  49.      * @param imageUri 
  50.      * @return 
  51.      */  
  52.     public static Bitmap getusericon(URL imageUri) {  
  53.         // 显示网络上的图片  
  54.         URL myFileUrl = imageUri;  
  55.         Bitmap bitmap = null;  
  56.         try {  
  57.             HttpURLConnection conn = (HttpURLConnection) myFileUrl  
  58.                     .openConnection();  
  59.             conn.setDoInput(true);  
  60.             conn.connect();  
  61.             InputStream is = conn.getInputStream();  
  62.             bitmap = BitmapFactory.decodeStream(is);  
  63.             is.close();  
  64.         } catch (IOException e) {  
  65.             e.printStackTrace();  
  66.         }  
  67.         return bitmap;  
  68.     }  
  69.   
  70.     /** 
  71.      * 根据一个网络连接(String)获取bitmap图像 
  72.      *  
  73.      * @param imageUri 
  74.      * @return 
  75.      * @throws MalformedURLException 
  76.      */  
  77.     public static Bitmap getbitmap(String imageUri) {  
  78.         // 显示网络上的图片  
  79.         Bitmap bitmap = null;  
  80.         try {  
  81.             URL myFileUrl = new URL(imageUri);  
  82.             HttpURLConnection conn = (HttpURLConnection) myFileUrl  
  83.                     .openConnection();  
  84.             conn.setDoInput(true);  
  85.             conn.connect();  
  86.             InputStream is = conn.getInputStream();  
  87.             bitmap = BitmapFactory.decodeStream(is);  
  88.             is.close();  
  89.   
  90.             Log.i(TAG, "image download finished." + imageUri);  
  91.         } catch (IOException e) {  
  92.             e.printStackTrace();  
  93.             return null;  
  94.         }  
  95.         return bitmap;  
  96.     }  
  97.   
  98.     /** 
  99.      * 下载图片 同时写道本地缓存文件中 
  100.      *  
  101.      * @param context 
  102.      * @param imageUri 
  103.      * @return 
  104.      * @throws MalformedURLException 
  105.      */  
  106.     public static Bitmap getbitmapAndwrite(String imageUri) {  
  107.         Bitmap bitmap = null;  
  108.         try {  
  109.             // 显示网络上的图片  
  110.             URL myFileUrl = new URL(imageUri);  
  111.             HttpURLConnection conn = (HttpURLConnection) myFileUrl  
  112.                     .openConnection();  
  113.             conn.setDoInput(true);  
  114.             conn.connect();  
  115.   
  116.             InputStream is = conn.getInputStream();  
  117.             File cacheFile = FileUtil.getCacheFile(imageUri);  
  118.             BufferedOutputStream bos = null;  
  119.             bos = new BufferedOutputStream(new FileOutputStream(cacheFile));  
  120.             Log.i(TAG, "write file to " + cacheFile.getCanonicalPath());  
  121.   
  122.             byte[] buf = new byte[1024];  
  123.             int len = 0;  
  124.             // 将网络上的图片存储到本地  
  125.             while ((len = is.read(buf)) > 0) {  
  126.                 bos.write(buf, 0, len);  
  127.             }  
  128.   
  129.             is.close();  
  130.             bos.close();  
  131.   
  132.             // 从本地加载图片  
  133.             bitmap = BitmapFactory.decodeFile(cacheFile.getCanonicalPath());  
  134.             String name = MD5Util.MD5(imageUri);  
  135.   
  136.         } catch (IOException e) {  
  137.             e.printStackTrace();  
  138.         }  
  139.         return bitmap;  
  140.     }  
  141.   
  142.     public static boolean downpic(String picName, Bitmap bitmap) {  
  143.         boolean nowbol = false;  
  144.         try {  
  145.             File saveFile = new File("/mnt/sdcard/download/weibopic/" + picName  
  146.                     + ".png");  
  147.             if (!saveFile.exists()) {  
  148.                 saveFile.createNewFile();  
  149.             }  
  150.             FileOutputStream saveFileOutputStream;  
  151.             saveFileOutputStream = new FileOutputStream(saveFile);  
  152.             nowbol = bitmap.compress(Bitmap.CompressFormat.PNG, 100,  
  153.                     saveFileOutputStream);  
  154.             saveFileOutputStream.close();  
  155.         } catch (FileNotFoundException e) {  
  156.             e.printStackTrace();  
  157.         } catch (IOException e) {  
  158.             e.printStackTrace();  
  159.         } catch (Exception e) {  
  160.             e.printStackTrace();  
  161.         }  
  162.         return nowbol;  
  163.     }  
  164.   
  165.     public static void writeTofiles(Context context, Bitmap bitmap,  
  166.             String filename) {  
  167.         BufferedOutputStream outputStream = null;  
  168.         try {  
  169.             outputStream = new BufferedOutputStream(context.openFileOutput(  
  170.                     filename, Context.MODE_PRIVATE));  
  171.             bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);  
  172.         } catch (FileNotFoundException e) {  
  173.             e.printStackTrace();  
  174.         }  
  175.     }  
  176.   
  177.     /** 
  178.      * 将文件写入缓存系统中 
  179.      *  
  180.      * @param filename 
  181.      * @param is 
  182.      * @return 
  183.      */  
  184.     public static String writefile(Context context, String filename,  
  185.             InputStream is) {  
  186.         BufferedInputStream inputStream = null;  
  187.         BufferedOutputStream outputStream = null;  
  188.         try {  
  189.             inputStream = new BufferedInputStream(is);  
  190.             outputStream = new BufferedOutputStream(context.openFileOutput(  
  191.                     filename, Context.MODE_PRIVATE));  
  192.             byte[] buffer = new byte[1024];  
  193.             int length;  
  194.             while ((length = inputStream.read(buffer)) != -1) {  
  195.                 outputStream.write(buffer, 0, length);  
  196.             }  
  197.         } catch (Exception e) {  
  198.         } finally {  
  199.             if (inputStream != null) {  
  200.                 try {  
  201.                     inputStream.close();  
  202.                 } catch (IOException e) {  
  203.                     e.printStackTrace();  
  204.                 }  
  205.             }  
  206.             if (outputStream != null) {  
  207.                 try {  
  208.                     outputStream.flush();  
  209.                     outputStream.close();  
  210.                 } catch (IOException e) {  
  211.                     e.printStackTrace();  
  212.                 }  
  213.             }  
  214.         }  
  215.         return context.getFilesDir() + "/" + filename + ".jpg";  
  216.     }  
  217.   
  218.     // 放大缩小图片  
  219.     public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {  
  220.         int width = bitmap.getWidth();  
  221.         int height = bitmap.getHeight();  
  222.         Matrix matrix = new Matrix();  
  223.         float scaleWidht = ((float) w / width);  
  224.         float scaleHeight = ((float) h / height);  
  225.         matrix.postScale(scaleWidht, scaleHeight);  
  226.         Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height,  
  227.                 matrix, true);  
  228.         return newbmp;  
  229.     }  
  230.   
  231.     // 将Drawable转化为Bitmap  
  232.     public static Bitmap drawableToBitmap(Drawable drawable) {  
  233.         int width = drawable.getIntrinsicWidth();  
  234.         int height = drawable.getIntrinsicHeight();  
  235.         Bitmap bitmap = Bitmap.createBitmap(width, height, drawable  
  236.                 .getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888  
  237.                 : Bitmap.Config.RGB_565);  
  238.         Canvas canvas = new Canvas(bitmap);  
  239.         drawable.setBounds(0, 0, width, height);  
  240.         drawable.draw(canvas);  
  241.         return bitmap;  
  242.   
  243.     }  
  244.   
  245.     // 获得圆角图片的方法  
  246.     public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {  
  247.         if(bitmap == null){  
  248.             return null;  
  249.         }  
  250.           
  251.         Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),  
  252.                 bitmap.getHeight(), Config.ARGB_8888);  
  253.         Canvas canvas = new Canvas(output);  
  254.   
  255.         final int color = 0xff424242;  
  256.         final Paint paint = new Paint();  
  257.         final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());  
  258.         final RectF rectF = new RectF(rect);  
  259.   
  260.         paint.setAntiAlias(true);  
  261.         canvas.drawARGB(0, 0, 0, 0);  
  262.         paint.setColor(color);  
  263.         canvas.drawRoundRect(rectF, roundPx, roundPx, paint);  
  264.   
  265.         paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));  
  266.         canvas.drawBitmap(bitmap, rect, rect, paint);  
  267.         return output;  
  268.     }  
  269.   
  270.     // 获得带倒影的图片方法  
  271.     public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {  
  272.         final int reflectionGap = 4;  
  273.         int width = bitmap.getWidth();  
  274.         int height = bitmap.getHeight();  
  275.   
  276.         Matrix matrix = new Matrix();  
  277.         matrix.preScale(1, -1);  
  278.   
  279.         Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2,  
  280.                 width, height / 2, matrix, false);  
  281.   
  282.         Bitmap bitmapWithReflection = Bitmap.createBitmap(width,  
  283.                 (height + height / 2), Config.ARGB_8888);  
  284.   
  285.         Canvas canvas = new Canvas(bitmapWithReflection);  
  286.         canvas.drawBitmap(bitmap, 0, 0, null);  
  287.         Paint deafalutPaint = new Paint();  
  288.         canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);  
  289.   
  290.         canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);  
  291.   
  292.         Paint paint = new Paint();  
  293.         LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,  
  294.                 bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,  
  295.                 0x00ffffff, TileMode.CLAMP);  
  296.         paint.setShader(shader);  
  297.         // Set the Transfer mode to be porter duff and destination in  
  298.         paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));  
  299.         // Draw a rectangle using the paint with our linear gradient  
  300.         canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()  
  301.                 + reflectionGap, paint);  
  302.   
  303.         return bitmapWithReflection;  
  304.     }  
  305.   
  306. }  


 FileUtil

[java]  view plain copy
  1. package com.wangge.coupon.util;  
  2.   
  3. import java.io.File;  
  4. import java.io.IOException;  
  5.   
  6. import android.os.Environment;  
  7. import android.util.Log;  
  8.   
  9. import com.wangge.coupon.http.AsynImageLoader;  
  10.   
  11. public class FileUtil {  
  12.     private static final String TAG = "FileUtil";  
  13.   
  14.     public static File getCacheFile(String imageUri){  
  15.         File cacheFile = null;  
  16.         try {  
  17.             if (Environment.getExternalStorageState().equals(  
  18.                     Environment.MEDIA_MOUNTED)) {  
  19.                 File sdCardDir = Environment.getExternalStorageDirectory();  
  20.                 String fileName = getFileName(imageUri);  
  21.                 File dir = new File(sdCardDir.getCanonicalPath()  
  22.                         + AsynImageLoader.CACHE_DIR);  
  23.                 if (!dir.exists()) {  
  24.                     dir.mkdirs();  
  25.                 }  
  26.                 cacheFile = new File(dir, fileName);  
  27.                 Log.i(TAG, "exists:" + cacheFile.exists() + ",dir:" + dir + ",file:" + fileName);  
  28.             }    
  29.         } catch (IOException e) {  
  30.             e.printStackTrace();  
  31.             Log.e(TAG, "getCacheFileError:" + e.getMessage());  
  32.         }  
  33.           
  34.         return cacheFile;  
  35.     }  
  36.       
  37.     public static String getFileName(String path) {  
  38.         int index = path.lastIndexOf("/");  
  39.         return path.substring(index + 1);  
  40.     }  
  41. }  

Android异步加载网络图片的最佳实践与实例 网络图片加载的安全性问题主要来源于以下几个方面:图片来源的安全性:从不可信的源加载图片可能会引入恶意软件或不安全的内容。传输过程中的安全:通过未加密的HTTP协议加载图片可能会遭受中间人攻击(MITM),导致敏感信息泄露。图片文件本身的漏洞利用:某些图片格式(如BMP、JPEG)可能存在漏洞,恶意构造的图片文件可被利用执行任意代码。 阅读详情

相关推荐

Android开发GridView异步加载网络图片实战

Override// 触发loadInBackground()@Override与LoaderManager结合使用:@Override@Override@Override});通过本章的介绍,我们不仅掌握了LruCache和的基本使用方式,还了解了如何构建一个高效的双缓存架构。实际开发中,建议结合第三方图片加载库(如Glide)的缓存机制进行优化,同时关注内存与磁盘的平衡,避免过度占用系统资源。

weixin_30533301的博客 1103

android 异步图片加载 开源,异步加载图片BitmapFun分析

博客地址:http://my.oschina.net/lifj/blog/313866--------2014年8月19日BY拉风的道长开源项目地址项目简介如果图片资源是静态的,当我们要在View上显示图片时,只需要简单的将图片赋值给ImageView就可以了,但如果需要浏览网络上的图片时该如何做呢?有可能图片很大,有可能网速很慢并且不稳定,这种情况下该如何增加用户体验。Android官方的Bi...

weixin_32655655的博客 279

华为无线WiFi实战:基于802.1x与NPS的企业级认证部署指南

本文提供了一份详尽的华为无线WiFi企业级认证部署实战指南。通过整合802.1x协议与Windows NPS服务器,构建基于AD域账号的安全认证体系,彻底解决传统WiFi密码共享带来的安全风险。文章详细拆解了从NPS服务器配置、证书部署到华为AC端RADIUS模板、AAA方案、认证域及VAP模板调用的全流程,并附有终端连接测试与常见故障排查方法,助力企业实现高效、安全的无线网络接入管理。

weixin_29239661的博客 277

android 加载网络bitmap图片 oom 简书_Android常见问题--ImageView加载图片OOM

开发中给ImageView加载一个高质量图片时,APP抛出了“Canvas: trying to draw too large(840253440bytes) bitmap.”的异常。猜测是图片占用内存太大,超出APP被分配的内存(我用的mate9,APP被分的内存差不多200m),造成了OOM。解决方法:1.修改图片分辨率。降低分辨率以减少内存占用,前提是手机展示时不会失真太严重。2.正确的放置...

weixin_42523260的博客 822

树莓派5 Ubuntu24.04部署Astra Pro深度相机SDK实战指南

本文详细介绍了在树莓派5上运行Ubuntu24.04系统部署Astra Pro深度相机SDK的完整流程,包括环境准备、硬件连接、SDK安装配置、镜像画面修正以及深度数据采集优化等关键步骤。针对新手常见问题提供了实用解决方案,帮助开发者快速实现深感摄像头的高效应用。

weixin_42628280的博客 231

DRAM知识整理系列(三):部分时序参数整理

一、tCL-tRCD-tRP-tRAS(第一时序) 内存是根据行和列寻址的,当请求触发后,最初是tRAS(Active to precharge Delay),预充电后,内存才真正开始初始化RAS(Row Address Strobe)。一旦tRAS激活后,RAS开始进行需要数据的寻址。首先是行地址,然后初始化tRCD(RAS to CAS Delay),周期结束,接着通过CAS(Column Address Strobe)访问所需数据的十六进制地址。其中,从CAS开始到CAS结束,就是CAS延迟(即t

不吃鱼的猫的博客 7万+

android 圆角bitmap,Android--Bitmap处理、圆角、圆形

/*** 转换图片成圆形**@parambitmap* 传入Bitmap对象*@return*/public staticBitmap toRoundBitmap(Bitmap bitmap) {int width =bitmap.getWidth();int height =bitmap.getHeight();floatroundPx;floatleft, top, ri...

weixin_39822147的博客 508

Android Glide加载并显示圆角图片

我们都知道手机加载图片是一个耗时又耗内存的事情,但因为效果我们又不得不加载各种各样的图片。但自己写的图片加载与缓存不仅代码繁琐,还会因为考虑不全造成各种各样未知的bug,所以越来越多的人利用第三方的框架来加载图片,而Glide在这方面可谓说独占鳌头。 选择Glide理由: 1.集成简单,一行代码依赖完成 2.使用简单,一行代码调用完成 3.能加载各种类型的图片,不管是静态图还是gif图 4.优秀的...

u014714188的博客 3407

【深度学习基础】多任务学习(Multi-Task Learning)

多任务学习(Multi-task learning)是和单任务学习(single-task learning)相对的一种机器学习方法。在机器学习领域,标准的算法理论是一次学习一个任务,也就是系统的输出为实数的情况。复杂的学习问题先被分解成理论上独立的子问题,然后分别对每个子问题进行学习,最后通过对子问题学习结果的组合建立复杂问题的数学模型。多任务学习是一种联合学习,多个任务并行学习,结果相互影响。一次只学习一个任务(task),大部分的机器学习任务都属于单任务学习。

十二月的猫 1万+

AI 时代嵌入式工程师的能力模型与学习路线:全系列收官

AI 时代嵌入式工程师的能力模型与学习路线:全系列收官

weixin_42162924的博客 51

android从json文件异步加载图片,android 安卓异步加载网络图片,与viewpager结合使用示例...

android 安卓异步加载网络图片,与viewpager结合使用示例发布时间:2020-07-01 03:54:59来源:51CTO阅读:1204作者:careylwq【1】异步加载图片类AsyncImageLoaderpackagecom.example.testdddleapk.cus;importjava.io.IOException;importjava.lang.ref.Soft...

weixin_31830691的博客 184

出现 has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ header is present on the 解决方法

Access to XMLHttpRequest at 'http://127.0.0.1:5000/api/data' from origin 'http://10.197.0.79:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

码农研究僧的博客 1万+

【Android】异步加载网络图片

Android图片的异步加载,主要原理: 加载图片时先查看缓存中时候存在该图片,如果存在则返回该图片,否则先加载载一个默认的占位图片,同时创建一个通过网络获取图片的任务并添加,任务完成后放松消息给主线程更新界面。 使用方法: [java] view plaincopy AsynImageLoader asynImageLoader = new

好想睡觉…… 5437

运行codex时出现登录失败:failed to start login server: 以一种访问权限不允许的方式做了一个访问套接字的尝试。 (os error 10013) 解决方案

的本质是Windows 系统端口保留策略而非代码 bug。推荐使用方案一(调整动态端口范围),一劳永逸解决。如果你安装了 Docker Desktop 或启用了 WSL2,调整端口范围后记得检查相关服务是否正常运行。

一键难忘的博客 4218

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Android异步加载网络图片,美团安卓面试

Android架构学习进阶是一条漫长而艰苦的道路,不能靠一时激情,更不是熬几天几夜就能学好的,必须养成平时努力学习的习惯。所以:贵在坚持!上面分享的字节跳动公司2021年的面试真题解析大全,笔者还把一线互联网企业主流面试技术要点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节。【Android高级架构视频学习资源】Android部分精讲视频领取学习后更加是如虎添翼!进军BATJ大厂等(备战)!

2401_84149256的博客 713

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

安卓GridView异步加载网络图片

安卓GridView异步加载网络图片总结感想今天,第一次使用加载网络图片,对于网络GridView的图片网络加载与大家分享下。 先看下效果图 看完效果下面就看看具体代码的实现吧 MainActivity 的写法 //gridview要显示的数据商品列表 private List < ProductDetailsBean > goods; //我们要填充的容器gridview哦

wheretogowater的博客 3745

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Android异步加载网络图片,android开发基础知识点

*/ public void showImageAsyn(ImageView imageView, String url, int resId){ imageView.setTag(url); Bitmap bitmap = loadImageAsyn(url, getImageCallback(imageView, resId)); if(bitmap ==..

m0_64604178的博客 211

android viewpager动态加载图片,android 安卓异步加载网络图片,与viewpager结合使用示例...

【1】异步加载图片类AsyncImageLoaderpackagecom.example.testdddleapk.cus;importjava.io.IOException;importjava.lang.ref.SoftReference;importjava.util.HashMap;importorg.apache.http.HttpEntity;importorg.apach...

weixin_36400833的博客 232

android中异步加载网络图片

随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666) 思路:先为ListView或者GridView等设置默认图片,然后启用异步线程下载网络图片然后更新adapter,刷新UI,代码如下: MainActivity: package com.home.asynl...

孤云博客 3133

Android异步加载网络图片,android音乐播放器开发教程

task.callback = callback; Log.i(TAG, “new Task ,” + path); if(!taskQueue.contains(task)){ taskQueue.add(task); // 唤醒任务下载队列 synchronized (runnable) { runnable.notify(); } } } // 缓存..

m0_65146275的博客 148

android async http 异步加载图片,Android 中使用 AsyncTask 异步读取网络图片

1.新建Android工程AsyncLoadPicture新建布局文件activity_main.xml主界面为一个GridView,还有其子项布局文件gridview_item.xml2.功能主界面MainActivity.java,主代码如下package com.example.asyncloadpicture;import java.util.ArrayList;import androi...

weixin_42533243的博客 256

Android网络图片异步加载

前言 其实很幸运,入职一周之后就能跟着两个师兄做android开发,师兄都是大神,身为小白的我只能多多学习,多多努力。最近一段时间都忙的没机会总结,今天刚完成了android客户端图片异步加载的类,这里记录一下(ps:其实我这里都是参考网上开源实现) 原理 在ListView或者GridView中加载图片的原理基本都是一样的: 先从内存缓存中获取,取到则返回,取不到

小一的专栏 1958

java图片异步加载_在Android的应用中实现网络图片异步加载的方法

前言其实很幸运,入职一周之后就能跟着两个师兄做android开发,师兄都是大神,身为小白的我只能多多学习,多多努力。最近一段时间都忙的没机会总结,今天刚完成了android客户端图片异步加载的类,这里记录一下(ps:其实我这里都是参考网上开源实现)原理在ListView或者GridView中加载图片的原理基本都是一样的:先从内存缓存中获取,取到则返回,取不到进行下一步从文件缓存中获取,取到则返回并...

weixin_35319943的博客 155
上一篇: Android/Java面试题,边面试边成长,为了应试而应试
下一篇: C/C++中函数参数传递详解
起风啰
博客等级 码龄16年 30粉丝 4原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址