이미지의 일부 내보내기
Contents
[
Hide
]이미지의 일부 내보내는 방법
문제: 이미지의 일부를 내보내는 방법 (CADNET-504).
팁: 이를 위해 RenderPartOfImage 메서드를 사용할 수 있으며, 이 메서드는 현재 뷰포트를 찾아서 교체합니다.
예제:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void RenderPartOfImage(PointF topLeft, double tileWidth, double tileHeight, string outputFileName) | |
{ | |
CadVportTableObject newView = new CadVportTableObject(); | |
System.Console.WriteLine("Top left = " + topLeft.X + " " + topLeft.Y + " width= " + tileWidth + " height= " + tileHeight); | |
// note: exactly such table name is required for active view | |
newView.Name = "*Active"; | |
newView.CenterPoint.X = topLeft.X + (tileWidth / 2); | |
newView.CenterPoint.Y = topLeft.Y - (tileHeight / 2); | |
newView.ViewHeight.Value = tileHeight; | |
newView.ViewAspectRatio.Value = tileWidth / tileHeight; | |
// search for active viewport and replace it | |
for (int i = 0; i < cadImage.ViewPorts.Count; i++) | |
{ | |
CadVportTableObject currentView = (CadVportTableObject)(cadImage.ViewPorts[i]); | |
if ((currentView.TableName == null && cadImage.ViewPorts.Count == 1) || | |
string.Equals(currentView.TableName.ToLowerInvariant(), "*active")) | |
{ | |
cadImage.ViewPorts[i] = newView; | |
break; | |
} | |
} | |
PngOptions pngOptions = GetSaveOptions(true); | |
pngOptions.VectorRasterizationOptions.PageHeight = (float)tileHeight * 100f; | |
pngOptions.VectorRasterizationOptions.PageWidth = (float)tileWidth * 100f; | |
cadImage.Save(outputFileName, pngOptions); | |
} |