Richard77
Richard77

Reputation: 21621

how can I resize an image keeping its dimensions ratio when the file has just been uploaded by the user (as opposed to residing in the C drive)

Few days ago, I posted a question on how to resize an image while keeping the ratio of its dimensions. I get an nice answer which helped me understand how to do so.

Unfortunately, I've not been yet capable of exploiting that to solve my problem. The main problem resides in the type of file used to process the image.

1° in the answer it's about creating an image file of type

System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile("C:/path + filename");

2° In my case I'm getting an image uploaded by the user in my actionResult

public ActionResult UpLoadImage(HttpPostedFileBase image)
{
   //Now do something with image..
}

I've difficulty to create an Image object, first of all, because of the way the file System.Drawing.Image is created. ...FromFile(OriginalFile) where OriginalFile is the name + path of the image "C:/path/filename".

But the file I have has been uploaded and reside in a Database. And to access it, I make a query to the database.

To make the long story short, how can I resize an image keeping its dimensions ratio when the file has just been uploaded by the user (as opposed to residing in the C drive).

EDIT

How about if I want to save it (not to a c drive but) to a database? So far, what I do is to save (i) the image's data as byte and (ii) the Mime type as a string.

How do I save the Image of type ystem.Drawing.Image to database using the same Technicals?

Thanks for helping

Upvotes: 0

Views: 409

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038780

You can try loading the image from stream (Image.FromStream method).

Upvotes: 2

Related Questions