zoukankan      html  css  js  c++  java
  • ndroid获得Bitmap的三种方法(转载)

    一、        使用BitmapFactory解析图片

          

    // --> 使用BitmapFactory解析图片

               public void myUseBitmapFactory(Canvas canvas){

               // 定义画笔

                  Paint paint = new Paint();

               // 获取资源流

                  Resources rec = getResources();

                  InputStream in = rec.openRawResource(R.drawable.haha);

               // 设置图片

                  Bitmap bitmap =BitmapFactory.decodeStream(in);

               // 绘制图片

                  canvas.drawBitmap(bitmap, 0,20, paint);         

               }

    二、        使用BitmapDrawable解析图片

           // --> 使用BitmapDrawable解析图片

               public void myUseBitmapDrawable(Canvas canvas){

               // 定义画笔

                  Paint paint = new Paint();

               // 获得资源

                  Resources rec = getResources();

               // BitmapDrawable

                  BitmapDrawable bitmapDrawable = (BitmapDrawable) rec.getDrawable(R.drawable.haha);

               // 得到Bitmap

                  Bitmap bitmap = bitmapDrawable.getBitmap();

               // 在画板上绘制图片

                  canvas.drawBitmap(bitmap, 20,120,paint);

               }

    三、        使用InputStream和BitmapDrawable绘制

           // --> 使用InputStream和BitmapDrawable解析图片

               public void myUseInputStreamandBitmapDrawable(Canvas canvas){

               // 定义画笔

                  Paint paint = new Paint();

               // 获得资源

                  Resources rec = getResources();

               // InputStream得到资源流

                  InputStream in = rec.openRawResource(R.drawable.haha);

               // BitmapDrawable 解析数据流

                  BitmapDrawable bitmapDrawable =  new BitmapDrawable(in);

               // 得到图片

                  Bitmap bitmap = bitmapDrawable.getBitmap();

               // 绘制图片

                  canvas.drawBitmap(bitmap, 100, 100,paint);

               }

  • 相关阅读:
    一名3年工作经验的程序员面试分享应该具备的技能
    [activiti] Activiti 5.18 的Mybatis版本依赖问题
    [java] JVM监控与调优
    [mysql] mysqldump 导出数据库表
    【extjs】 extjs5 Ext.grid.Panel 搜索示例
    [tomcat] tomcat+nginx 负载均衡配置
    [mysql] mysql explain 使用
    Oracle自用脚本(持续更新)
    Mysql 简单问题汇总(持续更新)
    开源项目导入eclipse的一般步骤
  • 原文地址:https://www.cnblogs.com/draem0507/p/3131871.html
Copyright © 2011-2022 走看看