通过 Java 转到 DNG
构建您自己的 Java 应用程序以使用服务器端 API 合并 DNG 文件。
如何使用 Java 合并 DNG 文件
如果您想让您的创造力尽情发挥,那么现在就是使用图像拼贴的时候了。即使源文件格式不同,此功能也允许您合并照片和图像。吸引人们注意您的作品集的一个好方法是使用带有重复图像或图案的照片壁纸。在这种情况下,可以在水平和垂直方向上组合图像。如果您需要演示处理文件的结果,您可以轻松合并两个图像:应用照片效果之前和之后。为了合并 DNG 文件,我们将使用 Aspose.Imaging for Java API 是一个功能丰富、功能强大 易于使用的 Java 平台图像处理和转换 API。您可以直接从 Maven
并通过将以下配置添加到 pom.xml 将其安装在基于 Maven 的项目中。
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging</artifactId>
<version>version of aspose-imaging API</version>
<classifier>jdk16</classifier>
</dependency>
通过 Java 合并 DNG 的步骤
你需要 aspose-imaging-version-jdk16.jar 在您自己的环境中尝试以下工作流程。
- 使用 Image.load 方法加载 DNG 文件
- 将图像组合成新的图像
- 将裁剪后的图像以 Aspose.Imaging 支持的格式保存到光盘
系统要求
所有主要操作系统都支持 Java 的 Aspose.Imaging。只需确保您具有以下先决条件。
- 已安装 JDK 1.6 或更高版本。
合并 DNG 图像 - Java
import com.aspose.imaging.Color; | |
import com.aspose.imaging.Graphics; | |
import com.aspose.imaging.Image; | |
import com.aspose.imaging.RectangleF; | |
import com.aspose.imaging.fileformats.png.PngColorType; | |
import com.aspose.imaging.imageoptions.PngOptions; | |
import com.aspose.imaging.sources.StreamSource; | |
import java.io.File; | |
import java.io.FilenameFilter; | |
import java.util.ArrayList; | |
import java.util.List; | |
enum MergeStyle | |
{ | |
Horizontal, | |
Vertical | |
} | |
// Test directory should have source images to merge | |
String TestDirectory = "D:\\Many2One\\"; | |
MergeStyle mStyle = MergeStyle.Horizontal; // or MergeStyle.Vertical | |
List<Image> images = new ArrayList<Image>(); | |
try | |
{ | |
int totalWidth = 0; | |
int totalHeight = 0; | |
int maxWidth = 0; | |
int maxHeight = 0; | |
final String fileMask = ".png"; | |
File[] files = new File(TestDirectory).listFiles(new FilenameFilter() | |
{ | |
@Override | |
public boolean accept(File dir, String name) | |
{ | |
return name.endsWith(fileMask); | |
} | |
}); | |
if (files == null) | |
{ | |
return; | |
} | |
for (File fileName : files) | |
{ | |
try (Image image = Image.load(fileName.getAbsolutePath())) | |
{ | |
totalWidth += image.getWidth(); | |
if (image.getWidth() > maxWidth) | |
{ | |
maxWidth = image.getWidth(); | |
} | |
totalHeight += image.getHeight(); | |
if (image.getHeight() > maxHeight) | |
{ | |
maxHeight = image.getHeight(); | |
} | |
images.add(image); | |
} | |
} | |
if (images.isEmpty()) | |
{ | |
return; | |
} | |
String mergeStyle; | |
int targetWidth, targetHeight; | |
if (mStyle == MergeStyle.Horizontal) | |
{ | |
targetWidth = totalWidth; | |
targetHeight = maxHeight; | |
} | |
else if (mStyle == MergeStyle.Vertical) | |
{ | |
targetWidth = maxWidth; | |
targetHeight = totalHeight; | |
} | |
else | |
{ | |
return; // other merge styles are not supported | |
} | |
String outputPath = TestDirectory + "output\\"; | |
File dir = new File(outputPath); | |
assert dir.exists() || dir.mkdirs(); | |
outputPath = outputPath + "merged_" + mStyle.name() + ".png"); | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.setColorType(PngColorType.TruecolorWithAlpha); | |
pngOptions.setSource(new StreamSource()); | |
try (Image image = Image.create(pngOptions, targetWidth, targetHeight)) | |
{ | |
image.setBackgroundColor(Color.getWhite()); | |
final Graphics graphics = new Graphics(image); | |
float x = 0, y = 0; | |
for (Image it : images) | |
{ | |
graphics.drawImage(it, new RectangleF(x, y, it.getWidth(), it.getHeight())); | |
if (mStyle == MergeStyle.Horizontal) | |
{ | |
x += it.getWidth(); | |
} | |
if (mStyle == MergeStyle.Vertical) | |
{ | |
y += it.getHeight(); | |
} | |
} | |
image.save(outputPath); | |
} | |
} | |
finally | |
{ | |
for (Image image : images) | |
{ | |
image.close(); | |
} | |
images.clear(); | |
} |
关于 Java API 的 Aspose.Imaging
Aspose.Imaging API 是一种图像处理解决方案,用于在应用程序中创建、修改、绘制或转换图像(照片)。它提供:跨平台的图像处理,包括但不限于各种图像格式之间的转换(包括统一的多页或多帧图像处理)、绘图等修改、使用图形基元、转换(调整大小、裁剪、翻转和旋转) 、二值化、灰度、调整)、高级图像处理功能(过滤、抖动、遮罩、去偏斜)和内存优化策略。它是一个独立的库,不依赖任何软件进行图像操作。可以在项目中使用原生 API 轻松添加高性能图像转换功能。这些是 100% 私有的本地 API,图像在您的服务器上处理。通过在线应用合并 DNG
通过访问我们的 Live Demos 网站 合并 DNG 文档。 现场演示有以下好处
DNG 什么是 DNG 文件格式
DNG 是一种用于存储原始文件的数码相机图像格式。它是由 Adobe 于 2004 年 9 月开发的。它基本上是为数码摄影而开发的。 DNG 是 TIFF/EP 标准格式的扩展,大量使用元数据。为了轻松灵活地处理来自数码相机的原始数据和艺术控制,摄影师选择相机原始文件。 JPEG 和 TIFF 格式存储由相机处理的图像,因此在这些格式中没有太大的更改空间。
阅读更多其他支持的合并格式
使用 Java,可以轻松合并不同的格式,包括。