zoukankan      html  css  js  c++  java
  • Android的Bitmap和BitmapDrawable类解析-android学习之旅(六十)

    这里写图片描写叙述

    使用简单图片

    这里写图片描写叙述

    使用Drawable对象

    这里写图片描写叙述

    bitmap和BitmapDrawable对象

    这里写图片描写叙述
    这里写图片描写叙述
    这里写图片描写叙述

    package peng.liu.test;
    
    import android.app.Activity;
    import android.content.res.AssetFileDescriptor;
    import android.content.res.AssetManager;
    import android.graphics.BitmapFactory;
    import android.graphics.drawable.BitmapDrawable;
    import android.graphics.drawable.ClipDrawable;
    import android.media.MediaPlayer;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.view.View;
    import android.view.animation.Animation;
    import android.view.animation.AnimationUtils;
    import android.widget.ImageView;
    
    import java.io.InputStream;
    import java.util.Timer;
    import java.util.TimerTask;
    
    
    public class MainActivity extends Activity{
        String[] images;
        ImageView image;
        int currentImg;
        AssetManager asset;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            image = (ImageView) findViewById(R.id.imageBit);
            try{
                asset = getAssets();
                images = asset.list("");
            }catch (Exception e){
                e.printStackTrace();
            }
            findViewById(R.id.btnBit).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (currentImg >= images.length){
                        currentImg = 0;
                    }
                    while (!images[currentImg].endsWith(".png")&&!images[currentImg].endsWith(".jpg")&&!images[currentImg].endsWith(".gif")){
                        currentImg++;
                        if (currentImg >= images.length){
                            currentImg = 0;
                        }
                        InputStream assetFile = null;
                        try{
                            assetFile = asset.open(images[currentImg++]);
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                        BitmapDrawable drawable = (BitmapDrawable) image.getDrawable();
                        if (drawable != null && !drawable.getBitmap().isRecycled()){
                            drawable.getBitmap().recycle();
                        }
                        image.setImageBitmap(BitmapFactory.decodeStream(assetFile));
                    }
                }
            });
        }
    }
    
  • 相关阅读:
    阿里中间件——消息中间件Notify和MetaQ
    大型网站架构系列:分布式消息队列
    Mycat
    spring集成mybatis实现mysql读写分离
    mysql5.7.18的安装与主从复制
    NuGet学习笔记(3) 搭建属于自己的NuGet服务器
    NuGet学习笔记(1)——初识NuGet及快速安装使用
    Android 中使用 html 作布局文件
    获取WebView加载HTML时网页中的内容
    android学习——popupWindow 在指定位置上的显示
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5280584.html
Copyright © 2011-2022 走看看