//把指定路径的图片转化为二进制
073 |
public byte[] GetPictureData(string imagepath) |
076 |
FileStream fs = new FileStream(imagepath, FileMode.Open); |
077 |
byte[] byData = new byte[fs.Length]; |
078 |
fs.Read(byData, 0, byData.Length); |
083 |
protected string btnAdd_Click(object sender, EventArgs e) |
086 |
HttpPostedFile upPhoto = UpPhoto.PostedFile; |
087 |
int upPhotoLength = upPhoto.ContentLength; |
088 |
byte[] PhotoArray = new Byte[upPhotoLength]; |
089 |
Stream PhotoStream = upPhoto.InputStream; |
090 |
PhotoStream.Read(PhotoArray, 0, upPhotoLength); |
091 |
return Encoding.UTF8.GetString(PhotoArray); |
095 |
HttpContext.Current.Response.ContentType = "application/octet-stream" ; |
096 |
HttpContext.Current.Response.BinaryWrite(PhotoArray); |
099 |
public System.Drawing.Image ReturnPhoto(byte[] streamByte){ |
100 |
System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte); |
101 |
System.Drawing.Image img = System.Drawing.Image.FromStream(ms); |
106 |
public byte[] PhotoImageInsert(System.Drawing.Image imgPhoto){ |
108 |
MemoryStream mstream = new MemoryStream(); |
109 |
imgPhoto.Save(mstream, System.Drawing.Imaging.ImageFormat.Bmp); |
110 |
byte[] byData = new Byte[mstream.Length]; |
111 |
mstream.Position = 0; |
112 |
mstream.Read(byData, 0, byData.Length); |
121 |
public static byte[] StringToByteArray(string str) |
122 |
{ return Encoding.UTF8.GetBytes(str); } |
124 |
public static string ByteArrayToString(byte[] bytes) |
125 |
{ return Encoding.UTF8.GetString(bytes); } |
|