没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|行业资讯|编辑:胡涛|2024-09-02 11:16:40.863|阅读 39 次
概述:这篇博文将更进一步,向您展示如何在 Java 中绘制几何形状
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
最近,我们使用Aspose.PSD for Java实现了绘制诸如日食和线条等形状的功能。然而,这篇博文将更进一步,向您展示如何在 Java 中绘制几何形状。幸运的是,您可以使用这个Java 绘图库以编程方式执行此操作,因为它是一个完整的包,可以在 Java 应用程序中处理形状。因此,没有额外的要求,我们可以直接进入安装和实施部分。
Aspose.PSD 是高级PSD文件格式操作API,没有任何Adobe Photoshop依赖项。API允许创建或编辑Photoshop文件,并提供更新图层属性,添加水印,执行图形操作或将一种文件格式转换为另一种文件的功能。Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
现在,您可以转到此 安装 指南查看所有提到的详细信息。但是,您可以 在此处下载 JAR 文件。
Maven 配置:
<repositories> <repository> <id>snapshots</id> <name>repo</name> <url>http://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@evget.com
.NET应用UI框架DevExpress XAF v25.1即将在6月更新,新版本重点增强领域仍然是Blazor,欢迎加入社群及时获取最新信息!
Web测试工具Parasoft SOAtest让测试脚本的创建和复用变得简单高效,自动适应界面变化,实现数据驱动的零压力维护,同时确保跨浏览器测试的无缝执行,极大地降低了维护成本,提高了测试效率。
Parasoft Jtest作为一款强大的Java自动化测试工具,通过灵活的规则定制和统一标准管理,为团队提供了高效的代码规范与合规性检查解决方案。无论是应对行业标准还是企业特殊需求,它都能帮助开发者提升代码质量、降低风险,从而在复杂的开发环境中实现高效协作与稳定交付。
作为全球领先的三维图形开发平台,Tech Soft 3D提供的HOOPS产品套件已成为众多计算机辅助制造(CAM)软件的核心基础架构之一,并为其提供了高性能的数据解析、三维渲染与协作能力。
创建,读取,编辑和转换PSD和PSB文件,而没有任何Adobe Photoshop依赖项。
Aspose.Cells for .NET专业的电子表格控件,无需MS Excel也可满足一切Excel表格功能。
Aspose.Words for .NET无需Microsoft Word也可在任何平台上满足Word文档的一切操作需求。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@evget.com
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
慧都科技 版权所有 Copyright 2003-
2025 渝ICP备12000582号-13 渝公网安备
50010702500608号