2011-12-28 2 views
1

나는 내 사진 포트폴리오를위한 포토 앨범을 제작 중입니다. 하지만 다음과 같은 질문을하고 있습니다.썸네일과 포토 앨범

썸네일 버전을 서버의 파일 시스템에 저장해야합니까? 아니면 썸네일 이미지가 요청되면 썸네일을 동적으로 생성해야합니까?

파일을 한 번 생성하면 (파일을 업로드 할 때) 썸네일 저장에 대한 장점이 서버에서 덜 처리된다고 생각합니다. 하지만 축소판 축소 크기가 언젠가 결정된다면 문제가있을 수 있습니다. 또한 2 개의 파일을 저장합니다 (Thumb plus 원본).

그런 다음 축소판에 가장 적합한 크기가 있습니까? 내 생각에 그 대답은 - 엄지 손톱을 얼마나 저장할 것이냐하는 것입니다. 내 문제는 내 thumnails가 150 최대 또는 최대 150 최대의 최대로 크기가 조정되고있다입니다. 그러나 파일 크기는 여전히 약 40k에 이릅니다.

내가 이것을 사용하고 있습니다 :

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 점의 엄지 손가락을 보여 주면 ...로드하는 데 시간이 걸립니다.

답변

2

예 썸네일 파일로 저장해야하며 항상 처리하지 않아야합니다.

이미지에 대해서는 이미지를 분할하고 압축하는 데 사용되는 크기이기 때문에 8x8 또는 16x16 크기의 배열 블록에 절대적으로 맞도록하십시오. 예를 들어, 그것은 150 × 150 8분의 150 = 18.75 때문에 확인 파일 크기를 줄이기 152x152 때문에 8분의 152 = 19 개

후 속성을 사용하고있다

g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; 
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; 
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 

을 품질을 변경하고 여기에 예시되어 있지 How to: Use Interpolation Mode to Control Image Quality During Scaling

+0

감사합니다. 블록 정보. 매우 도움이됩니다. 품질면에서 System.Drawing.Image를 사용하고 있습니다.이 객체 유형은 언급하지 않았습니다. 내가 비트 맵을 대신 사용하고 위에 언급 된 속성을 사용하여 항상 Jpeg로 저장해야합니까? – Craig

+0

@cdotlister 예 더 많은 생각을 제어 할 수있는 더 자세한 섬네일 절차를 사용하십시오. – Aristos

+0

감사합니다 - 비트 맵에서 이러한 속성을 사용하는 방법을 잘 모르겠습니다 ... BitmapObject.InterpolationMode가 작동하지 않습니다. – Craig