zoukankan      html  css  js  c++  java
  • assets目录图片查看器

    public class ImagActivity extends Activity {
    
        AssetManager assetManager=null;
        String []dec;
        int currentImg=0;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_imag);
            final Button button=(Button)findViewById(R.id.imagButton);
            final ImageView imgBig=(ImageView)findViewById(R.id.imgBig);
           
    
            try
            {
                assetManager=getAssets();
                dec=assetManager.list("");
    
    
            }catch (IOException e){
                e.printStackTrace();
            }
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
    
                    InputStream inputStream=null;
                    currentImg=(++currentImg)%dec.length;
                    while(!dec[currentImg].endsWith(".jpg")) {
                        currentImg=(++currentImg)%dec.length;
                    }
                    try{
                        inputStream=assetManager.open(dec[currentImg]);
    
                    }catch (IOException e){
                        e.printStackTrace();
                    }
                    BitmapDrawable ibitmapDrawable=(BitmapDrawable)imgBig.getDrawable();
    
                    if(ibitmapDrawable!=null&&!bitmapDrawablep.getBitmap().isRecycled()) {
                        Bitmap bitmapTmp=ibitmapDrawable.getBitmap();
                       // bitmapTmp.recycle();
                        bitmapTmp=null;
                    }
                    imgBig.setImageBitmap(BitmapFactory.decodeStream(inputStream));
    
                    if(inputStream!=null){
                        try{
                            inputStream.close();
                        }catch (IOException e){
                            e.printStackTrace();
                        }
                    }
                }
            });
        }
    
        @Override
        protected void onDestroy() {
            super.onDestroy();
    
        }
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Java并发/多线程-线程池的使用
    pam详解
    chrony时间同步服务
    网站每日UV数据指标去重统计
    阻塞式发送邮件
    待办事项-redis
    解决Windows7、Windows10 ping不通的问题
    redis序列化和反序列化的操作-(以前咋操作我都忘记了)
    秒杀活动下的公平队列抢购机制
    控制某个字段不在页面展示
  • 原文地址:https://www.cnblogs.com/Thereisnospon/p/4768446.html
Copyright © 2011-2022 走看看