php把圖片轉換成二進制
enctype="multipart/form-data"
http://ke..com/view/3247116.htm
你也可以看看這個理解一下
Ⅱ php將圖片轉為二進制後,我想得到二進制的數據,但是直接在瀏覽上輸出會亂碼
如果 你是想保存成圖片文件的話, 那你就把二進制數據寫到文件里, 記得文件後綴是 gif
For Example:
file_put_contents('1.gif', $a);
Ⅲ 怎麼將圖片轉換成二進制,存入資料庫,然後怎麼讀出來並顯示
1.將Image圖像文件存入到資料庫中
我們知道資料庫里的Image類型的數據是"二進制數據",因此必須將圖像文件轉換成位元組數組才能存入資料庫中.
要這里有關數據的操作略寫,我將一些代碼段寫成方法,方便直接調用.
//根據文件名(完全路徑)
public byte[] SetImageToByteArray(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open);
int streamLength = (int)fs.Length;
byte[] image = new byte[streamLength];
fs.Read(image, 0, streamLength);
fs.Close();
return image;
}
//另外,在ASP.NET中通過FileUpload控制項得到的圖像文件可以通過以下方法
public byte[] SetImageToByteArray(FileUpload FileUpload1)
{
Stream stream = FileUpload1.PostedFile.InputStream;
byte[] photo = new byte[FileUpload1.PostedFile.ContentLength];
stream.Read(photo, 0, FileUpload1.PostedFile.ContentLength);
stream.Close();
return photo;
}
2.從sql Server資料庫讀取Image類型的數據,並轉換成bytes[]或Image圖像文件
//要使用SqlDataReader要載入using System.Data.SqlClient命名空間
//將資料庫中的Image類型轉換成byte[]
public byte[] SetImage(SqlDataReader reader)
{
return (byte[])reader["Image"];//Image為資料庫中存放Image類型欄位
}
//將byte[]轉換成Image圖像類型
//載入以下命名空間using System.Drawing;/using System.IO;
using System.Data.SqlClient;*/
public Image SetByteToImage(byte[] mybyte)
{
Image image;
MemoryStream mymemorystream = new MemoryStream(mybyte,0, mybyte.Length);
image = Image.FromStream(mymemorystream);
return image;
}
Ⅳ 如何將圖片轉換成二進制存儲
資源簡介圖片的常見存儲與讀取凡是有以下幾種:存儲圖片:以二進制的形式存儲圖片時,要把資料庫中的欄位設置為Image數據類型(SQL Server),存儲的數據是Byte[].1.參數是圖片路徑:返回Byte[]類型: public byte[] GetPictureData(string imagepath) { /**/////根據圖片文件的路徑使用文件流打開,並保存為byte[] FileStream fs = new FileStream(imagepath, FileMode.Open);//可以是其他重載方法 byte[] byData = new byte[fs.Length]; fs.Read(byData, 0, byData.Length); fs.Close(); return byData; }2.參數類型是Image對象,返回Byte[]類型: public byte[] PhotoImageInsert(System.Drawing.Image imgPhoto) { //將Image轉換成流數據,並保存為byte[] MemoryStream mstream = new MemoryStream(); imgPhoto.Save(mstream, System.Drawing.Imaging.ImageFormat.Bmp); byte[] byData = new Byte[mstream.Length]; mstream.Position = 0; mstream.Read(byData, 0, byData.Length); mstream.Close(); return byData; }好了,這樣通過上面的方法就可以把圖片轉換成Byte[]對象,然後就把這個對象保存到資料庫中去就實現了把圖片的二進制格式保存到資料庫中去了。下面我就談談如何把資料庫中的圖片讀取出來,實際上這是一個相反的過程。讀取圖片:把相應的欄位轉換成Byte[]即:Byte[] bt=(Byte[])XXXX1.參數是Byte[]類型,返回值是Image對象: public System.Drawing.Image ReturnPhoto(byte[] streamByte) { System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); return img; }2.參數是Byte[] 類型,沒有返回值,這是針對asp.net中把圖片從輸出到網頁上(Response.BinaryWrite) public void WritePhoto(byte[] streamByte) { // Response.ContentType 的默認值為默認值為「text/html」 Response.ContentType = "image/GIF"; //圖片輸出的類型有: image/GIF image/JPEG Response.BinaryWrite(streamByte); }補充:針對Response.ContentType的值,除了針對圖片的類型外,還有其他的類型: Response.ContentType = "application/msword"; Response.ContentType = "application/x-shockwave-flash"; Response.ContentType = "application/vnd.ms-excel";另外可以針對不同的格式,用不同的輸出類型以適合不同的類型: switch (dataread("document_type")) { case "doc": Response.ContentType = "application/msword"; case "swf": Response.ContentType = "application/x-shockwave-flash"; case "xls": Response.ContentType = "application/vnd.ms-excel"; case "gif": Response.ContentType = "image/gif"; case "Jpg": Response.ContentType = "image/jpeg"; }立即獲得您的.
Ⅳ php 圖片以二進制流的形式存入資料庫。並且能顯示出來。
這個真不會。
Ⅵ php圖片以二進制的方式存儲在資料庫的問題
mysql自己有select語句,用這個來操作
比如說你每個圖片主碼設一個auto_increasment的id(自動以1,2,3這樣排序下去的方式存圖片),然後比如說一共有50張圖片,依次讀出for(i=0,i<50,i++){select
圖片
from
資料庫
where(圖片id=
i);}就這樣可以依次根據圖片的id讀下去。
Ⅶ php中如何將圖片轉成二進制呢
安卓蘋果的開發都可以支持類似windows的socket io 庫吧?
一般情況下,一個安卓應用 常用到的絕大部分圖片是存儲在手機端的,只有少量的必須獲取的才會下載,下載一般也是 net io
Ⅷ Thinkphp二進制圖片接收和轉換
可以直接用post接受二進制數據,然後用header函數輸出圖片,
Ⅸ php怎樣將圖片轉換成二進制或者是字元串
header("Content-type:image/jpeg");
$PSize=filesize('1.jpg');
$picturedata=fread(fopen('1.jpg',"r"),$PSize);
echo$picturedata;
或file_get_contents
Ⅹ php將圖片文件轉換成二進制輸出的方法
本文實例講述了php將圖片文件轉換成二進制輸出的方法。分享給大家供大家參考。具體實現方法如下:
1
2
3
4
header(
Content-type:
image/jpeg);
$PSize
=
filesize('1.jpg');
$picturedata
=
fread(fopen('1.jpg',
r),
$PSize);
echo
$picturedata;
就這么簡單4行代碼,就將圖片以二進制流的形式輸出到客戶端了,和打開一張圖片沒有任何區別。
這里需要注意的是,發送的header要根據具體情況而定,不一定都是image/jpeg。JPG的就是image/jpeg,但PNG的就是image/png.不同類型的圖片輸出不同的頭部。