bitmap

Android-加载图片避免OOM

删除回忆录丶 提交于 2020-02-16 21:28:50
http://blog.csdn.net/guolin_blog/article/details/9316683 高效加载大图片 我们在编写Android程序的时候经常要用到许多图片,不同图片总是会有不同的形状、不同的大小,但在大多数情况下,这些图片都会大于我们程序所需要的大小。比如说系统图片库里展示的图片大都是用手机摄像头拍出来的,这些图片的分辨率会比我们手机屏幕的分辨率高得多。大家应该知道,我们编写的应用程序都是有一定内存限制的,程序占用了过高的内存就容易出现OOM(OutOfMemory)异常。我们可以通过下面的代码看出每个应用程序最高可用内存是多少。 int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); Log.d("TAG", "Max memory is " + maxMemory + "KB"); 因此在展示高分辨率图片的时候,最好先将图片进行 压缩 。压缩后的图片大小应该和用来展示它的控件大小相近,在一个很小的ImageView上显示一张超大的图片不会带来任何视觉上的好处,但却会占用我们相当多宝贵的内存,而且在性能上还可能会带来负面影响。下面我们就来看一看,如何对一张大图片进行适当的压缩,让它能够以最佳大小显示的同时,还能防止OOM的出现。 大体思路如下: 1.压缩图片 获取图片的长度

Convert Graphics object to Bitmap

杀马特。学长 韩版系。学妹 提交于 2020-02-14 21:37:51
问题 I do have following issue with my graphics object. EDIT: I do have a picturebox_image (imageRxTx) which is a live stream from a camera. What I do in the paint event is to draw some lines on top of the image imageRxTx (not shown in the code below). This works so far without problem. Now I need to check for circles in imageRxTx and therefore I have to use the method ProcessImage() which needs a Bitmap as parameter. Unfortunately I do not have the Bitmap image but rather the handle (hDC) to my

Convert Graphics object to Bitmap

怎甘沉沦 提交于 2020-02-14 21:35:36
问题 I do have following issue with my graphics object. EDIT: I do have a picturebox_image (imageRxTx) which is a live stream from a camera. What I do in the paint event is to draw some lines on top of the image imageRxTx (not shown in the code below). This works so far without problem. Now I need to check for circles in imageRxTx and therefore I have to use the method ProcessImage() which needs a Bitmap as parameter. Unfortunately I do not have the Bitmap image but rather the handle (hDC) to my

Convert Graphics object to Bitmap

天涯浪子 提交于 2020-02-14 21:35:12
问题 I do have following issue with my graphics object. EDIT: I do have a picturebox_image (imageRxTx) which is a live stream from a camera. What I do in the paint event is to draw some lines on top of the image imageRxTx (not shown in the code below). This works so far without problem. Now I need to check for circles in imageRxTx and therefore I have to use the method ProcessImage() which needs a Bitmap as parameter. Unfortunately I do not have the Bitmap image but rather the handle (hDC) to my

2D Array grid on drawing canvas

寵の児 提交于 2020-02-12 10:49:55
问题 I am writing an pixel art app that paints images the user draws on the screen to pixel look. There are two ways to approach it. Either pixelate the image after saving or have a grid before hand so the user draws the pixel image. I don't find anything on the later method. So my issue with the first is drawing a grid where if a cell is touched I would change the color of it. I tried drawing rectangles on a canvas but that was pointless because i couldn't control the cells. I was thinking about

2D Array grid on drawing canvas

让人想犯罪 __ 提交于 2020-02-12 10:49:25
问题 I am writing an pixel art app that paints images the user draws on the screen to pixel look. There are two ways to approach it. Either pixelate the image after saving or have a grid before hand so the user draws the pixel image. I don't find anything on the later method. So my issue with the first is drawing a grid where if a cell is touched I would change the color of it. I tried drawing rectangles on a canvas but that was pointless because i couldn't control the cells. I was thinking about

Android 自定义圆形图片 CircleImageView

孤街浪徒 提交于 2020-02-12 04:15:28
/*--> */ /*--> */ 1.效果预览 1.1.布局中写自定义圆形图片的路径即可    1.2.然后看一看图片效果    1.3.原图是这样的 @mipmap/ic_launcher    2.使用过程 2.1.CircleImageView源代码  public class CircleImageView extends AppCompatImageView { private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP; private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888; private static final int COLORDRAWABLE_DIMENSION = 1; private static final int DEFAULT_BORDER_WIDTH = 0; private static final int DEFAULT_BORDER_COLOR = Color.BLACK; private final RectF mDrawableRect = new RectF(); private final RectF mBorderRect = new RectF();

Python学习笔记——图形用户界面(1)

♀尐吖头ヾ 提交于 2020-02-12 03:59:35
import tkinter win = tkinter . Tk ( ) win . title ( string = "吴宇翔为什么是一个傻逼?" ) tkinter . Label ( win , background = "SystemHighlight" , text = "关于吴宇翔为什么这么傻逼," ) . pack ( ) tkinter . Label ( win , background = "SystemScrollbar" , text = "这是公理无需证明。" ) . pack ( ) tkinter . Button ( win , padx = "2p" , text = "关闭" , command = win . quit ) . pack ( side = "bottom" ) win . mainloop ( ) import tkinter win = tkinter . Tk ( ) tkinter . Button ( win , relief = "ridge" , borderwidth = 5 , text = "关闭" , command = win . quit ) . pack ( ) win . mainloop ( ) import tkinter from tkinter import Label TEXT = [

listView加载显示图片(缓存)

浪尽此生 提交于 2020-02-11 19:50:52
我用的是异步加载图片的方式,并且使用了缓存的方式。 1、这是继承了AsyncTask<String, Void, Bitmap>的MyTask类,用异步加载图片 public class MyTask extends AsyncTask<String, Void, Bitmap> { private ImageView imageView; private LruCache<String, Bitmap> lruCache; /** * 构造方法,需要把ImageView控件和LruCache对象传进来 * * @param imageView * 加载图片到此 * @param lruCache * 缓存图片的对象 */ public MyTask(ImageView imageView, LruCache<String, Bitmap> lruCache) { super(); this.imageView = imageView; this.lruCache = lruCache; } /** * 调用LruCache的put 方法将图片加入内存缓存中,要给这个图片一个key 方便下次从缓存中取出来 * * @param key * @param bitmap */ private void addBitmapToMemoryCache(String key, Bitmap

位图bitmap数据结构

谁都会走 提交于 2020-02-10 21:51:37
位图是一种很特殊的数据结构,可以利用位图来排序,但是这种排序方法对输入的数据是有比较严格的要求(数据不能重复,大致知道数据的范围)。举个例子,假如有一个集合{3,5,7,8,2,1},我们可以用一个8位的二进制向量set[1-8]来表示该集合,如果数据存在,则将set相对应的二进制位置1,否则置0.根据给出的集合得到的set为{1,1,1,0,1,0,1,1},然后再根据set集合的值输出对应的下标即可得到集合{3,5,7,8,2,1}的排序结果。 位图的应用: 1.给40亿个不重复的unsigned int的整数,没有排过序,然后再给一个数,如果快速判断这个数是否在那40亿个数当中。 因为unsigned int数据的最大范围在在40亿左右,40 10^8/1024 1024*8=476,因此只需申请512M的内存空间,每个bit位表示一个unsigned int。读入40亿个数,并设置相应的bit位为1.然后读取要查询的数,查看该bit是否为1,是1则存在,否则不存在。 2.给40亿个unsigned int的整数,如何判断这40亿个数中哪些数重复? 同理,可以申请512M的内存空间,然后读取40亿个整数,并且将相应的bit位置1。如果是第一次读取某个数据,则在将该bit位置1之前,此bit位必定是0;如果是第二次读取该数据,则可根据相应的bit位是否为1判断该数据是否重复。