2013-07-31 3 views
0

byte []를 이미지로 변환하는 코드가 있지만 내 코드는 항상 Portrait 모드 인 가로 모드로 작성합니다. 원본 이미지의 페이지 방향을 감지하고이 속성으로 새 이미지를 작성하려면 어떻게합니까? 어떤 제안?가로 또는 세로 속성이있는 이미지에 byte []를 쓰는 방법은 무엇입니까?

public void SendFax(byte[] file, string fileName) 
    { 
     try 
     { 
      MemoryStream ms = new MemoryStream(file); 
      Image imgSave = Image.FromStream(ms); 
      Bitmap bmSave = new Bitmap(imgSave); 
      Bitmap bmTemp = new Bitmap(bmSave); 
      Graphics grSave = Graphics.FromImage(bmTemp); 
      grSave.DrawImage(imgSave, 0, 0, imgSave.Width, imgSave.Height) 

      //Save Image to physical path 
      bmTemp.Save("C:/..." + fileName); 

      imgSave.Dispose(); 
      bmSave.Dispose(); 
      bmTemp.Dispose(); 
      grSave.Dispose(); 

     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 
    } 

답변

0

시도해보십시오. 비교를 기반으로 img 높이와 너비를 확인하여 초상화/경관을 결정하십시오.

int srcWidth = image.Width; 
int srcHeight = image.Height; 
int thumbWidth = width; 
int thumbHeight; 
Bitmap bmp; 
if (srcHeight > srcWidth) 
{ 
    thumbHeight = (srcHeight/srcWidth) * thumbWidth; 
    bmp = new Bitmap(thumbWidth, thumbHeight); 
} 
else 
{ 
    thumbHeight = thumbWidth; 
    thumbWidth = (srcWidth/srcHeight) * thumbHeight; 
    bmp = new Bitmap(thumbWidth, thumbHeight); 
}