直線の描画
この例では、Graphics クラスを使用して、イメージの表面に直線形状を描画します。操作をデモンストレーションするために、例では新しいイメージを作成し、Graphics クラスによって公開された DrawLine メソッドを使用して、イメージの表面に直線を描画します。まず、高さと幅を指定して PsdImage を作成します。
イメージが作成されたら、Graphics クラスによって公開された Clear メソッドを使用して背景色を設定します。Graphics クラスの DrawLine メソッドは、2つのポイント構造を結ぶイメージに直線を描画するために使用されます。このメソッドには、Pen クラスのインスタンスおよびポイントまたは構造体の座標ペアを引数として受け入れるいくつかのオーバーロードがあります。Pen クラスは、線、曲線、図形を描画するためのオブジェクトを定義します。Pen クラスには、指定された色、幅、およびブラシで線を描画するためのいくつかのオーバーロードされたコンストラクタがあります。SolidBrush クラスは、特定の色で連続して描画するために使用されます。最後に、イメージは bmp ファイル形式にエクスポートされます。以下のコードスニペットは、イメージの表面に直線形状を描画する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outpath = dataDir + "Lines.bmp"; | |
BmpOptions saveOptions = new BmpOptions(); | |
saveOptions.BitsPerPixel = 32; | |
// Create an instance of Image | |
using (Image image = new PsdImage(100, 100)) | |
{ | |
// Create and initialize an instance of Graphics class and Clear Graphics surface | |
Graphics graphic = new Graphics(image); | |
graphic.Clear(Color.Yellow); | |
// Draw two dotted diagonal lines by specifying the Pen object having blue color and co-ordinate Points | |
graphic.DrawLine(new Pen(Color.Blue), 9, 9, 90, 90); | |
graphic.DrawLine(new Pen(Color.Blue), 9, 90, 90, 9); | |
// Draw a four continuous line by specifying the Pen object having Solid Brush with red color and two point structures | |
graphic.DrawLine(new Pen(new SolidBrush(Color.Red)), new Point(9, 9), new Point(9, 90)); | |
graphic.DrawLine(new Pen(new SolidBrush(Color.Aqua)), new Point(9, 90), new Point(90, 90)); | |
graphic.DrawLine(new Pen(new SolidBrush(Color.Black)), new Point(90, 90), new Point(90, 9)); | |
graphic.DrawLine(new Pen(new SolidBrush(Color.White)), new Point(90, 9), new Point(9, 9)); | |
image.Save(outpath, saveOptions); | |
} |
楕円の描画
楕円の描画例は、描画された形状シリーズの2番目の記事です。Graphics クラスを使用して、イメージの表面に楕円形状を描画します。操作をデモンストレーションするために、例では新しいイメージを作成し、Graphics クラスによって公開された DrawEllipse メソッドを使用して、イメージの表面に楕円形状を描画します。まず、高さと幅を指定して PsdImage を作成します。
イメージを作成した後、Graphics クラスオブジェクトを作成して初期化し、Clear メソッドを使用してイメージの背景色を設定します。Graphics クラスの DrawEllipse メソッドは、矩形構造によって指定されたイメージ表面に楕円形状を描画するために使用されます。このメソッドには、Pen インスタンスと Rectangle/RectangleF クラスまたは座標ペア、高さ、幅を引数として受け入れるいくつかのオーバーロードがあります。Pen クラスは、線、曲線、図形を描画するために使用されるオブジェクトを定義します。Pen クラスには、指定された色、幅、ブラシで線を描画するためのいくつかのオーバーロードされたコンストラクタがあります。Rectangle クラスは、矩形の位置とサイズを表す4つの整数のセットを格納します。Rectangle クラスには、指定されたサイズと位置で矩形構造を描画するためのいくつかのオーバーロードされたコンストラクタがあります。SolidBrush クラスは、特定の色で連続して描画するために使用されます。最後に、イメージは bmp ファイル形式にエクスポートされます。以下のコードスニペットは、イメージの表面に楕円形状を描画する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outpath = dataDir + "Ellipse.bmp"; | |
// Create an instance of BmpOptions and set its various properties | |
BmpOptions saveOptions = new BmpOptions(); | |
saveOptions.BitsPerPixel = 32; | |
// Create an instance of Image | |
using (Image image = new PsdImage(100, 100)) | |
{ | |
// Create and initialize an instance of Graphics class and Clear Graphics surface | |
Graphics graphic = new Graphics(image); | |
graphic.Clear(Color.Yellow); | |
// Draw a dotted ellipse shape by specifying the Pen object having red color and a surrounding Rectangle | |
graphic.DrawEllipse(new Pen(Color.Red), new Rectangle(30, 10, 40, 80)); | |
// Draw a continuous ellipse shape by specifying the Pen object having solid brush with blue color and a surrounding Rectangle | |
graphic.DrawEllipse(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40)); | |
// export image to bmp file format. | |
image.Save(outpath, saveOptions); | |
} |
四角形の描画
この例では、イメージの表面に四角形形状を描画します。操作をデモンストレーションするために、例では新しいイメージを作成し、Graphics クラスによって公開された DrawRectangle メソッドを使用して、イメージの表面に四角形形状を描画します。まず、高さと幅を指定して PsdImage を作成します。その後、Graphics クラスの Clear メソッドを使用して、イメージの背景色を設定します。
Graphics クラスの DrawRectangle メソッドは、矩形構造によって指定されたイメージ表面に四角形形状を描画するために使用されます。このメソッドには、Pen および Rectangle/RectangleF クラスのインスタンス、または座標ペア、幅、高さを引数として受け入れるいくつかのオーバーロードがあります。Rectangle クラスには、矩形の位置とサイズを表す4つの整数のセットを格納します。Rectangle クラスには、指定されたサイズと位置で矩形構造を描画するためのいくつかのオーバーロードされたコンストラクタがあります。最後に、イメージは bmp ファイル形式にエクスポートされます。以下のコードスニペットは、イメージの表面に四角形形状を描画する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outpath = dataDir + "Rectangle.bmp"; | |
// Create an instance of BmpOptions and set its various properties | |
BmpOptions saveOptions = new BmpOptions(); | |
saveOptions.BitsPerPixel = 32; | |
// Create an instance of Image | |
using (Image image = new PsdImage(100, 100)) | |
{ | |
// Create and initialize an instance of Graphics class, Clear Graphics surface, Draw a rectangle shapes and save all changes. | |
Graphics graphic = new Graphics(image); | |
graphic.Clear(Color.Yellow); | |
graphic.DrawRectangle(new Pen(Color.Red), new Rectangle(30, 10, 40, 80)); | |
graphic.DrawRectangle(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40)); | |
// export image to bmp file format. | |
image.Save(outpath, saveOptions); | |
} |
円弧の描画
この図形シリーズのセッションでは、イメージの表面に円弧形状を描画します。Graphics の DrawArc メソッドを使用して、BMP イメージ上で操作をデモンストレーションします。まず、高さと幅を指定して PsdImage を作成します。イメージが作成されたら、Graphics クラスによって公開された Clear メソッドを使用して背景色を設定します。
Graphics クラスの DrawArc メソッドは、イメージ表面に円弧形状を描画するために使用されます。DrawArc は、矩形構造または座標ペアで指定された楕円の一部を表します。このメソッドには、Pen クラスと Rectangle/RectangleF 構造体または座標ペア、幅、高さを引数として受け入れるいくつかのオーバーロードがあります。最後に、イメージは bmp ファイル形式にエクスポートされます。以下のコードスニペットは、イメージの表面に円弧形状を描画する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outpath = dataDir + "Arc.bmp"; | |
// Create an instance of BmpOptions and set its various properties | |
BmpOptions saveOptions = new BmpOptions(); | |
saveOptions.BitsPerPixel = 32; | |
// Create an instance of Image | |
using (Image image = new PsdImage(100, 100)) | |
{ | |
// Create and initialize an instance of Graphics class and clear Graphics surface | |
Graphics graphic = new Graphics(image); | |
graphic.Clear(Color.Yellow); | |
// Draw an arc shape by specifying the Pen object having red black color and coordinates, height, width, start & end angles | |
int width = 100; | |
int height = 200; | |
int startAngle = 45; | |
int sweepAngle = 270; | |
// Draw arc to screen and save all changes. | |
graphic.DrawArc(new Pen(Color.Black), 0, 0, width, height, startAngle, sweepAngle); | |
// export image to bmp file format. | |
image.Save(outpath, saveOptions); | |
} |
ベジエ曲線の描画
この例では、Graphics クラスを使用して、イメージの表面にベジエ曲線形状を描画します。操作をデモンストレーションするために、例では新しいイメージを作成し、Graphics クラスによって公開された DrawBezier メソッドを使用して、イメージの表面にベジエ曲線形状を描画します。まず、高さと幅を指定して PsdImage を作成します。イメージが作成されたら、Graphics クラスによって公開された Clear メソッドを使用して背景色を設定します。
Graphics クラスの DrawBezier メソッドは、4つのポイント構造で定義されたイメージ表面にベジエスプライン形状を描画するために使用されます。このメソッドには、Pen クラスのインスタンスと4つの順序付けられた座標ペア、4つの Point/PointF 構造体、または Point/PointF 構造体の配列を引数として受け入れるいくつかのオーバーロードがあります。Pen クラスは、線、曲線、図形を描画するためのオブジェクトを定義します。Pen クラスには、指定された色、幅、ブラシで線を描画するためのいくつかのオーバーロードされたコンストラクタがあります。最後に、イメージは bmp ファイル形式にエクスポートされます。以下のコードスニペットは、イメージの表面にベジエ形状を描画する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outpath = dataDir + "Bezier.bmp"; | |
// Create an instance of BmpOptions and set its various properties | |
BmpOptions saveOptions = new BmpOptions(); | |
saveOptions.BitsPerPixel = 32; | |
// Create an instance of Image | |
using (Image image = new PsdImage(100, 100)) | |
{ | |
// Create and initialize an instance of Graphics class and clear Graphics surface | |
Graphics graphic = new Graphics(image); | |
graphic.Clear(Color.Yellow); | |
// Initializes the instance of PEN class with black color and width | |
Pen BlackPen = new Pen(Color.Black, 3); | |
float startX = 10; | |
float startY = 25; | |
float controlX1 = 20; | |
float controlY1 = 5; | |
float controlX2 = 55; | |
float controlY2 = 10; | |
float endX = 90; | |
float endY = 25; | |
// Draw a Bezier shape by specifying the Pen object having black color and co-ordinate Points and save all changes. | |
graphic.DrawBezier(BlackPen, startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY); | |
// export image to bmp file format. | |
image.Save(outpath, saveOptions); | |
} |
コア機能を使用したイメージの描画
Aspose.PSD は、画像をゼロから作成するを含む多くの有用な機能を提供するライブラリです。画像のビットマップ情報を操作するなど、コア機能を使用した描画や、Graphics および GraphicsPath のような高度な機能を使用して異なるブラシとペンを使用してイメージ表面に形状を描画します。Aspose.PSD の RasterImage クラスを使用すると、画像領域のピクセル情報を取得し、操作できます。RasterImage クラスには、ピクセルの取得と設定などの画像操作のためのメソッドが含まれています。Creating Files で説明されている方法のいずれかを使用して新しい画像を作成し、RasterImage クラスのインスタンスに割り当てます。RasterImage クラスの LoadPixels メソッドを使用して、画像の一部のピクセル情報を取得します。ピクセルの配列を取得したら、例えば各ピクセルの色を変更するなどの操作を行うことができます。ピクセル情報を操作した後は、RasterImage クラスの SavePixels メソッドを使用して、画像の所定の領域に設定します。以下のコードスニペットは、コア機能を使用してイメージを描画する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string loadpath = dataDir + "sample.psd"; | |
string outpath = dataDir + "CoreDrawingFeatures.bmp"; | |
// Create an instance of Image | |
using (PsdImage image = new PsdImage(loadpath)) | |
{ | |
// load pixels | |
var pixels = image.LoadArgb32Pixels(new Rectangle(0, 0, 100, 10)); | |
for (int i = 0; i < pixels.Length; i++) | |
{ | |
// specify pixel color value (gradient in this case). | |
pixels[i] = i; | |
} | |
// save modified pixels. | |
image.SaveArgb32Pixels(new Rectangle(0, 0, 100, 10), pixels); | |
// export image to bmp file format. | |
image.Save(outpath, new BmpOptions()); | |
} |