導航:首頁 > 操作系統 > androidpng轉bitmap

androidpng轉bitmap

發布時間:2022-05-23 12:53:43

『壹』 android如何從SD卡讀取圖片文件轉化為bitmap

SDK 中有專門取SD卡路徑的靜態方法
public String getSDPath(){
File sdDir = null;
boolean sdCardExist = Environment.getExternalStorageState()
.equals(Android.os.Environment.MEDIA_MOUNTED); //判斷sd卡是否存在
if (sdCardExist) {
sdDir = Environment.getExternalStorageDirectory();//獲取跟目錄
}
return sdDir.toString();
}

不要寫死路徑

『貳』 android 已經知道路徑怎麼將路徑中的圖片變成Bitmap

/**
* 獲取本地圖片並指定高度和寬度
*/
public static Bitmap getNativeImage(String imagePath)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
// 獲取這個圖片的寬和高
Bitmap myBitmap = BitmapFactory.decodeFile(imagePath, options); //此時返回myBitmap為空
//計算縮放比
int be = (int)(options.outHeight / (float)200);
int ys = options.outHeight % 200;//求余數
float fe = ys / (float)200;
if (fe >= 0.5)
be = be + 1;
if (be <= 0)
be = 1;
options.inSampleSize = be;
//重新讀入圖片,注意這次要把options.inJustDecodeBounds 設為 false
options.inJustDecodeBounds = false;
myBitmap = BitmapFactory.decodeFile(imagePath, options);
return myBitmap;
}
/**
* 以最省內存的方式讀取本地資源的圖片 或者SDCard中的圖片
* @param imagePath
* 圖片在SDCard中的路徑
* @return
*/
public static Bitmap getSDCardImg(String imagePath)
{
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
//獲取資源圖片
return BitmapFactory.decodeFile(imagePath, opt);
}

『叄』 android中Bitmap存為一張圖片

可以用Bitmap.compress函數來把Bitmap對象保存成PNG或JPG文件,然後可以用BitmapFactory把文件中的數據讀進來再生成Bitmap對象。
保存的代碼大概類似於這樣:
try {
FileOutputStream out = new FileOutputStream(filename);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
具體的可以去查Bitmap和BitmapFactory的幫助文檔。

『肆』 Android ,base64轉bitmap

1 把圖像文件讀如byte數組中。
2 然後調用EncodeBase64函數,把Byte數組傳入,函數返回Base64的字元串。
以上即可完成Base64轉換。

反方向
1 然後調用DecodeBase64函數,把Byte64字元串傳入,函數返回Byte數組。
2 把Bye數組內容寫入文件,文件名為bitmap點陣圖的bpm文件即可。

『伍』 Android Bitmap 與 Drawable之間的區別和轉換

Android bitmap和drawable的區別和轉換如下:

1.bitmap 轉換 drawable

java">Bitmapbitmap=newBitmap(...);Drawabledrawable=newBitmapDrawable(bitmap);
//Drawabledrawable=newFastBitmapDrawable(bitmap);

2.Drawable to Bitmap
BitmapDrawable, FastBitmapDrawable直接用getBitmap
b. 其他類型的Drawable用Canvas畫到一個bitmap上

Canvascanvas=newCanvas(bitmap)
drawable.draw(canvas);
Drawabled=ImagesList.get(0);Bitmapbitmap=((BitmapDrawable)d).getBitmap();

區別如下:

1.Bitmap - 稱作點陣圖,一般點陣圖的文件格式後綴為bmp,當然編碼器也有很多如RGB565、RGB888。作為一種逐像素的顯示對象執行效率高,但是缺點也很明顯存儲效率低。

2.Drawable - 作為Android平下通用的圖形對象,它可以裝載常用格式的圖像,比如GIF、PNG、JPG,當然也支持BMP,當然還提供一些高級的可視化對象,比如漸變、圖形等。

另外還有如下相類似的格式:

Canvas - 名為畫布,可以看作是一種處理過程,使用各種方法來管理Bitmap、GL或者Path路徑,同時它可以配合Matrix矩陣類給圖像做旋轉、縮放等操作,同時Canvas類還提供了裁剪、選取等操作。

Paint - 可以把它看做一個畫圖工具,比如畫筆、畫刷。管理了每個畫圖工具的字體、顏色、樣式。

『陸』 如何把png文件轉為可用於android.graphics.BitmapFactory.decod

把包在linux下解包。改了在換進去

『柒』 求教,如何在Android中將圖片轉化為矩陣

Android本身的android.graphics.Bitmap實現
一般在Android使用圖片,都會用到這個類,這個類中有一個函數:
getPixels(int[] pixels, int offset, int stride, int x, int y, int width, int height)
Returns in pixels[] a of the data in the bitmap.
功能和你要求的類似,只不過返回的是一位數組,轉成二維數組應該不是問題吧。
使用是需注意,對於比較大的圖片,你的操作很可能會比較佔用內存,需要處理一下out of memory的exception。

閱讀全文

與androidpng轉bitmap相關的資料

熱點內容
如何登錄伺服器看源碼 瀏覽:522
如何做伺服器端 瀏覽:154
注冊伺服器地址指什麼 瀏覽:433
文本命令行 瀏覽:97
撲克牌睡眠解壓 瀏覽:192
rc4演算法流程圖 瀏覽:159
胡蘿卜解壓方法 瀏覽:35
掃描pdf格式軟體 瀏覽:876
程序員在銀行開賬戶 瀏覽:516
android資料庫下載 瀏覽:749
中午伺服器崩潰怎麼辦 瀏覽:425
產品經理和程序員待遇 瀏覽:442
解憂程序員免費閱讀 瀏覽:109
錄像免壓縮 瀏覽:508
總結所學過的簡便演算法 瀏覽:362
南昌哪些地方需要程序員 瀏覽:761
三台伺服器配置IP地址 瀏覽:175
如何用命令方塊連續對話 瀏覽:280
win7linux共享文件夾 瀏覽:304
命令符打開本地服務 瀏覽:601