<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] # 1. 前言 在這個目錄下將記錄關于Bitmap的一些操作。首先來對比一下Bitmap和Drawable的區別。 # 2. Bitmap和Drawable Bitmap 稱作位圖,一般位圖的文件格式擴展名為.bmp,當然編碼器也有很多,如RGB565、 RGB8888。作為一種逐像素的顯示對象,其執行效率高;但缺點也很明顯,即存儲效率低。 Drawable 作為 Android 下通用的圖形對象,它可以裝載常用格式的圖像,比如 GIF、PNG、 JPG,當然也支持 BMP,還提供了一些高級的可視化對象,比如漸變、圖形等。 也就是說,Bitmap 是 Drawable,而 Drawable 不一定是 Bitmap。 ![](https://img.kancloud.cn/e4/34/e434010454e501243089f337281d83df_1003x167.png) Drawable 在占用**內存和繪制速度**這兩個非常關鍵的點上勝過 Bitmap,這也是在 Android UI 系統中普遍使用 Drawable 的原因之一。**Drawable 有很多派生類**,通過這些派生類**可以很容易地生成漸變、層疊等效果**。單從這 一方面而言,Drawable 比 Bitmap 有優勢。但如果僅僅用作空白畫布來繪圖,那么 Drawable 構造和使用起來則不如 Bitmap 方便。 ## 2.1 Bitmap和Drawable相互轉換 ### 1. Bitmap => Drawable 將 Bitmap 轉換為 BitmapDrawable 對象,然后轉換為 Drawable 使用。即: ~~~kotlin // 創建Bitmap對象 val bm = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888); val canvas = Canvas(bm) val paint = Paint(Paint.ANTI_ALIAS_FLAG) paint.color = Color.BLACK // 繪制一個紅色的圓到畫布,即Bitmap上 canvas.drawColor(Color.RED) canvas.drawCircle(width / 2f, width / 2f, (width/2).toFloat(), paint) // 轉換 val bitmapDrawable = BitmapDrawable(resources, bm) as Drawable ~~~ ### 2. Drawable => Bitmap 最簡單的做法也是借助BitmapDrawable對象,直接使用: ~~~ // 創建Bitmap對象 val drawable = resources.getDrawable(R.drawable.circle, null) val bitmap = (drawable as BitmapDrawable).bitmap ~~~ 也可以使用畫布的方式來完成,比如: ~~~ // 創建Bitmap對象 val drawable = resources.getDrawable(R.drawable.circle, null) val w = drawable.intrinsicWidth val h = drawable.intrinsicHeight val createBitmap = Bitmap.createBitmap( w, h, Bitmap.Config.ARGB_8888 ) val canvas = Canvas(createBitmap) drawable.setBounds(0, 0, w, h) drawable.draw(canvas) // return createBitmap ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看