获得将椭圆注释合并到 JPG 图像中的能力是一项宝贵的技能,可以让用户更有效地传达信息。本文提供了有关如何使用 Java 向 JPG 添加椭圆注释的深入教程。无论您是从事设计项目、处理技术图表还是寻求强调图像中的特定区域,椭圆注释都提供了多功能解决方案。以下部分将深入研究 在 Java 编程语言中向 JPG 插入椭圆注释的更多细节。
使用 Java 添加椭圆注释到 JPG 的步骤
- 设置您的 IDE 以利用 GroupDocs.Annotation for Java,允许将椭圆注释集成到 JPG 图像中
- 通过提供 JPG 文件路径作为其构造函数的参数来创建 Annotator 类的实例
- 实例化 EllipseAnnotation 类并定义必要的属性,例如位置和页码
- 调用 Annotator.add 方法,将 EllipseAnnotation 对象作为参数传递
- 调用 Annotator.save 方法将生成的 JPG 输出保存到磁盘
通过按照提供的说明并在任何计算机上安装注释库,您可以使用 Java 轻松*在 JPG 中创建椭圆注释。当您深入研究合并注释的潜力时,请记住,这种方法不仅简化了流程,而且保证了跨不同平台的兼容性。这使其成为旨在增强图像处理能力的开发人员的宝贵工具。这些步骤适用于 Windows、macOS 和 Linux 等常用操作系统,所有操作系统都配备了 Java。无需安装额外的软件即可将椭圆注释集成到 JPG 文件中。
使用 Java 将椭圆注释添加到 JPG 的代码
import com.groupdocs.annotation.Annotator; | |
import com.groupdocs.annotation.licenses.License; | |
import com.groupdocs.annotation.models.PenStyle; | |
import com.groupdocs.annotation.models.Rectangle; | |
import com.groupdocs.annotation.models.annotationmodels.EllipseAnnotation; | |
import java.util.Calendar; | |
public class AddEllipseAnnotationtoJPGUsingJava { | |
public static void main(String[] args) { | |
// Set License to avoid the limitations of Annotation library | |
License license = new License(); | |
license.setLicense("GroupDocs.Annotation.lic"); | |
// Create an instance of Annotator class | |
Annotator annotator = new Annotator("input.jpg"); | |
// Create an instance of EllipseAnnotation class and set options | |
EllipseAnnotation ellipse = new EllipseAnnotation(); | |
ellipse.setBackgroundColor(65535); | |
ellipse.setBox(new Rectangle(100, 100, 100, 100)); | |
ellipse.setCreatedOn(Calendar.getInstance().getTime()); | |
ellipse.setMessage("This is ellipse annotation"); | |
ellipse.setOpacity(0.7); | |
ellipse.setPageNumber(0); | |
ellipse.setPenColor(65535); | |
ellipse.setPenStyle(PenStyle.DOT); | |
ellipse.setPenWidth((byte) 3); | |
// Add ellipse annotation | |
annotator.add(ellipse); | |
// Save JPG to disk | |
annotator.save("output.jpg"); | |
} | |
} |
总之,在注释库的帮助下,使用Java向JPG图像添加椭圆注释的过程已经被简化并且变得高效。一旦注释库成功安装并根据需要调整输入和输出文件路径,将代码集成到您的应用程序中就变成了一项简单的任务。恭喜!您现在已经掌握了在 JPG Java 中成功包含*椭圆注释的知识。
我们之前发表过一篇文章,解释了将距离注释合并到 JPG 图像中的过程。如需更多信息,请参阅我们的指南,了解如何使用Java为JPG添加距离注释。