通过 Java 过滤 CMX
构建您自己的 Java 应用程序以使用服务器端 API 过滤 CMX 文件。
如何使用 Java 过滤 CMX 文件
即使是最完美的图像也可以进一步增强或转化为完全不同且独特的艺术作品。应用滤镜来实现各种图像效果。例如,您可以锐化图像,或者相反,添加模糊、平滑图像或消除颜色噪声。当您希望赋予图像独特性时,滤镜也非常有用。为此,请应用所需的效果或组合不同的效果。这种方法允许您细化颜色渐变、消除噪点,同时增强照片中对象边缘的清晰度。为了过滤 CMX 文件,我们将使用 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 过滤 CMX 的步骤
你需要 aspose-imaging-version-jdk16.jar 在您自己的环境中尝试以下工作流程。
- 使用 Image.Load 方法加载 CMX 文件 +过滤图像;
- 以 Aspose.Imaging 支持的格式将压缩图像保存到光盘
系统要求
所有主要操作系统都支持 Java 的 Aspose.Imaging。只需确保您具有以下先决条件。
- 已安装 JDK 1.6 或更高版本。
过滤 CMX 图像 - Java
import com.aspose.imaging.IMultipageImage; | |
import com.aspose.imaging.Image; | |
import com.aspose.imaging.RasterImage; | |
import com.aspose.imaging.imageoptions.PngOptions; | |
import java.io.File; | |
import java.util.Arrays; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.function.Consumer; | |
medianfilter(); | |
public static void smallRectangularfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/SmallRectangularFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new SmallRectangularFilterOptions()); | |
}, "smallrectangular"); | |
} | |
public static void bigRectangularfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/BigRectangularFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new BigRectangularFilterOptions()); | |
}, "bigrectangular"); | |
} | |
public static void sharpenfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/SharpenFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new SharpenFilterOptions()); | |
}, "sharpen"); | |
} | |
public static void motionWienerfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/MotionWienerFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new MotionWienerFilterOptions(20, 2, 0)); | |
}, "motionwiener"); | |
} | |
public static void bilateralSmoothingfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/BilateralSmoothingFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new BilateralSmoothingFilterOptions()); | |
}, "bilateralsmoothing"); | |
} | |
public static void gaussBlurfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/GaussianBlurFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new GaussianBlurFilterOptions(5, 4)); | |
}, "gaussblur"); | |
} | |
public static void gaussWienerfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/GaussWienerFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new GaussWienerFilterOptions(5, 5)); | |
}, "gausswiener"); | |
} | |
public static void medianfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/MedianFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new MedianFilterOptions(20)); | |
}, "median"); | |
} | |
static String templatesFolder = "D:\\"; | |
public static void filterImages(Consumer<RasterImage> doFilter, String filterName) | |
{ | |
List<String> rasterFormats = Arrays.asList("jpg", "png", "bmp", "apng", "dicom", | |
"jp2", "j2k", "tga", "webp", "tif", "gif", "ico"); | |
List<String> vectorFormats = Arrays.asList("svg", "otg", "odg", "eps", "wmf", "emf", "wmz", "emz", "cmx", "cdr"); | |
List<String> allFormats = new LinkedList<>(rasterFormats); | |
allFormats.addAll(vectorFormats); | |
allFormats.forEach( | |
formatExt -> | |
{ | |
String inputFile = templatesFolder + "template." + formatExt; | |
boolean isVectorFormat = vectorFormats.contains(formatExt); | |
//Need to rasterize vector formats before background remove | |
if (isVectorFormat) | |
{ | |
inputFile = rasterizeVectorImage(formatExt, inputFile); | |
} | |
String outputFile = templatesFolder + String.format("%s_%s.png", filterName, formatExt); | |
System.out.println("Processing " + formatExt); | |
try (RasterImage image = (RasterImage) Image.load(inputFile)) | |
{ | |
doFilter.accept(image); | |
//If image is multipage save each page to png to demonstrate results | |
if (image instanceof IMultipageImage && ((IMultipageImage) image).getPageCount() > 1) | |
{ | |
IMultipageImage multiPage = (IMultipageImage) image; | |
final int pageCount = multiPage.getPageCount(); | |
final Image[] pages = multiPage.getPages(); | |
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) | |
{ | |
String fileName = String.format("%s_page%d_%s.png", filterName, pageIndex, formatExt); | |
pages[pageIndex].save(fileName, new PngOptions()); | |
} | |
} | |
else | |
{ | |
image.save(outputFile, new PngOptions()); | |
} | |
} | |
//Remove rasterized vector image | |
if (isVectorFormat) | |
{ | |
new File(inputFile).delete(); | |
} | |
} | |
); | |
} | |
private static String rasterizeVectorImage(String formatExt, String inputFile) | |
{ | |
String outputFile = templatesFolder + "rasterized."+ formatExt + ".png"; | |
try (Image image = Image.load(inputFile)) | |
{ | |
image.save(outputFile, new PngOptions()); | |
} | |
return outputFile; | |
} |
关于 Java API 的 Aspose.Imaging
Aspose.Imaging API 是一种图像处理解决方案,用于在应用程序中创建、修改、绘制或转换图像(照片)。它提供:跨平台的图像处理,包括但不限于各种图像格式之间的转换(包括统一的多页或多帧图像处理)、绘图等修改、使用图形基元、转换(调整大小、裁剪、翻转和旋转) 、二值化、灰度、调整)、高级图像处理功能(过滤、抖动、遮罩、去偏斜)和内存优化策略。它是一个独立的库,不依赖任何软件进行图像操作。可以在项目中使用原生 API 轻松添加高性能图像转换功能。这些是 100% 私有的本地 API,图像在您的服务器上处理。通过在线应用过滤 CMX
通过访问我们的 Live Demos 网站 过滤 CMX 文档。 现场演示有以下好处
CMX 什么是 CMX 文件格式
带有 CMX 扩展名的文件是 Corel Exchange 图像文件格式,CorelSuite 应用程序用作演示文稿。它包含作为矢量图形的图像数据以及描述图像的元数据。 CMX 文件可由 CorelDraw、Corel Presentations、Paint Shop Pro 和某些版本的 Adobe Illustrator 打开。
阅读更多其他支持的过滤器格式
使用 Java,可以轻松过滤不同的格式,包括。