提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|行业资讯|编辑:胡涛|2024-09-02 11:16:40.863|阅读 124 次
概述:这篇博文将更进一步,向您展示如何在 Java 中绘制几何形状
#慧都22周年庆大促·界面/图表报表/文档/IDE/IOT/测试等千款热门软控件火热促销中>>
相关链接:
最近,我们使用Aspose.PSD for Java实现了绘制诸如日食和线条等形状的功能。然而,这篇博文将更进一步,向您展示如何在 Java 中绘制几何形状。幸运的是,您可以使用这个Java 绘图库以编程方式执行此操作,因为它是一个完整的包,可以在 Java 应用程序中处理形状。因此,没有额外的要求,我们可以直接进入安装和实施部分。
Aspose.PSD 是高级PSD文件格式操作API,没有任何Adobe Photoshop依赖项。API允许创建或编辑Photoshop文件,并提供更新图层属性,添加水印,执行图形操作或将一种文件格式转换为另一种文件的功能。支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
现在,您可以转到此 安装 指南查看所有提到的详细信息。但是,您可以 在此处下载 JAR 文件。
Maven 配置:
<repositories> <repository> <id>snapshots</id> <name>repo</name> <url>//repository.aspose.com/repo/</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-psd</artifactId> <version>24.4</version> <classifier>jdk16</classifier> </dependency> </dependencies>
安装完成后,您可以按照以下步骤操作:
以下代码示例演示了如何使用 Aspose.PSD for Java 绘制矩形:
public class Main {
// Drawing rectangle in java
public static void main(String[] args) throws Exception {
String outpath = "/files/rectangle.bmp";
// Create an instance of BmpOptions class.
BmpOptions saveOptions = new BmpOptions();
// Invoke the setBitsPerPixel method to set the bits per pixel.
saveOptions.setBitsPerPixel(32);
// Create an instance of Image class and initialize it with the object of PsdImage class.
try (PsdImage image = new PsdImage(100, 100)) {
// Instantiate an instance of the Graphics class with the object of the Image class.
Graphics graphic = new Graphics(image);
// Set the background color of the image by calling the getYellow method.
graphic.clear(Color.getYellow());
// The drawRectangle method will draw a rectangle.
graphic.drawRectangle(new Pen(Color.getRed()), new RectangleF(30, 10, 40, 80));
graphic.drawRectangle(new Pen(new SolidBrush(Color.getBlue())), new RectangleF(10, 30, 80, 40));
// Export image to bmp file format by calling the save method.
image.save(outpath, saveOptions);
}
}
}
输出:
类似地,您可以按照下面提到的代码片段在 Java 中绘制圆弧:
public class Main {
// Draw an Arc
public static void main(String[] args) throws Exception {
String outpath = "/file/arc.bmp";
// Create an instance of BmpOptions class and invoke the setBitsPerPixel method to set the bits per pixel. .
BmpOptions saveOption = new BmpOptions();
saveOption.setBitsPerPixel(32);
// Create an instance of Image class and initialize it with the object of PsdImage class.
try (PsdImage 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);
// Save the image to bmp file format.
image.save(outpath, saveOption);
}
}
}
输出:
总而言之,除了在 Java 中绘制几何形状外,Aspose.PSD for Java还提供了许多功能。因此,我们已经介绍了如何使用此Java 绘图库创建矩形和圆弧。果您还有其他疑问,欢迎查阅本系列其他教程,或者私信我们获取帮助~
欢迎下载|体验更多Aspose文档管理产品
获取更多信息请咨询 或 加入Aspose技术交流群(761297826)
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@hmdbvip.cn




HOOPS Visualize Web使用模型树作为一种三维模型格式转换的方式,以便在Web和移动应用程序中进行展示和交互。模型树允许用户对模型进行层级操作和选择,以满足特定的需求。
自2007年以来,GeoLogismiki一直使用TeeChart Pro VCL/FMX图表库将复杂的数据转化为清晰、交互式的图形。
近日,国产化文档开发组件Spire.Office 同步更新 .NET和 Java 版本至10.10.0 !本次更新带来了多项全新功能与性能优化,为开发者提供更强大、更高效的文档、表格、PDF、演示文稿处理能力。
通过将 ActiveReportsJS Web报表设计器无缝集成到Vue项目,能实现最终用户自助设计/编辑报表,彻底告别依赖开发的繁琐流程。
相关产品
创建,读取,编辑和转换PSD和PSB文件,而没有任何Adobe Photoshop依赖项。
Aspose.Cells for .NET专业的电子表格控件,无需MS Excel也可满足一切Excel表格功能。
Aspose.Words for .NET无需Microsoft Word也可在任何平台上满足Word文档的一切操作需求。
最新文章 MORE
永利最大(官方)网站相关的文章 MORE
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@hmdbvip.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
永利最大(官方)网站