我正在爲我的照片作品組建一個相冊。但我在以下問題上自問:縮略圖和相冊
是否應該將縮略圖版本保存在服務器上的文件系統上,還是應該在請求縮略圖時動態生成縮略圖?
我猜存儲縮略圖的專業人員在服務器上的處理較少,因爲它只生成一次文件(上傳文件時)。但缺點是,如果我決定有一天縮略圖大小不對,我有一個問題。此外,我現在存儲2個文件(拇指加原件)。
那麼,縮略圖是否存在最佳尺寸?我想答案是 - 你想存儲多少縮略圖。我的問題是,我的thumnails正在調整到最高150或最高150寬。但是,這些文件的大小仍然在4萬左右。
我使用這個:
public void ResizeImage(string originalFile, string newFile, int newWidth, int maxHeight, bool onlyResizeIfWider)
{
System.Drawing.Image fullsizeImage = System.Drawing.Image.FromFile(MapPath(GlobalVariables.UploadPath + "/" + originalFile));
// Prevent using images internal thumbnail
fullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
fullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
if (onlyResizeIfWider)
{
if (fullsizeImage.Width <= newWidth)
{
newWidth = fullsizeImage.Width;
}
}
int newHeight = fullsizeImage.Height * newWidth/fullsizeImage.Width;
if (newHeight > maxHeight)
{
// Resize with height instead
newWidth = fullsizeImage.Width * maxHeight/fullsizeImage.Height;
newHeight = maxHeight;
}
System.Drawing.Image newImage = fullsizeImage.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);
// Clear handle to original file so that we can overwrite it if necessary
fullsizeImage.Dispose();
// Save resized picture
newImage.Save(MapPath(GlobalVariables.UploadPath + "/" + newFile));
}
有沒有減少文件大小的方式,如150高/ 150寬是非常小的。我想上升到250左右,但如果我顯示12個拇指......需要一段時間才能加載。
感謝您的信息塊。很有幫助。有了質量,我使用了System.Drawing.Image - 而這個對象類型沒有提到的屬性。我應該使用位圖來代替,然後一直保存爲Jpeg,一旦使用了上述的屬性? – Craig 2011-12-28 06:08:35
@cdotlister是使用更好的更詳細的縮略圖程序,你可以控制更多的想法。 – Aristos 2011-12-28 06:25:41
謝謝 - 我不確定如何在我的位圖上使用這些屬性... BitmapObject.InterpolationMode不起作用。 – Craig 2011-12-28 06:40:11