2014-04-16 4 views
0

표준 WMF 파일은 GDI 명령 레코드 다음에 18 바이트 헤더를 사용한다는 것을 알고 있습니다. 간단한 웹 검색은 "표준 헤더 앞에 다른 헤더를 배치하는 두 가지 추가 WMF 변형이 있습니다. 배치 가능 메타 파일은 페이지에서 이미지를 배치하기 위해 x-y 좌표를 포함하는 22 바이트 헤더를 사용합니다." 하지만 이런 종류의 메타 파일 유형에 대한 실제 응용 프로그램이 부족하지는 않습니까? 이 유형은 표준 WMF와 비교하여 어떤 종류의 요구 사항을 처리해야합니까? 관심이있는 이유는 무엇입니까? 나는 다시 크기와는 META 파일에서 비트 맵을 구성하려고 시점에서 실패 GIF에 WMF 변환 다음과 같은 코드가 있습니다배치 가능한 메타 파일 크기 변경

public Stream Resize(string filePath, int maxSize) 
    { 
     try 
     { 
      MemoryStream stream = new MemoryStream(); 

      using (Metafile img = new Metafile(filePath)) 
      { 
       MetafileHeader header = img.GetMetafileHeader(); 
       float scale = header.DpiX/96f; 

       var newSize = CalcaulateSize(img.Width, img.Height, maxSize); 

       using (Bitmap bitmap = new Bitmap((int)(scale * img.Width/header.DpiX * 100), (int)(scale * img.Height/header.DpiY * 100))) 
       { 
        using (Graphics g = Graphics.FromImage(bitmap)) 
        { 
         g.Clear(Color.White); 
         g.ScaleTransform(scale, scale); 
         g.DrawImage(img, 0, 0); 
        } 

        var resizedBitmap = new Bitmap(newSize.Width, newSize.Height); 

        using (var g2 = Graphics.FromImage(resizedBitmap)) 
        { 
         g2.CompositingQuality = CompositingQuality.HighQuality; 
         g2.InterpolationMode = InterpolationMode.HighQualityBicubic; 
         g2.SmoothingMode = SmoothingMode.AntiAlias; 
         g2.PixelOffsetMode = PixelOffsetMode.HighQuality; 
         g2.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; 
         g2.TextContrast = 12; 
         g2.Clear(Color.White); 
         g2.DrawImage(bitmap, 0, 0, newSize.Width, newSize.Height); 
        } 

        resizedBitmap.Save(stream, ImageFormat.Gif); 
       } 

       stream.Position = 0; 
      } 

      return stream; 
     } 
     catch (Exception) 
     { 
      return null; 
     } 

을하고 예외 "인수가 유효하지 않습니다"를 제기한다.

(INT) (* 스케일 img.Width/header.DpiX * 100) = 22,181 (INT) (* 스케일 img.Height/header.DpiY * 100)) = 33,718

[너무 많은 메모리 한 번에 하나의 비트 맵에 모두 할당되어 즉각적인 예외가 발생 함]

첨부 코드를 변경하여 배치 가능한 메타 파일을 어떻게 변환 하시겠습니까?

답변

0

크기 계산이 꺼져있는 것 같습니다.

내 C++ 코드를 보면, hEMF가 메타 파일의 핸들 인 확장 메타 파일 헤더의 정보를 기반으로 계산됩니다. 그런 다음이 치수를 사용하여 그래픽을 사용하여 이미지를 직접 화면에 그립니다.

희망 또는 MSDN link 조금 도와주세요. 더 이상 미안해.

 ENHMETAHEADER emh; 
    UINT nBytes = ::GetEnhMetaFileHeader(hEMF, sizeof(ENHMETAHEADER), &emh); 
    if (nBytes != 0) { 
     RECT rect{ // Based on info from http://support.microsoft.com/kb/230675 
      (int) ((float) (emh.rclFrame.left) * emh.szlDevice.cx/(emh.szlMillimeters.cx*100.0f)), // Left 
      (int) ((float) (emh.rclFrame.top) * emh.szlDevice.cy/(emh.szlMillimeters.cy*100.0f)),  // Top 
      (int) ((float) (emh.rclFrame.right) * emh.szlDevice.cx/(emh.szlMillimeters.cx*100.0f)), // Right 
      (int) ((float) (emh.rclFrame.bottom) * emh.szlDevice.cy/(emh.szlMillimeters.cy*100.0f)) // Bottom 
     }; 
     bounds.x = abs(rect.right - rect.left); 
     bounds.y = abs(rect.bottom - rect.top);