I'm not good at putting up a question, feel free to reword/retag this to make it more understandable. Thanks.
I have an image proxy page helps me handle all requests to images of product with custom manipulation values. For example:
http://mysite.com/ImageProxy.aspx?id={ITEM ID}&width={WIDTH}&height={HEIGHT}&gloss={GLOSS}&reflection={REFLECTION}
To reduce server-side loads, I cache by saving the files of already generated images for reuse when the same product with same manipulation values are called.
This works at the beginning but is getting slower when more images shown in a single page. I want to know how I can improve this situation, or is image proxy tends to be slow by its natural?
*E开发者_StackOverflowdited: *
I am:
- developing with
ASP.NET MVC
- using
System.Drawing.Drawing2D
,System.Drawing.Imaging
to manipulate images. - Currently a page is about ~500kb in size *(of result page) with 8~10 images per page and 30~50kb (PNG) for each image.
- image is currently PNG with transparency as reflection and rounded-corner effects as there as option and image may sit on various of background solid background color (ie/ GIF may be an option).
Try this:
// GetCacheFileName -> Returns the full path of the "cached" image
// CreateImage -> Used to create a new image if necessary
string cacheFile = GetCacheFileName(param1, param2, param3, param4);
if (!File.Exists(cacheFile))
{
Image cacheImage = CreateImage(param1, param2, param3, param4);
cacheImage.Save(cacheFile, ImageFormat.Jpeg);
}
Response.ContentType = "image/jpeg";
Response.TransmitFile(cacheFile);
The two things to notice here are:
- Tell the framework to save the image as jpeg
- Save the file to disk and use Response.TransmitFile instead of Response.WriteFile or Response.OutputStream.Write
精彩评论