帮助从调整大小的图像中获取数据
我使用 ASP.NET 文件上传控件,然后调整图像大小并将新图像存储在新的位图中。这是我到目前为止的代码:
protected void ResizeImage()
{
Bitmap originalBMP = new Bitmap(FileUpload1.FileContent);
//Calculate new image dimensions
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
int sngRatio = origWidth / origHeight;
int newWidth = 100;
int newHeight = newWidth / sngRatio;
Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
}
我直接上传到 Amazon S3,我需要将一些数据传递到其上传方法。如何从我一直在文件上传中使用的新位图获取以下信息?:
FileUpload1.FileBytes
FileUpload1.FileBytes.Length
我是否需要将新位图保存到流中以便获取字节数组?
I'm using an ASP.NET file upload control and then resizing an image and storing the new image in a new Bitmap. Here is the code I have so far:
protected void ResizeImage()
{
Bitmap originalBMP = new Bitmap(FileUpload1.FileContent);
//Calculate new image dimensions
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
int sngRatio = origWidth / origHeight;
int newWidth = 100;
int newHeight = newWidth / sngRatio;
Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
}
I'm uploading directly to Amazon S3 and I need to pass some data to its upload method. How do I get the following information from my new bitmap that I have been using with the fileupload?:
FileUpload1.FileBytes
FileUpload1.FileBytes.Length
Do I need to save my new bitmap to a stream so I can get an array of bytes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个
MemoryStream
并对其调用Bitmap.Save
。然后您可以调用MemoryStream.ToArray()。
You need to create a
MemoryStream
and callBitmap.Save
to it.You can then call
MemoryStream.ToArray()
.