本文介绍了我需要获取图像的二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实际上我上传了一张图片,然后根据需要使用Image resizer和imazen.crop裁剪上传的图片。现在我需要将裁剪的图像存储到sql server中。所以我需要将裁剪后的图像的二进制数据存储到数据库。
任何人都可以帮助我。
我可以获取上传图片的二进制数据。代码如下...
那么,现在如何获取被裁剪图像的二进制数据?
我尝试了什么:
Actually I uploaded a image and then Crop the uploaded image as desired using Image resizer and imazen.crop.Now i need to store the cropped image into sql server.So I need the binary data for the cropped image to be stored into the database.
Can Anyone Please help me.
I can get the binary data for the uploaded image.Code is below...
So, now how to get the binary data for the image that is cropped?
What I have tried:
int length = FileUpload1.PostedFile.ContentLength;
//create a byte array to store the binary image data
byte[] imgbyte = new byte[length];
//store the currently selected file in memeory
HttpPostedFile img = FileUpload1.PostedFile;
//set the binary data
img.InputStream.Read(imgbyte, 0, length);
string sql = "Insert into Files(FileName,FileContent,Keyword)values('" + txtImage.Text + "', @FileContent ,'" + TextBox1.Text + "')";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@FileContent", SqlDbType.Image).Value = imgbyte;
推荐答案
MemoryStream ms = new MemoryStream();
myImage.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
byte[] myImageData = ms.ToArray();
这篇关于我需要获取图像的二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!