帮助从调整大小的图像中获取数据

发布于 2024-10-10 21:52:09 字数 690 浏览 0 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妳是的陽光 2024-10-17 21:52:09

您需要创建一个MemoryStream并对其调用Bitmap.Save

然后您可以调用MemoryStream.ToArray()。

You need to create a MemoryStream and call Bitmap.Save to it.

You can then call MemoryStream.ToArray().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文