[image]20 手机录制视频为什么会自动退出?内存是够的 大神tv录制们帮帮忙

Android加载上百张图片做动画出现OOM(内存溢出)解决方案-安卓教程-手机开发-壹聚教程网Android加载上百张图片做动画出现OOM(内存溢出)解决方案
有一个Android应用中要做一个有几百张图片的帧动画(恶心),这样很容易出现android内存溢出,本文我们来谈谈防止OOM的解决方案。
帧动画一开始我的想法是直接用帧动画来做,可是我太天真了,当帧数放到 50 几张的时候,已经在有些机器上奔溃了!所以这个方案否决!GIF动图虽然可以显示,但是已经卡的我,已经不想看了,直接放弃视频在这里,我突然想到我可以直接把他做成一个小视频啊,而且可以极限压缩视频。最终,视频大小被压缩到 500K 左右。此时已经基本可以满足需求了,但是我们有好多类似的动画,要求在每个动画切换的时候要有衔接感,不能有突兀的感觉,所有在这里视频就不能很好的完成任务了,所有再次放弃,已经泪牛满面了!!!!SurfaceView + BitmapRegionDecoder +缓存首先回答一下:为什么会想到这个解决方案?&&& 首先在做帧动画的时候,大约每帧之间的时间差值是 40ms 可以说速度非常快了,在如此快速的图片切换上,自然而然的想到来了使用SurfaceView。&&& 现在再来说说为什么想到要使用这个类 BitmapRegionDecoder .这个也是从我司游戏开发人员那儿得到的经验?他们在做游戏的时候,游戏中的切图都是放在一张大图上的,然后在根据对应的 xml,json 文件,获取相应的图片,接着再来切图。对此,我想能不能把所有的动图都放到同一张的图片上呢,之后在根据对应的描述文件,裁剪出我想要的图片呢!所以就用到了 BitmapRegionDecoder. 它的作用是:于显示图片的某一块矩形区域!之后,我在找设计人员商量一一下,把图片在尽量的压缩。之后从美工那儿获取的信息是这样的:&&& json格式的描述文件:{&frames&: [{&& &&filename&: &kidbot-正常闭眼0000&,&& &&frame&: {&x&:0,&y&:0,&w&:360,&h&:300},&& &&rotated&: false,&& &&trimmed&: false,&& &&spriteSourceSize&: {&x&:0,&y&:0,&w&:360,&h&:300},&& &&sourceSize&: {&w&:360,&h&:300}}.....}png图片:接下来就好做了,解析 json 格式的文件,裁剪图片。&&& 最后说一下为什么使用缓存,其实很简单,因为切换的频率实在太高了,没有必要每次都从图片中裁剪,这里就把裁剪出来的 bitmap 缓存起来在用。从而介绍内存开销!最后给出代码:public&class&AnimView&extends&SurfaceView&implements&SurfaceHolder.Callback&{
&&&&private&BitmapRegionDecoder&bitmapRegionD
&&&&private&SurfaceHolder&mH
&&&&private&boolean&isrunning&=&
&&&&private&AnimThread&
&&&&private&Paint&mP
&&&&private&int&WIDTH&=&0;
&&&&private&int&HEIGHT&=&0;
&&&&private&int&state&=&-1;
&&&&private&boolean&isstart&=&
&&&&private&boolean&isblinkfirst&=&
&&&&private&int&rate&=&40;
&&&&private&int&index&=&0;
&&&&private&Matrix&
&&&&private&Random&
&&&&private&Handler&handler&=&new&Handler()&{
&&&&&&&&public&void&handleMessage(android.os.Message&msg)&{
&&&&&&&&&&&&isblinkfirst&=&
&&&&&&&&};
&&&&private&SparseArray&WeakReference&Bitmap&&&weakB
&&&&private&SparseArray&WeakReference&Bitmap&&&cweakB
&&&&private&BitmapFactory.Options&
&&&&public&AnimView(Context&context)&{
&&&&&&&&super(context);
&&&&&&&&init();
&&&&public&AnimView(Context&context,&AttributeSet&attrs)&{
&&&&&&&&super(context,&attrs);
&&&&&&&&init();
&&&&public&AnimView(Context&context,&AttributeSet&attrs,&int&defStyleAttr)&{
&&&&&&&&super(context,&attrs,&defStyleAttr);
&&&&&&&&init();
&&&&@SuppressLint(&NewApi&)
&&&&private&void&init()&{
&&&&&&&&weakBitmaps&=&new&SparseArray&WeakReference&Bitmap&&();
&&&&&&&&cweakBitmaps&=&new&SparseArray&WeakReference&Bitmap&&();
&&&&&&&&mHolder&=&getHolder();
&&&&&&&&mHolder.addCallback(this);
&&&&&&&&mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
&&&&&&&&setState(FaceBean.BLINK);
&&&&&&&&mPaint&=&new&Paint(Paint.ANTI_ALIAS_FLAG);
&&&&&&&&matrix&=&new&Matrix();
&&&&&&&&float[]&values&=&{&-1f,&0.0f,&0.0f,&0.0f,&1f,&0.0f,&0.0f,&0.0f,&1.0f&};
&&&&&&&&matrix.setValues(values);
&&&&&&&&WindowManager&manger&=&(WindowManager)&getContext().getSystemService(
&&&&&&&&&&&&&&&&Context.WINDOW_SERVICE);
&&&&&&&&DisplayMetrics&displayMetrics&=&new&DisplayMetrics();
&&&&&&&&manger.getDefaultDisplay().getMetrics(displayMetrics);
&&&&&&&&WIDTH&=&displayMetrics.widthPixels&/&2;
&&&&&&&&HEIGHT&=&displayMetrics.heightPixels&/&2;
&&&&&&&&rand&=&new&Random();
&&&&&&&&options&=&new&Options();
&&&&&&&&options.inPreferredConfig&=&Bitmap.Config.RGB_565;
&&&&@Override
&&&&public&void&surfaceCreated(SurfaceHolder&holder)&{
&&&&&&&&handler.sendEmptyMessageDelayed(0,&1000&*&(4&+&rand.nextInt(4)));
&&&&&&&&thread&=&new&AnimThread();
&&&&&&&&thread.start();
&&&&@Override
&&&&public&void&surfaceChanged(SurfaceHolder&holder,&int&format,&int&width,
&&&&&&&&&&&&int&height)&{
&&&&@Override
&&&&public&void&surfaceDestroyed(SurfaceHolder&holder)&{
&&&&&&&&if&(thread&!=&null)&{
&&&&&&&&&&&&thread.stopThread();
&&&&public&class&AnimThread&extends&Thread&{
&&&&&&&&@Override
&&&&&&&&public&void&run()&{
&&&&&&&&&&&&super.run();
&&&&&&&&&&&&SurfaceHolder&holder&=&mH
&&&&&&&&&&&&while&(isrunning)&{
&&&&&&&&&&&&&&&&Canvas&canvas&=&holder.lockCanvas();
&&&&&&&&&&&&&&&&if&(canvas&==&null)
&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&synchronized&(AnimThread.class)&{
&&&&&&&&&&&&&&&&&&&&AnimBean.Frames&
&&&&&&&&&&&&&&&&&&&&switch&(state)&{
&&&&&&&&&&&&&&&&&&&&case&FaceBean.BLINK:
&&&&&&&&&&&&&&&&&&&&&&&&frames&=&KidbotRobotApplication.animBlink.getFrames()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.get(index);
&&&&&&&&&&&&&&&&&&&&&&&&if&(frames.getFrame().getW()&&=&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Rect&rect&=&new&Rect(frames.getFrame().getX(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getFrame().getY(),&frames.getFrame()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getX()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&frames.getSourceSize().getW(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getFrame().getY()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&frames.getSourceSize().getH());
&&&&&&&&&&&&&&&&&&&&&&&&&&&&WeakReference&Bitmap&&weakBitmap&=&weakBitmaps
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.get(index);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Bitmap&map&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(weakBitmap&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map&=&bitmapRegionDecoder.decodeRegion(rect,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&options);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&weakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(map));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map=weakBitmap.get();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(map&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map&=&bitmapRegionDecoder.decodeRegion(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&rect,&options);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&weakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(map));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(map&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&holder.unlockCanvasAndPost(canvas);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint.setXfermode(new&PorterDuffXfermode(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Mode.CLEAR));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawPaint(mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint.setXfermode(new&PorterDuffXfermode(Mode.SRC));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawBitmap(map,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&(int)&(WIDTH&-&(map.getWidth()&*&1)&-&150),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&(int)&(HEIGHT&-&(map.getHeight()&/&2)),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawBitmap(map,&(int)&(WIDTH&+&150),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&(int)&(HEIGHT&-&(map.getHeight()&/&2)),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&==&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(map.isRecycled())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map.recycle();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&if&(!isstart)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&&&KidbotRobotApplication.animBlink
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getFrames().size())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index++;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&==&KidbotRobotApplication.animBlink
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getFrames().size())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(rand.nextInt(10)&&=&2)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index&=&1;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&&&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&==&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index++;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&if&(!isblinkfirst)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&index&=&0;
&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&==&KidbotRobotApplication.animBlink
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getFrames().size()&-&1)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isblinkfirst&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index&=&0;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&handler.sendEmptyMessageDelayed(0,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&1000&*&(4&+&rand.nextInt(4)));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&case&FaceBean.ANGRY:
&&&&&&&&&&&&&&&&&&&&&&&&frames&=&KidbotRobotApplication.animAngry.getFrames()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.get(index);
&&&&&&&&&&&&&&&&&&&&&&&&if&(frames.getFrame().getW()&&=&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Rect&rect&=&new&Rect(frames.getFrame().getX(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getFrame().getY(),&frames.getFrame()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getX()&+&frames.getFrame().getW(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getFrame().getH()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&frames.getFrame().getX());
&&&&&&&&&&&&&&&&&&&&&&&&&&&&WeakReference&Bitmap&&weakBitmap&=&weakBitmaps
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.get(index);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Bitmap&map&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(weakBitmap&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map&=&bitmapRegionDecoder.decodeRegion(rect,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&options);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&weakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(map));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map=weakBitmap.get();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(map&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map&=&bitmapRegionDecoder.decodeRegion(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&rect,&options);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&weakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(map));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(map&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&holder.unlockCanvasAndPost(canvas);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint.setXfermode(new&PorterDuffXfermode(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Mode.CLEAR));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawPaint(mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint.setXfermode(new&PorterDuffXfermode(Mode.SRC));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Bitmap&dstbmp&=
&&&&&&&&&&&&&&&&&&&&&&&&&&&&weakBitmap=cweakBitmaps.get(index);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if(weakBitmap==null){
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&dstbmp&=&Bitmap.createBitmap(map,&0,&0,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map.getWidth(),&map.getHeight(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&matrix,&true);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&cweakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(dstbmp));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}else{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&dstbmp=weakBitmap.get();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if(dstbmp==null){
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&dstbmp&=&Bitmap.createBitmap(map,&0,&0,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map.getWidth(),&map.getHeight(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&matrix,&true);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&cweakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(dstbmp));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawBitmap(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getSpriteSourceSize().getX()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(WIDTH
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&-&(map.getWidth()&*&1)&-&150),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getSpriteSourceSize().getY()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(HEIGHT&-&(map.getHeight()&/&2)),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawBitmap(dstbmp,&frames
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getSpriteSourceSize().getX()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(WIDTH&+&150),&frames
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getSpriteSourceSize().getY()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(HEIGHT&-&(map.getHeight()&/&2)),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(dstbmp.isRecycled())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&dstbmp.recycle();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(map.isRecycled())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map.recycle();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&if&(!isstart)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&&&KidbotRobotApplication.animAngry
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getFrames().size())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index++;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&==&KidbotRobotApplication.animAngry
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getFrames().size())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&&&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&==&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index++;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&case&FaceBean.HAPPY:
&&&&&&&&&&&&&&&&&&&&&&&&frames&=&KidbotRobotApplication.animHappy.getFrames()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.get(index);
&&&&&&&&&&&&&&&&&&&&&&&&if&(frames.getFrame().getW()&&=&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Rect&rect&=&new&Rect(frames.getFrame().getX(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getFrame().getY(),&frames.getFrame()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getX()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&frames.getSourceSize().getW(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getFrame().getY()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&frames.getSourceSize().getH());
&&&&&&&&&&&&&&&&&&&&&&&&&&&&WeakReference&Bitmap&&weakBitmap&=&weakBitmaps
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.get(index);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Bitmap&map&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(weakBitmap&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map&=&bitmapRegionDecoder.decodeRegion(rect,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&options);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&weakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(map));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map=weakBitmap.get();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(map&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map&=&bitmapRegionDecoder.decodeRegion(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&rect,&options);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&weakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(map));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(map&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&holder.unlockCanvasAndPost(canvas);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint.setXfermode(new&PorterDuffXfermode(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Mode.CLEAR));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawPaint(mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint.setXfermode(new&PorterDuffXfermode(Mode.SRC));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Bitmap&dstbmp&=
&&&&&&&&&&&&&&&&&&&&&&&&&&&&weakBitmap=cweakBitmaps.get(index);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if(weakBitmap==null){
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&dstbmp&=&Bitmap.createBitmap(map,&0,&0,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map.getWidth(),&map.getHeight(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&matrix,&true);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&cweakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(dstbmp));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}else{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&dstbmp=weakBitmap.get();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if(dstbmp==null){
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&dstbmp&=&Bitmap.createBitmap(map,&0,&0,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map.getWidth(),&map.getHeight(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&matrix,&true);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&cweakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(dstbmp));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawBitmap(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getSpriteSourceSize().getX()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(WIDTH
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&-&(map.getWidth()&*&1)&-&150),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getSpriteSourceSize().getY()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(HEIGHT&-&(map.getHeight()&/&2)),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawBitmap(dstbmp,&frames
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getSpriteSourceSize().getX()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(WIDTH&+&150),&frames
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getSpriteSourceSize().getY()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(HEIGHT&-&(map.getHeight()&/&2)),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&//&if&(dstbmp.isRecycled())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&//&dstbmp.recycle();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&//&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&//&if&(map.isRecycled())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&//&map.recycle();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&//&}
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&if&(!isstart)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&&&KidbotRobotApplication.animHappy
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getFrames().size())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index++;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&==&KidbotRobotApplication.animHappy
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getFrames().size())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&&&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&==&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index++;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&case&FaceBean.RESOLVE:
&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&case&FaceBean.RISUS:
&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&case&FaceBean.SEERIGHT:
&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&case&FaceBean.SAD:
&&&&&&&&&&&&&&&&&&&&&&&&frames&=&KidbotRobotApplication.animSad.getFrames()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.get(index);
&&&&&&&&&&&&&&&&&&&&&&&&if&(frames.getFrame().getW()&&=&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Rect&rect&=&new&Rect(frames.getFrame().getX(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getFrame().getY(),&frames.getFrame()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getX()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&frames.getSourceSize().getW(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getFrame().getY()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&frames.getSourceSize().getH());
&&&&&&&&&&&&&&&&&&&&&&&&&&&&WeakReference&Bitmap&&weakBitmap&=&weakBitmaps
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.get(index);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Bitmap&map&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(weakBitmap&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map&=&bitmapRegionDecoder.decodeRegion(rect,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&options);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&weakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(map));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map=weakBitmap.get();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(map&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map&=&bitmapRegionDecoder.decodeRegion(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&rect,&options);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&weakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(map));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(map&==&null)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&holder.unlockCanvasAndPost(canvas);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint.setXfermode(new&PorterDuffXfermode(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Mode.CLEAR));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawPaint(mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint.setXfermode(new&PorterDuffXfermode(Mode.SRC));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Bitmap&dstbmp&=
&&&&&&&&&&&&&&&&&&&&&&&&&&&&weakBitmap=cweakBitmaps.get(index);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if(weakBitmap==null){
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&dstbmp&=&Bitmap.createBitmap(map,&0,&0,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map.getWidth(),&map.getHeight(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&matrix,&true);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&cweakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(dstbmp));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}else{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&dstbmp=weakBitmap.get();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if(dstbmp==null){
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&dstbmp&=&Bitmap.createBitmap(map,&0,&0,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map.getWidth(),&map.getHeight(),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&matrix,&true);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&cweakBitmaps.put(index,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&new&WeakReference&Bitmap&(dstbmp));
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawBitmap(
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getSpriteSourceSize().getX()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(WIDTH
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&-&(map.getWidth()&*&1)&-&150),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&frames.getSpriteSourceSize().getY()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(HEIGHT&-&(map.getHeight()&/&2)),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&canvas.drawBitmap(dstbmp,&frames
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getSpriteSourceSize().getX()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(WIDTH&+&150),&frames
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getSpriteSourceSize().getY()
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&(int)&(HEIGHT&-&(map.getHeight()&/&2)),
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&mPaint);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(dstbmp.isRecycled())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&dstbmp.recycle();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(map.isRecycled())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&map.recycle();
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&if&(!isstart)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&&&KidbotRobotApplication.animSad
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getFrames().size())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index++;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&==&KidbotRobotApplication.animSad
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.getFrames().size())&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&&&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index--;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(index&==&0)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&else&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&index++;
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&isstart&=&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&default:
&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&holder.unlockCanvasAndPost(canvas);
&&&&&&&&&&&&&&&&try&{
&&&&&&&&&&&&&&&&&&&&Thread.sleep(rate);
&&&&&&&&&&&&&&&&}&&(InterruptedException&e)&{
&&&&&&&&&&&&&&&&&&&&e.printStackTrace();
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&}
&&&&&&&&public&void&stopThread()&{
&&&&&&&&&&&&isrunning&=&
&&&&&&&&&&&&try&{
&&&&&&&&&&&&&&&&join();
&&&&&&&&&&&&}&catch&(InterruptedException&e)&{
&&&&&&&&&&&&&&&&e.printStackTrace();
&&&&&&&&&&&&}
&&&&public&synchronized&void&setRate(int&rate)&{
&&&&&&&&this.rate&=&
&&&&public&int&getState()&{
&&&&&&&&return&this.
&&&&public&synchronized&void&setState(int&state)&{
&&&&&&&&//&if&(FaceBean.BLINK&==&this.state)&{
&&&&&&&&//&while&((index&!=&KidbotRobotApplication.animBlink.getFrames()
&&&&&&&&//&.size()&-&1))&{
&&&&&&&&//&
&&&&&&&&//&}
&&&&&&&&//&}
&&&&&&&&cweakBitmaps.clear();
&&&&&&&&weakBitmaps.clear();
&&&&&&&&this.state&=&
&&&&&&&&this.index&=&0;
&&&&&&&&switch&(state)&{
&&&&&&&&case&FaceBean.BLINK:
&&&&&&&&&&&&try&{
&&&&&&&&&&&&&&&&bitmapRegionDecoder&=&BitmapRegionDecoder.newInstance(
&&&&&&&&&&&&&&&&&&&&&&&&getContext().getAssets().open(&kidbot_blink.png&),
&&&&&&&&&&&&&&&&&&&&&&&&false);
&&&&&&&&&&&&}&catch&(IOException&e)&{
&&&&&&&&&&&&&&&&e.printStackTrace();
&&&&&&&&&&&&}
&&&&&&&&&&&&
&&&&&&&&case&FaceBean.ANGRY:
&&&&&&&&&&&&try&{
&&&&&&&&&&&&&&&&bitmapRegionDecoder&=&BitmapRegionDecoder.newInstance(
&&&&&&&&&&&&&&&&&&&&&&&&getContext().getAssets().open(&kidbot_angry.png&),
&&&&&&&&&&&&&&&&&&&&&&&&false);
&&&&&&&&&&&&}&catch&(IOException&e)&{
&&&&&&&&&&&&&&&&e.printStackTrace();
&&&&&&&&&&&&}
&&&&&&&&&&&&
&&&&&&&&case&FaceBean.HAPPY:
&&&&&&&&&&&&try&{
&&&&&&&&&&&&&&&&bitmapRegionDecoder&=&BitmapRegionDecoder.newInstance(
&&&&&&&&&&&&&&&&&&&&&&&&getContext().getAssets().open(&kidbot_happy.png&),
&&&&&&&&&&&&&&&&&&&&&&&&false);
&&&&&&&&&&&&}&catch&(IOException&e)&{
&&&&&&&&&&&&&&&&e.printStackTrace();
&&&&&&&&&&&&}
&&&&&&&&&&&&
&&&&&&&&case&FaceBean.RESOLVE:
&&&&&&&&&&&&try&{
&&&&&&&&&&&&&&&&bitmapRegionDecoder&=&BitmapRegionDecoder.newInstance(
&&&&&&&&&&&&&&&&&&&&&&&&getContext().getAssets().open(&kidbot_blink.png&),
&&&&&&&&&&&&&&&&&&&&&&&&false);
&&&&&&&&&&&&}&catch&(IOException&e)&{
&&&&&&&&&&&&&&&&e.printStackTrace();
&&&&&&&&&&&&}
&&&&&&&&&&&&
&&&&&&&&case&FaceBean.RISUS:
&&&&&&&&&&&&try&{
&&&&&&&&&&&&&&&&bitmapRegionDecoder&=&BitmapRegionDecoder.newInstance(
&&&&&&&&&&&&&&&&&&&&&&&&getContext().getAssets().open(&kidbot_blink.png&),
&&&&&&&&&&&&&&&&&&&&&&&&false);
&&&&&&&&&&&&}&catch&(IOException&e)&{
&&&&&&&&&&&&&&&&e.printStackTrace();
&&&&&&&&&&&&}
&&&&&&&&&&&&
&&&&&&&&case&FaceBean.SEERIGHT:
&&&&&&&&&&&&
&&&&&&&&case&FaceBean.SAD:
&&&&&&&&&&&&try&{
&&&&&&&&&&&&&&&&bitmapRegionDecoder&=&BitmapRegionDecoder.newInstance(
&&&&&&&&&&&&&&&&&&&&&&&&getContext().getAssets().open(&kidbot_sad.png&),&false);
&&&&&&&&&&&&}&catch&(IOException&e)&{
&&&&&&&&&&&&&&&&e.printStackTrace();
&&&&&&&&&&&&}
&&&&&&&&&&&&
&&&&public&synchronized&void&setRunning(boolean&isrunning)&{
&&&&&&&&this.isrunning&=&
&&&&public&synchronized&void&addIndex()&{
&&&&&&&&this.index++;
}Android高效加载大图、多图解决方案,有效避免程序OOM比如说系统图片库里展示的图片大都是用手机摄像头拍出来的,这些图片的分辨率会比我们手机屏幕的分辨率高得多。大家应该知道,我们编写的应用程序都是有一定内存限制的,程序占用了过高的内存就容易出现OOM(OutOfMemory)异常。我们可以通过下面的代码看出每个应用程序最高可用内存是多少。&&& int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);& &&&& Log.d(&TAG&, &Max memory is & + maxMemory + &KB&); &&&& &因此在展示高分辨率图片的时候,最好先将图片进行压缩。压缩后的应该和用来展示它的控件大小相近,在一个很小的ImageView上显示一张超大的图片不会带来任何视觉上的好处,但却会占用我们相当多宝贵的内存,而且在性能上还可能会带来负面影响。下面我们就来看一看,如何对一张大图片进行适当的压缩,让它能够以最佳大小显示的同时,还能防止OOM的出现。BitmapFactory这个类提供了多个解析方法(decodeByteArray, decodeFile, decodeResource等)用于创建Bitmap对象,我们应该根据图片的来源选择合适的方法。比如SD卡中的图片可以使用decodeFile方法,网络上的图片可以使用decodeStream方法,资源文件中的图片可以使用decodeResource方法。这些方法会尝试为已经构建的bitmap分配内存,这时就会很容易导致OOM出现。为此每一种解析方法都提供了一个可选的BitmapFactory.Options参数,将这个参数的inJustDecodeBounds属性设置为true就可以让解析方法禁止为bitmap分配内存,返回值也不再是一个Bitmap对象,而是null。虽然Bitmap是null了,但是BitmapFactory.Options的outWidth、outHeight和outMimeType属性都会被赋值。这个技巧让我们可以在之前就获取到图片的长宽值和MIME类型,从而根据情况对图片进行压缩。如下代码所示:&&& BitmapFactory.Options options = new BitmapFactory.Options();& &&&& options.inJustDecodeBounds =& &&&& BitmapFactory.decodeResource(getResources(), R.id.myimage, options);& &&&& int imageHeight = options.outH& &&&& int imageWidth = options.outW& &&&& String imageType = options.outMimeT &&&& &为了避免OOM异常,最好在解析每张图片的时候都先检查一下图片的大小,除非你非常信任图片的来源,保证这些图片都不会超出你程序的可用内存。现在图片的大小已经知道了,我们就可以决定是把整张图片加载到内存中还是加载一个压缩版的图片到内存中。以下几个因素是我们需要考虑的:预估一下加载整张图片所需占用的内存。为了加载这一张图片你所愿意提供多少内存。用于展示这张图片的控件的实际大小。当前设备的屏幕尺寸和分辨率。比如,你的ImageView只有128*96像素的大小,只是为了显示一张,这时候把一张像素的图片完全加载到内存中显然是不值得的。那我们怎样才能对图片进行压缩呢?通过设置BitmapFactory.Options中inSampleSize的值就可以实现。比如我们有一张像素的图片,将inSampleSize的值设置为4,就可以把这张图片压缩成512*384像素。原本加载这张图片需要占用13M的内存,压缩后就只需要占用0.75M了(假设图片是ARGB_8888类型,即每个像素点占用4个字节)。下面的方法可以根据传入的宽和高,计算出合适的inSampleSize值:&&&&public&static&int&calculateInSampleSize(BitmapFactory.Options&options,&&&
&&&&&&&&&&&&int&reqWidth,&int&reqHeight)&{&&&
&&&&&&&&//&源图片的高度和宽度&&&
&&&&&&&&final&int&height&=&options.outH&&&
&&&&&&&&final&int&width&=&options.outW&&&
&&&&&&&&int&inSampleSize&=&1;&&&
&&&&&&&&if&(height&&&reqHeight&||&width&&&reqWidth)&{&&&
&&&&&&&&&&&&//&计算出实际宽高和目标宽高的比率&&&
&&&&&&&&&&&&final&int&heightRatio&=&Math.round((float)&height&/&(float)&reqHeight);&&&
&&&&&&&&&&&&final&int&widthRatio&=&Math.round((float)&width&/&(float)&reqWidth);&&&
&&&&&&&&&&&&//&选择宽和高中最小的比率作为inSampleSize的值,这样可以保证最终图片的宽和高&&&
&&&&&&&&&&&&//&一定都会大于等于目标的宽和高。&&&
&&&&&&&&&&&&inSampleSize&=&heightRatio&&&widthRatio&?&heightRatio&:&widthR&&&
&&&&&&&&}&&&
&&&&&&&&return&inSampleS&&&
&&&&}&&&& &使用这个方法,首先你要将BitmapFactory.Options的inJustDecodeBounds属性设置为true,解析一次图片。然后将BitmapFactory.Options连同期望的宽度和高度一起传递到到calculateInSampleSize方法中,就可以得到合适的inSampleSize值了。之后再解析一次图片,使用新获取到的inSampleSize值,并把inJustDecodeBounds设置为false,就可以得到压缩后的图片了。&&&&public&static&Bitmap&decodeSampledBitmapFromResource(Resources&res,&int&resId,&&&
&&&&&&&&&&&&int&reqWidth,&int&reqHeight)&{&&&
&&&&&&&&//&第一次解析将inJustDecodeBounds设置为true,来获取&&&
&&&&&&&&final&BitmapFactory.Options&options&=&new&BitmapFactory.Options();&&&
&&&&&&&&options.inJustDecodeBounds&=&&&&
&&&&&&&&BitmapFactory.decodeResource(res,&resId,&options);&&&
&&&&&&&&//&调用上面定义的方法计算inSampleSize值&&&
&&&&&&&&options.inSampleSize&=&calculateInSampleSize(options,&reqWidth,&reqHeight);&&&
&&&&&&&&//&使用获取到的inSampleSize值再次解析图片&&&
&&&&&&&&options.inJustDecodeBounds&=&&&&
&&&&&&&&return&BitmapFactory.decodeResource(res,&resId,&options);&&&
&&&&}&&& 下面的代码非常简单地将任意一张图片压缩成100*100的缩略图,并在ImageView上展示。 &&&&mImageView.setImageBitmap(&&&
&&&&&&&&decodeSampledBitmapFromResource(getResources(),&R.id.myimage,&100,&100));&&&& &使用图片缓存技术在你应用程序的UI界面加载一张图片是一件很简单的事情,但是当你需要在界面上加载一大堆图片的时候,情况就变得复杂起来。在很多情况下,(比如使用ListView, GridView 或者 ViewPager 这样的组件),屏幕上显示的图片可以通过滑动屏幕等事件不断地增加,最终导致OOM。为了保证内存的使用始终维持在一个合理的范围,通常会把被移除屏幕的图片进行回收处理。此时垃圾回收器也会认为你不再持有这些图片的引用,从而对这些图片进行GC操作。用这种思路来解决问题是非常好的,可是为了能让程序快速运行,在界面上迅速地加载图片,你又必须要考虑到某些图片被回收之后,用户又将它重新滑入屏幕这种情况。这时重新去加载一遍刚刚加载过的图片无疑是性能的瓶颈,你需要想办法去避免这个情况的发生。这个时候,使用内存缓存技术可以很好的解决这个问题,它可以让组件快速地重新加载和处理图片。下面我们就来看一看如何使用内存缓存技术来对图片进行缓存,从而让你的应用程序在加载很多图片的时候可以提高响应速度和流畅性。内存缓存技术对那些大量占用应用程序宝贵内存的图片提供了快速访问的方法。其中最核心的类是LruCache (此类在android-support-v4的包中提供) 。这个类非常适合用来缓存图片,它的主要算法原理是把最近使用的对象用强引用存储在 LinkedHashMap 中,并且把最近最少使用的对象在缓存值达到预设定值之前从内存中移除。在过去,我们经常会使用一种非常流行的内存缓存技术的实现,即软引用或弱引用 (SoftReference or WeakReference)。但是现在已经不再推荐使用这种方式了,因为从 Android 2.3 (API Level 9)开始,垃圾回收器会更倾向于回收持有软引用或弱引用的对象,这让软引用和弱引用变得不再可靠。另外,Android 3.0 (API Level 11)中,图片的数据会存储在本地的内存当中,因而无法用一种可预见的方式将其释放,这就有潜在的风险造成应用程序的内存溢出并崩溃。为了能够选择一个合适的缓存大小给LruCache, 有以下多个因素应该放入考虑范围内,例如:你的设备可以为每个应用程序分配多大的内存?设备屏幕上一次最多能显示多少张图片?有多少图片需要进行预加载,因为有可能很快也会显示在屏幕上?你的设备的屏幕大小和分辨率分别是多少?一个超高分辨率的设备(例如 Galaxy Nexus) 比起一个较低分辨率的设备(例如 Nexus S),在持有相同数量图片的时候,需要更大的缓存空间。图片的尺寸和大小,还有每张图片会占据多少内存空间。图片被访问的频率有多高?会不会有一些图片的访问频率比其它图片要高?如果有的话,你也许应该让一些图片常驻在内存当中,或者使用多个LruCache 对象来区分不同组的图片。你能维持好数量和质量之间的平衡吗?有些时候,存储多个低像素的图片,而在后台去开线程加载高像素的图片会更加的有效。并没有一个指定的缓存大小可以满足所有的应用程序,这是由你决定的。你应该去分析程序内存的使用情况,然后制定出一个合适的解决方案。一个太小的缓存空间,有可能造成图片频繁地被释放和重新加载,这并没有好处。而一个太大的缓存空间,则有可能还是会引起 java.lang.OutOfMemory 的异常。下面是一个使用 LruCache 来缓存图片的例子:&&&&private&LruCache&String,&Bitmap&&mMemoryC&&&
&&&&@Override&&&
&&&&protected&void&onCreate(Bundle&savedInstanceState)&{&&&
&&&&&&&&//&获取到可用内存的最大值,使用内存超出这个值会引起OutOfMemory异常。&&&
&&&&&&&&//&LruCache通过构造函数传入缓存值,以KB为单位。&&&
&&&&&&&&int&maxMemory&=&(int)&(Runtime.getRuntime().maxMemory()&/&1024);&&&
&&&&&&&&//&使用最大可用内存值的1/8作为缓存的大小。&&&
&&&&&&&&int&cacheSize&=&maxMemory&/&8;&&&
&&&&&&&&mMemoryCache&=&new&LruCache&String,&Bitmap&(cacheSize)&{&&&
&&&&&&&&&&&&@Override&&&
&&&&&&&&&&&&protected&int&sizeOf(String&key,&Bitmap&bitmap)&{&&&
&&&&&&&&&&&&&&&&//&重写此方法来衡量每张图片的大小,默认返回图片数量。&&&
&&&&&&&&&&&&&&&&return&bitmap.getByteCount()&/&1024;&&&
&&&&&&&&&&&&}&&&
&&&&&&&&};&&&
&&&&public&void&addBitmapToMemoryCache(String&key,&Bitmap&bitmap)&{&&&
&&&&&&&&if&(getBitmapFromMemCache(key)&==&null)&{&&&
&&&&&&&&&&&&mMemoryCache.put(key,&bitmap);&&&
&&&&&&&&}&&&
&&&&public&Bitmap&getBitmapFromMemCache(String&key)&{&&&
&&&&&&&&return&mMemoryCache.get(key);&&&
&&&&}在这个例子当中,使用了系统分配给应用程序的八分之一内存来作为缓存大小。在中高配置的手机当中,这大概会有4兆(32/8)的缓存空间。一个全屏幕的 GridView 使用4张 800x480分辨率的图片来填充,则大概会占用1.5兆的空间(800*480*4)。因此,这个缓存大小可以存储2.5页的图片。当向 ImageView 中加载一张图片时,首先会在 LruCache 的缓存中进行检查。如果找到了相应的键值,则会立刻更新ImageView ,否则开启一个后台线程来加载这张图片。&&&&public&void&loadBitmap(int&resId,&ImageView&imageView)&{&&&
&&&&&&&&final&String&imageKey&=&String.valueOf(resId);&&&
&&&&&&&&final&Bitmap&bitmap&=&getBitmapFromMemCache(imageKey);&&&
&&&&&&&&if&(bitmap&!=&null)&{&&&
&&&&&&&&&&&&imageView.setImageBitmap(bitmap);&&&
&&&&&&&&}&else&{&&&
&&&&&&&&&&&&imageView.setImageResource(R.drawable.image_placeholder);&&&
&&&&&&&&&&&&BitmapWorkerTask&task&=&new&BitmapWorkerTask(imageView);&&&
&&&&&&&&&&&&task.execute(resId);&&&
&&&&&&&&}&&&
&&&&}&&& BitmapWorkerTask 还要把新加载的图片的键值对放到缓存中。 &&&& &&&&&class&BitmapWorkerTask&extends&AsyncTask&Integer,&Void,&Bitmap&&{&&&
&&&&&&&&//&在后台加载图片。&&&
&&&&&&&&@Override&&&
&&&&&&&&protected&Bitmap&doInBackground(Integer...&params)&{&&&
&&&&&&&&&&&&final&Bitmap&bitmap&=&decodeSampledBitmapFromResource(&&&
&&&&&&&&&&&&&&&&&&&&getResources(),&params[0],&100,&100);&&&
&&&&&&&&&&&&addBitmapToMemoryCache(String.valueOf(params[0]),&bitmap);&&&
&&&&&&&&&&&&return&&&&
&&&&&&&&}&&&
&&&&}掌握了以上两种方法,不管是要在程序中加载超大图片,还是要加载大量图片,都不用担心OOM的问题了!不过仅仅是理论地介绍不知道大家能不能完全理解,在后面的文章中我会演示如何在实际程序中灵活运用上述技巧来避免程序OOM,敬请期待。
名称:大小:9.96MM下载:
上一页: &&&&&下一页:相关内容}

我要回帖

更多关于 大神tv录制端 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信