日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

android开发之bitmap转数组的方法

發布時間:2023/12/15 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android开发之bitmap转数组的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/** 方法一* 將bitmap轉為數組的方法** @param bitmap 圖片* @return 返回數組*/public byte[] getBytesByBitmap(Bitmap bitmap) {ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());return buffer.array();}/** 方法二* 將bitmap轉為數組的方法** @param bitmap 圖片* @return 返回數組*/public byte[] getBytesByBitmaps(Bitmap bitmap) {ByteArrayOutputStream outputStream = new ByteArrayOutputStream(bitmap.getByteCount());bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);return outputStream.toByteArray();}/** 方法三* 其中w和h你需要轉換的大小* path轉換為bitmap:上面方法即可;* imageview獲取drawable并轉換為 bitmap :Bitmap bt= ((BitmapDrawable) mImageview.getDrawable()).getBitmap();* resourceid轉換為bitmap:Bitmap bt = BitmapFactory.decodeResource(getResources(), R.drawable.resourceid);* Drawable轉換為bitmap:Bitmap bt= ((BitmapDrawable) Drawable).getBitmap();* 因為BitmapDrawable是繼承Drawable,所以可以靈活的轉換** @param path 圖片路徑* @param w 寬度* @param h 高度* @return 返回*/public Bitmap convertToBitmap(String path, int w, int h) {BitmapFactory.Options opts = new BitmapFactory.Options();// 設置為ture只獲取圖片大小opts.inJustDecodeBounds = true;opts.inPreferredConfig = Bitmap.Config.ARGB_8888;// 返回為空BitmapFactory.decodeFile(path, opts);int width = opts.outWidth;int height = opts.outHeight;float scaleWidth = 0.f, scaleHeight = 0.f;if (width > w || height > h) {// 縮放scaleWidth = ((float) width) / w;scaleHeight = ((float) height) / h;}opts.inJustDecodeBounds = false;float scale = Math.max(scaleWidth, scaleHeight);opts.inSampleSize = (int) scale;WeakReference weak = new WeakReference(BitmapFactory.decodeFile(path, opts));return Bitmap.createScaledBitmap((Bitmap) weak.get(), w, h, true);}

?

總結

以上是生活随笔為你收集整理的android开发之bitmap转数组的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。