I need to do the following: I have the URL of an image file. Now I need to get that image, and copy it to a specific folder on my own server, in 4 different thumbnail versions. Can someone help me how to do that in ASP.NET/C#?
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
jl2424
0 Points
8 Posts
Copy an image from an URL to own server and resize it
Apr 26, 2009 04:30 PM|LINK
I need to do the following: I have the URL of an image file. Now I need to get that image, and copy it to a specific folder on my own server, in 4 different thumbnail versions. Can someone help me how to do that in ASP.NET/C#?
nizam133
Contributor
3538 Points
638 Posts
Re: Copy an image from an URL to own server and resize it
Apr 26, 2009 05:15 PM|LINK
Hi, hey here a function for you which will resize the image, and also you can specify to have thimbnail version of your image
public static string ResizetheImage(string imageName, double csWidth, double csHeight, bool isThumbNail, string strType) { string newImagePath = string.Empty; string newImageName = string.Empty; string newImageURL = string.Empty; string strPath = string.Empty; string ImageURL = string.Empty; string name, extension; string strRandomCode = string.Empty; try { strPath = "UserImageDirecoryPath_pleasespecify"ImageURL = "ImageREADURL_You can specifythis" extension = imageName.Substring(imageName.LastIndexOf(".") + 1); if (!isThumbNail) {strRandomCode = Utilities.GenerateRandomCode(8); newImagePath = strPath + @"Temp\" + strRandomCode + "." + extension; newImageURL = ImageURL + @"Temp\" + strRandomCode + "." + extension; } else { name = imageName.Substring(0, imageName.LastIndexOf(".")); newImagePath = strPath + name + strType + extension; newImageURL = string.Empty; } double pictureAspectRatio = 0; int newWidth = 0, newHeight = 0, centeringFactor = 0; if (!File.Exists(strPath + imageName)) return string.Empty; Image picture = Image.FromFile(strPath + imageName); double csAspectRatio = csWidth / csHeight; Rectangle rect = new Rectangle(); double pictureWidth = picture.Width; double pictureHeight = picture.Height; // here 70 is the poup image width and height<input id="gwProxy" type="hidden"><input onclick="jsCall();" id="jsProxy" type="hidden"><div id="refHTML"></div>Gary yang - ...
All-Star
25901 Points
2588 Posts
Re: Copy an image from an URL to own server and resize it
Apr 30, 2009 04:33 AM|LINK
Hi jl2424,
Based on your description, It seems that you want to finish the following functions:
First: Download the image with Url.
Second: Resize the image and save it into disk.
For the first requirement, please try to solve it by using WebClient class. Please try to refer to the following code:
For the second requirement, please try to refer to the code below:
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
nareshprakas...
Participant
1396 Points
285 Posts
Re: Copy an image from an URL to own server and resize it
Apr 30, 2009 04:37 AM|LINK
See below link. I hope it is helpful for you.
http://dotnet-naresh.blogspot.com/
Naresh Prakash.
Click Here : SKY IS NOT THE LIMIT
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.