Learn how to Draw and Format Text in Java Using Aspose.Drawing for Java
Created
June 16, 2025 08:08
-
-
Save aspose-com-gists/65470c32709bff3ce26f08bc5b0614b4 to your computer and use it in GitHub Desktop.
Draw and Format Text in Java Using Aspose.Drawing for Java
This file contains hidden or 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
import com.aspose.drawing.*; | |
public class DrawText { | |
public static void main(String[] args) throws Exception { | |
Bitmap bitmap = new Bitmap(500, 200); | |
Graphics graphics = Graphics.fromImage(bitmap); | |
graphics.clear(Color.getLightGray()); | |
Font font = new Font("Arial", 24); | |
Brush brush = new SolidBrush(Color.getBlack()); | |
graphics.drawString("Hello, Aspose.Drawing for Java!", font, brush, 20, 80); | |
bitmap.save("draw-text-java.png"); | |
} | |
} |
This file contains hidden or 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
import com.aspose.drawing.*; | |
public class FormatText { | |
public static void main(String[] args) throws Exception { | |
Bitmap bitmap = new Bitmap(500, 200); | |
Graphics graphics = Graphics.fromImage(bitmap); | |
graphics.clear(Color.getWhite()); | |
Font font = new Font("Times New Roman", 28, FontStyle.BOLD | FontStyle.ITALIC); | |
Brush brush = new SolidBrush(Color.getBlue()); | |
graphics.drawString("Formatted Text in Java", font, brush, 20, 60); | |
bitmap.save("formatted-text-java.png"); | |
} | |
} |
This file contains hidden or 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
import com.aspose.drawing.*; | |
public class TextHinting { | |
public static void main(String[] args) throws Exception { | |
Bitmap bitmap = new Bitmap(500, 200); | |
Graphics graphics = Graphics.fromImage(bitmap); | |
graphics.clear(Color.getWhite()); | |
graphics.setTextRenderingHint(TextRenderingHint.AntiAliasGridFit); | |
Font font = new Font("Calibri", 24); | |
Brush brush = new SolidBrush(Color.getDarkGreen()); | |
graphics.drawString("Hinted Text with AntiAlias", font, brush, 20, 80); | |
bitmap.save("text-hinting-java.png"); | |
System.out.println("Hinted text image saved."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment