ציור תמונות

ציור קווים

דוגמה זו משתמשת במחלקת Graphics כדי לצייר צורות קווים על פני התמונה. כדי להדגים את הפעולה, הדוגמה יוצרת תמונה חדשה ומציירת קווים על פני התמונה באמצעות שיטת DrawLine המוצגת על ידי המחלקה Graphics. עלינו להתחיל ביצירה של PsdImage על ידי ציון הגובה והרוחב שלה.

לאחר שהתמונה נוצרה, נשתמש בשיטת Clear שמוצגת על ידי מחלקת ה-Graphics כדי להגדיר את צבע הרקע שלה. שיטת ה־DrawLine של מחלקת ה-Graphics משמשת לצייר קו על תמונה ומחברת שתי מבני נתונים של נקודה. ל־DrawLine יש מספר שם עומקים אשר מקבלים מופע של מחלקת ה-Pen וזוגי קואורדינטות של נקודות או מבני Point/PointF כארגומנטים. מחלקת Pen מגדירה אובייקט המשמש לצייר קווים, עקופים וצורות. למחלקת Pen יש מספר בנאים עמוסים לציור קווים עם צבע, רוחב ומברש מסוימים. מחלקת SolidBrush משמשת לציור מתמשך בצבע מסוים. לבסוף, התמונה מיוצאת לפורמט קובץ BMP. החלק של הקוד הבא מראה לך איך לצייר צורות קווים על פני התמונה.

String dataDir = Utils.getDataDir(DrawingLines.class) + "DrawingImages/";
// Create an instance of BmpOptions and set its various properties
String outpath = dataDir + "Lines.bmp";
BmpOptions saveOptions = new BmpOptions();
saveOptions.setBitsPerPixel(32);
// Create an instance of Image
try (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.getYellow());
// Draw two dotted diagonal lines by specifying the Pen object having blue color and co-ordinate Points
graphic.drawLine(new Pen(Color.getBlue()), 9, 9, 90, 90);
graphic.drawLine(new Pen(Color.getBlue()), 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.getRed())), new Point(9, 9), new Point(9, 90));
graphic.drawLine(new Pen(new SolidBrush(Color.getAqua())), new Point(9, 90), new Point(90, 90));
graphic.drawLine(new Pen(new SolidBrush(Color.getBlack())), new Point(90, 90), new Point(90, 9));
graphic.drawLine(new Pen(new SolidBrush(Color.getWhite())), new Point(90, 9), new Point(9, 9));
image.save(outpath, saveOptions);
}

ציור אליפסה

דוגמה זו היא המאמר השני בסדרת ציור צורות ועיגולים. נשתמש במחלקת Graphics כדי לצייר את צורת האליפסה על פני התמונה. כדי להדגים את הפעולה, הדוגמה תיצור תמונה חדשה ותצייר את צורת האליפסה על פני התמונה באמצעות שיטת DrawEllipse המוצגת על ידי מחלקת Graphics. נתחיל ראשית ביצירה של PsdImage ובציון הגובה והרוחב שלה.

לאחר יצירת התמונה, ניצור ונאתחל אובייקט מחלקת Graphics ונגדיר את צבע הרקע של התמונה על פי שימוש בשיטת Clear של מחלקת ה-Graphics. שיטת ה־DrawEllipse של מחלקת ה-Graphics משמשת לצייר את צורת האליפסה על פני התמונה בהתאם למבנה הריבועי הגומל. ל־DrawEllipse יש מספר שאריות המקבלים את המופעים של ה-Pen ומבנה ה־Rectangle/RectangleF ו- Pair של קואורדינות, גובה ורוחב כארגומנטים. מחלקת Pen מגדירה אובייקט המשמש לציור קווים, עקופים וצורות. למחלקת Pen יש מספר בנאים עמוסים לציור קווים עם צבע, רוחב ומברש מסוימים. מחלקת ה־Rectangle מאחסנת סט של ארבעה מספרים שמייצגים את המיקום והגודל של ריבוע. למחלקת Rectangle יש מספר בנאים עמוסים לציור מבנה הריבוע עם גודל ומיקום ספציפיים. מחלקת SolidBrush משמשת לציור מתמשך בצבע מסוים. לבסוף, התמונה מיוצאת לפורמט קובץ BMP. החלק של הקוד הבא מראה לך איך לצייר צורת אליפסה על פני התמונה.

String dataDir = Utils.getDataDir(DrawingEllipse.class) + "DrawingImages/";
// Create an instance of BmpOptions and set its various properties
String outpath = dataDir + "Ellipse.bmp";
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.setBitsPerPixel(32);
// Create an instance of Image
try (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.getYellow());
// Draw a dotted ellipse shape by specifying the Pen object having red color and a surrounding Rectangle
graphic.drawEllipse(new Pen(Color.getRed()), 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.getBlue())), new Rectangle(10, 30, 80, 40));
// export image to bmp file format.
image.save(outpath, saveOptions);
}

ציור מלבן

בדוגמה זו נצייר את צורת המלבן על פני התמונה. כדי להדגים את הפעולה, הדוגמה תיצור תמונה חדשה ותצייר צורת מלבן על פני התמונה באמצעות שיטת DrawRectangle המוצגת על ידי מחלקת Graphics. נתחיל ראשית ביצירה של PsdImage ובציון הגובה והרוחב שלה. לאחר מכן, נגדיר את צבע הרקע של התמונה על ידי השימוש בשיטת Clear של מחלקת ה-Graphics.

שיטת ה־DrawRectangle של מחלקת ה-Graphics משמשת לצייר את צורת המלבן על פני התמונה על פי מבנה הריבועי. ל־DrawRectangle יש מספר שאריות המקבלים את המופעים של ה-Pen ומבנה ה־Rectangle/RectangleF וזוג של קואורדינטות, רוחב וגובה כארגומנטים. מחלקת ה־Rectangle מאחסנת סט של ארבעה מספרים שמייצגים את המיקום והגודל של ריבוע. ל־Rectangle יש מספר בנאים עמוסים לציור מבנה הריבוע עם גודל ומיקום ספציפיים. לבסוף, התמונה מיוצאת לפורמט קובץ BMP. החלק של הקוד הבא מראה לך איך לצייר מלבן על פני התמונה.

// Create an instance of BmpOptions and set its various properties
String outpath = dataDir + "Rectangle.bmp";
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.setBitsPerPixel(32);
// Create an instance of Image
try (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.getYellow());
graphic.drawRectangle(new Pen(Color.getRed()), new Rectangle(30, 10, 40, 80));
graphic.drawRectangle(new Pen(new SolidBrush(Color.getBlue())), new Rectangle(10, 30, 80, 40));
// export image to bmp file format.
image.save(outpath, saveOptions);
}

ציור קשת

במהלך זה בסדרת הציור צורות, נצייר את צורת הקשת על פני התמונה. נשתמש בשיטת DrawArc של Graphics כדי להדגים את הפעולה על תמונת BMP. נתחיל ראשית ביצירה של PsdImage ובציון הגובה והרוחב שלה. לאחר שהתמונה נוצרה, נשתמש בשיטת Clear שמוצגת על ידי מחלקת ה-Graphics כדי להגדיר את צבע הרקע שלה.

שיטת ה־DrawArc של מחלקת ה-Graphics משמשת לצייר את צורת הקשת על פני התמונה. DrawArc מייצגת חלק מאליפסה בהגדרה מבנה הריבועי או זוג הקואורדינטות. ל־DrawArc יש מספר שם עומקים שמקבלים את המופעים של מחלקת ה-Pen ומבנה ה־Rectangle/RectangleF וזוג הקואורדינטות, רוחב וגובה כארגומנטים. לבסוף, התמונה מיוצאת לפורמט קובץ BMP. החלק של הקוד הבא מראה לך איך לצייר צורת קשת על פני התמונה.

String dataDir = Utils.getDataDir(DrawingArc.class) + "DrawingImages/";
// Create an instance of BmpOptions and set its various properties
String outpath = dataDir + "Arc.bmp";
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.setBitsPerPixel(32);
// Create an instance of Image
try (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.getYellow());
// 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.getBlack()), 0, 0, width, height, startAngle, sweepAngle);
// export image to bmp file format.
image.save(outpath, saveOptions);
}

ציור בזיר

דוגמה זו משתמשת במחלקת Graphics כדי לצייר את צורת הבזיר על פני התמונה. כדי להדגים את הפעולה, הדוגמה תיצור תמונה חדשה ותצייר את צורת הבזיר על פני התמונה באמצעות שיטת DrawBezier המוצגת על ידי מחלקת Graphics. נתחיל ראשית ביצירה של PsdImage ובציון הגובה והרוחב שלה. לאחר יצירת התמונה, נשתמש בשיטת Clear שמוצגת על ידי מחלקת ה-Graphics כדי להגדיר את צבע הרקע שלה.

שיטת ה־DrawBezier של מחלקת ה-Graphics משמשת לצייר צורת דרך בצורת בזיר על פני מישור התמונה המוגדר על ידי ארבע מבני נתונים. לשיטה יש מספר שם עומקים אשר מקבלים מופעים של מחלקת ה-Pen וארבע זוגות סדורים של קואורדינטות, או ארבע מבני Point/PointF או מערך של Point/PointF כמבני נתונים. מחלקת Pen מגדירה אובייקט המשמש לציור קווים, עקופים וצורות. למחלקת Pen יש מספר בנאים עמוסים לציור קווים עם צבע, רוחב ומברש מסוימים. לבסוף, התמונה מיוצאת לפורמט קובץ BMP. החלק של הקוד הבא מראה לך איך לצייר את צורת הבזיר על פני התמונה.

String dataDir = Utils.getDataDir(DrawingBezier.class) + "DrawingImages/";
// Create an instance of BmpOptions and set its various properties
String outpath = dataDir + "Bezier.bmp";
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.setBitsPerPixel(32);
// Create an instance of Image
try (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.getYellow());
// Initializes the instance of PEN class with black color and width
Pen BlackPen = new Pen(Color.getBlack(), 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 היא ספרייה המציעה מאפיינים ערכי