Ayuda para obtener datos de una imagen redimensionada

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?:


Do I need to save my new bitmap to a stream so I can get an array of bytes?

preguntado el 08 de enero de 11 a las 23:01

Using the Bitmap constructor will give you extremely poor quality images with lots of artifacts. Also, I hope you're using the using(){} clause around both Bitmap instances, because as-is that code will crash the server at 20-100 requests. I suggest you use a library designed to do server-safe image resizing instead, it's easier than avoiding the 29 pitfalls on your own. -

1 Respuestas

Necesitas crear un MemoryStream y llama Bitmap.Save a la misma.

Entonces puedes llamar MemoryStream.ToArray().

Respondido el 09 de enero de 11 a las 03:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.