//根据文件名(完全路径) 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; } //java/4482