2014-06-17 2 views
0

안녕하세요. 다음 코드는 두 개의 txt 상자가있는 WPF 양식 뒤에 있습니다. 1은 이미지의 src이고 다른 하나는 대상 경로입니다. WPF 형식을 사용하는 GDI +에서 일반적인 오류가 발생했습니다.

private void Button_Click(object sender, RoutedEventArgs e) 
    { 
     ProcessLbl.Content = ""; 
     string src = ImgSrc.Text; 
     string dest = ImgDest.Text; 
     string copyrightTxt = CopyWriteTxt.Text; 
     string[] filePaths = Directory.GetFiles(src, "*.jpg"); 
     MemoryStream ms = null; 
     foreach (string f in filePaths) 
     { 
      try 
      { 
       ProcessLbl.Content += src + "\\" + f.ToString() + Environment.NewLine; 
       System.Drawing.Image thumbnail_image = null; 
       System.Drawing.Image original_image = null; 
       System.Drawing.Bitmap final_image = null; 
       System.Drawing.Graphics graphic = null; 
       original_image = System.Drawing.Image.FromFile(System.IO.Path.Combine(src,f)); 

       int width = original_image.Width; 
       int height = original_image.Height; 
       int target_width = 500; 
       int target_height = 367; 
       int new_width, new_height; 

       float target_ratio = (float)target_width/(float)target_height; 
       float image_ratio = (float)width/(float)height; 

       if (target_ratio > image_ratio) 
       { 
        new_height = target_height; 
        new_width = (int)Math.Floor(image_ratio * (float)target_height); 
       } 
       else 
       { 
        new_height = (int)Math.Floor((float)target_width/image_ratio); 
        new_width = target_width; 
       } 

       new_width = new_width > target_width ? target_width : new_width; 
       new_height = new_height > target_height ? target_height : new_height; 
       final_image = new System.Drawing.Bitmap(target_width, target_height); 
       graphic = System.Drawing.Graphics.FromImage(final_image); 
       graphic.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.ColorTranslator.FromHtml("#c2c6c9")), new System.Drawing.Rectangle(0, 0, target_width, target_height)); 
       int paste_x = (target_width - new_width)/2; 
       int paste_y = (target_height - new_height)/2; 

       graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; 
       graphic.DrawImage(original_image, paste_x, paste_y, new_width, new_height); 
       final_image.Save(System.IO.Path.Combine(dest, f), System.Drawing.Imaging.ImageFormat.Jpeg); 
      } 
      catch (Exception ResizeExp) 
      { 
       System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ResizeExp, true); 
       ProcessLbl.Content += Environment.NewLine; 
       ProcessLbl.Content += Environment.NewLine; 
       ProcessLbl.Content += ResizeExp.Message + " " + trace.GetFrame(0).GetFileLineNumber(); 
       ProcessLbl.Content += Environment.NewLine; 
       ProcessLbl.Content += Environment.NewLine; 
      } 
     } 
     //ProcessLbl 
    } 
} 

나는 몇 가지 유사한 코드는 웹 페이지에서 실행하고 그것이 내가 얻을 어떤 이유로 오류

누구든지 도움이 될 수 있습니다 "일반 오류가 + GDI 발생을"잘 작동하지만 형성?

감사합니다.

답변

0

지정된 대상에 비트 맵을 저장할 적절한 권한이 있는지 확인하십시오. 다른 위치를 사용해보고 오류가 해결되는지 확인하십시오.이 위치 자체를 사용해야하는 경우 매니페스트 수정을 통해 관리자 권한을 획득해야합니다.

관련 문제