Question

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?

Was it helpful?

Solution

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

You can then call MemoryStream.ToArray().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top