图像通常是强大的沟通者,以视觉语言传达信息。向图像添加注释可以显着提高其价值和可用性。在本教程中,我们将探索如何使用 Java 向 JPG 添加突出显示注释的过程,为您提供全面的指南,以便将此功能无缝集成到您的项目中。以下步骤和代码示例展示了如何在 Java 中为 JPG 制作**突出显示注释。
使用 Java 添加突出显示注释到 JPG 的步骤
- 配置您的集成开发环境 (IDE) 以利用 GroupDocs.Annotation for Java,从而将突出显示注释集成到 JPG 图像中
- 通过提供 JPG 文件路径作为其构造函数的参数来创建 Annotator 类的实例
- 实例化 HighlightAnnotation 类并定义必要的属性,例如背景颜色、不透明度和位置
- 调用 Annotator.add 方法,将HighlightAnnotation 对象作为参数传递
- 调用 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.Point; | |
import com.groupdocs.annotation.models.annotationmodels.HighlightAnnotation; | |
import java.util.ArrayList; | |
import java.util.Calendar; | |
import java.util.List; | |
public class AddHighlightAnnotationtoJPGUsingJava { | |
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"); | |
Point point1 = new Point(80, 730); | |
Point point2 = new Point(240, 730); | |
Point point3 = new Point(80, 650); | |
Point point4 = new Point(240, 650); | |
List<Point> points = new ArrayList<Point>(); | |
points.add(point1); | |
points.add(point2); | |
points.add(point3); | |
points.add(point4); | |
// Create an instance of HighlightAnnotation class and set options | |
HighlightAnnotation highlight = new HighlightAnnotation(); | |
highlight.setBackgroundColor(65535); | |
highlight.setCreatedOn(Calendar.getInstance().getTime()); | |
highlight.setFontColor(0); | |
highlight.setMessage("This is highlight annotation"); | |
highlight.setOpacity(0.5); | |
highlight.setPageNumber(0); | |
highlight.setPoints(points); | |
// Add highlight annotation | |
annotator.add(highlight); | |
// Save JPG to disk | |
annotator.save("output.jpg"); | |
} | |
} |
总之,使用 Java 向 JPG 图像添加突出显示注释的过程提供了一种增强和自定义视觉内容的动态方法。无论您是在创建教育材料、文档,还是只是强调图像的某些方面,以编程方式注释 JPG 文件的能力都开启了一个充满可能性的世界。安装注释库并根据需要调整文件路径后,将代码添加到应用程序是一件容易的事。做得好!现在您知道如何使用 Java 在 JPG 中创建突出显示注释。
我们之前发表过一篇文章,指导您完成在 JPG 图像中包含椭圆注释的步骤。如需了解更多详情,请参阅我们的指南,了解如何使用Java向JPG添加椭圆注释。