當前位置:首頁 » 安卓系統 » bitmap轉byteandroid

bitmap轉byteandroid

發布時間: 2023-03-15 11:23:46

❶ 如何將從圖庫中查到的圖片轉換成 二進制 android 代碼

1、獲得圖庫返回的URL
2、根據URL獲得圖片的本地絕對地址,構建Bitmap
3、將Bitmap轉換成byte[]數組

public void onActivityResult(int requestCode, int resultCode, Intent data) {

Uri uri = data.getData();

String path=uri.getPath();
Bitmap bitmap = BitmapFactory.decodeFile(path,);
byte[] datas=bitmap2Bytes(bitmap );
}

public byte[] bitmap2Bytes(Bitmap bm) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}

❷ android bitmap對象怎樣轉化成uri

//Bitmap轉byte數組publicbyte[]Bitmap2Bytes(Bitmapbm){ByteArrayOutputStreambaos=newByteArrayOutputStream();bm.compress(Bitmap.CompressFormat.PNG,100,baos);//png類型returnbaos.toByteArray();}//寫到sdcard中publicvoidwrite(byte[]bs)throwsIOException{FileOutputStreamout=newFileOutputStream(newFile("/sdcard/test.png"));out.write(bs);out.flush();out.close();}先將Bitmap轉byte數組,然後再將byte數組寫到sdcard中。

❸ 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 - 可以把它看做一個畫圖工具,比如畫筆、畫刷。管理了每個畫圖工具的字體、顏色、樣式。

❹ 能不能將像素數組轉化成android里的Bitmap呢

如果有顏色數組int c[]=....
android中用創建
Bitmap m=Bitmap.createBitmap(c, 640,480, Config.ARGB_8888);
這樣最悶隱粗直接,按理螞鎮也最快攜歷。必須用ARGB_8888才能使用透明alpha數據。

也可以 setPixels方法也一樣。

❺ 如何將BitmapImage轉換為byte[]

這樣可以: [mw_shl_code=csharp,true] Uri uri = new Uri("ms-appx:///Assets/logo.png"); RandomAccessStreamReference streamRef = RandomAccessStreamReference.CreateFromUri(uri); // Create a buffer for reading the stream Windows.Storage.Streams.Buffer buffer = null; // Read the entire file into buffer using ( fileStream = await streamRef.OpenReadAsync()) { buffer = new Windows.Storage.Streams.Buffer((uint)fileStream.Size); await fileStream.ReadAsync(buffer, (uint)fileStream.Size, InputStreamOptions.None); } // Read buffer into byte array DataReader reader = DataReader.FromBuffer(buffer); byte[] imageBytes = new byte[buffer.Length]; reader.ReadBytes(imageBytes);[/迅悉mw_shl_code]樓主試試,成蠢昌激不成帶襪給個信 到DEVDIV.COM網站查看回答詳情>>

❻ Android Bitmap轉為Byte[]的問題

C輸出的是地址,每次運行從新構建對象,地址改變,但是指向的值不變

❼ android bitmap怎麼轉byte數組

ByteArrayOutputStreamstream=newByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG,100,stream);
byte[]byteArray=stream.toByteArray();

❽ android如何把byte數據存到內存中並轉為bitmap,求高手~~~~~~~~~~~~~~~~~~~~~~~~~~~

import java.io.File;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class MainAct extends Activity {
private ImageView img;
//圖片路徑
private String filepath = "/sdcard/sample.jpg";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
img = (ImageView) findViewById(R.id.img);
File file = new File(filepath);
if (file.exists()) {
Bitmap bm = BitmapFactory.decodeFile(filepath);
//將圖片顯示到ImageView中
img.setImageBitmap(bm);
}
}
}

請參考

❾ android byte[]轉化成bitmap 發生了錯誤,要如何解決呢大神快來呀 高懸賞

建議使用BitmapFactory的其他decode方法,如果是網路讀過來的流,最好在本地存成文件緩存,然後通過decodeFileDescriptor方法就沒這種問題了。
你可以看一下這里 http://www.thinksaas.cn/group/topic/203384/,也碰到了類似的問題

❿ android上傳圖片到php android用bitmap.compress壓縮為byte流 php怎麼解壓轉為圖片啊

android 文件上傳,自己封裝了個方法,
<?php
var_mp($_POST);
var_mp($_FILES);
foreach($_FILES as $key => $value){
move_uploaded_file($_FILES[$key]['tmp_name'],
$_SERVER['DOCUMENT_ROOT'].'/FileUpload/files/'.$_FILES[$key]['name']);
}
?>
PHP就這樣接受了

熱點內容
安卓內存大小有什麼影響 發布:2025-05-12 04:41:36 瀏覽:48
以下c語言常量錯誤的是 發布:2025-05-12 04:40:39 瀏覽:806
怎麼降低qq版本安卓80 發布:2025-05-12 04:40:39 瀏覽:189
一個密碼多少人知道後就不是秘密 發布:2025-05-12 04:26:07 瀏覽:520
ftp埠非21 發布:2025-05-12 04:09:09 瀏覽:228
雲伺服器屏蔽ip 發布:2025-05-12 04:08:47 瀏覽:911
為什麼安卓介面充電線松 發布:2025-05-12 03:41:20 瀏覽:669
安卓手機打擊墊怎麼玩 發布:2025-05-12 03:23:14 瀏覽:241
phpexplode 發布:2025-05-12 03:15:33 瀏覽:73
雙色球怎麼演算法 發布:2025-05-12 03:15:31 瀏覽:559