この小さなトピックでは、Java で DGN を JPG に変換する方法について説明します。ステップワイズ アルゴリズムや、Java で DGN を JPG 画像にエクスポートするためのコード スニペットなど、すべての重要な情報が含まれています。画像のレンダリング プロセス中に DGN から JPG を制御するさまざまなプロパティを確認できます。
JavaでDGNをJPGにエクスポートする手順
- リポジトリ マネージャーから Aspose.CAD for Java をインストールします
- Image クラスのインスタンスを使用してソース DGN ファイルにアクセスします
- CadRasterizationOptions クラスのインスタンスを作成し、そのプロパティを設定します
- JpegOptions クラス オブジェクトをインスタンス化して、目的の JPG オプションを設定します
- save メソッドを使用して、読み込んだ DGN を JPG に変換します。
前述の手順では、Java で DGN を JPEG に変換するアルゴリズムについて説明しました。これにより、環境を構成し、入力 DGN ファイルをロードします。続いて、画像サイズ、スケーリングなどのさまざまなプロパティを設定し、最後に画像を JPG ファイルとしてレンダリングします。
Java で DGN を JPG に変換するコード
import com.aspose.cad.Color; | |
import com.aspose.cad.Image; | |
import com.aspose.cad.License; | |
import com.aspose.cad.fileformats.dgn.DgnImage; | |
import com.aspose.cad.imageoptions.CadRasterizationOptions; | |
import com.aspose.cad.imageoptions.JpegOptions; | |
public class ConvertDGNToJPG { | |
public static void main(String[] args) throws Exception { // main method to convert DGN to JPG image using Java | |
String fPath= "D:/TestData/"; | |
// Initialize a license to convert DGN to JPEG | |
License licenseDGNtoJPG= new License(); | |
licenseDGNtoJPG.setLicense(fPath + "Conholdate.Total.Product.Family.lic"); | |
String srcDGNFile = fPath + "Nikon_D90_Camera.dgn"; | |
String outputJPGFile = fPath + "Nikon_D90_Camera.jpg"; | |
// Open the DGN file from the disk | |
DgnImage dgnImage = (DgnImage)Image.load(srcDGNFile); | |
// Create the PdfOptions object for the desired PDF | |
JpegOptions jpgOptions = new JpegOptions(); | |
// Initialize the vector rasterization options | |
CadRasterizationOptions dgnRasteroptions = new CadRasterizationOptions(); | |
dgnRasteroptions.setPageWidth(600); | |
dgnRasteroptions.setPageHeight(300); | |
dgnRasteroptions.setAutomaticLayoutsScaling(true); | |
dgnRasteroptions.setNoScaling(true); | |
// Convert DGN to JPG Image | |
dgnImage.save(outputJPGFile, jpgOptions); | |
} | |
} |
この例は、いくつかの API 呼び出しを使用して Java で DGN を JPG にレンダリングするために使用できます。 CadRasterizationOptions クラスは、自動レイアウト スケーリング、レイヤー、余白、品質などのプロパティを設定することにより、DGN ファイルのレンダリングをカスタマイズするために使用されます。JpegOptions クラスは、目的の出力 JPG 画像エクスポート オプションを設定するために使用されます。
このトピックでは、DGN ファイルを Java で JPG にエクスポートする方法を学習しました。 DWG を SVG イメージにエクスポートすることに関心がある場合は、JavaでDWGをSVGに変換する方法 の記事を参照してください。