Aspose.PDF For JAVA EmfMetafileImage类的问题

你好!

我使用的产品是:Aspose.PDF For JAVA,我遇到一个问题。

我之前用的aspose-pdf 20.12里com.aspose.pdf.internal.imaging.fileformats.metafile.EmfMetafileImage类,aspose-pdf升级为21.11后就没有这个类了,请问com.aspose.pdf.internal.imaging.fileformats.metafile.EmfMetafileImage类用什么代替?
aspose-pdf升级为21.11提示不存在aspose.pdf.internal.imaging.fileformats.metafile.EmfMetafileImage类
b05835f3972768fa38b2e245d1dacf3.png (34.8 KB)

@SupportDhorde

您能否与示例源文件一起分享示例控制台应用程序,以便我们可以更好地了解问题并尝试在我们的环境中复制它?

示例代码,如下:

public static boolean convert(String fromPath, String toPath) {	
	WmfMetafileImage wfmMetafile = null;
	try {
		wfmMetafile = new WmfMetafileImage(fromPath);
		// metafile.setDpi(300);
		wfmMetafile.save(toPath, new PngOptions());
		wfmMetafile.close();
		wfmMetafile.dispose();
		wfmMetafile = null;
		return true;
	} catch (Exception e) {
		if (wfmMetafile != null) {
			wfmMetafile.close();
			wfmMetafile.dispose();
			wfmMetafile = null;
		}
	}
	
	EmfMetafileImage emfMetafile = null;
	try {
		emfMetafile = new EmfMetafileImage(fromPath);
		if (StringUtils.endsWithIgnoreCase(toPath, ".jpg")) {
			emfMetafile.save(toPath, new JpegOptions());
		} else {
			emfMetafile.save(toPath, new PngOptions());
		}
		emfMetafile.close();
		emfMetafile.dispose();
		emfMetafile = null;
		return true;
	} catch (Exception e) {
		if (emfMetafile != null) {
			emfMetafile.close();
			emfMetafile.dispose();
			emfMetafile = null;
		}
	}
	return false;
}

aspose-pdf 20.12版本有WmfMetafileImage、EmfMetafileImage类,最新的aspose-pdf 21.11版本已无此版本

另外aspose-pdf 20.12版本中 WmfMetafileImage、EmfMetafileImage类的setBufferSizeHint没起作用,代码如下:
image.png (33.9 KB)

@aaaConvert

看起来您在一个项目中使用了多个 Aspose API。 EmfMetafileImage 没有在 Aspose.PDF 中作为公共成员提供。但是,它存在于 Aspose.Imaging for Java API 中。 Aspose.Imaging 在 Aspose.PDF 中用作内部部分,因此该类被混淆。现在您可以使用EmfImage

你说的EmfImage是 com.aspose.imaging.fileformats.emf.EmfImage 吗?

Aspose.Imaging for Java 和 Aspose.PDF For JAVA 都用过,Aspose.Imaging for Java转换wmf比Aspose.PDF For JAVA 速度慢,效果有偏差, 转换emf抛异常,所以emf、wmf转图片使用的Aspose.PDF For JAVA:

emf示例文件.zip (9.1 KB)
将emf示例文件.zip压缩包里的1.EMF转为png, 使用Aspose.Imaging for Java 抛异常,使用 Aspose.PDF For JAVA转换正常,此问题已单独提了,链接如下:

Aspose.Imaging for Java 使用的21.12-jdk16版本,1.EMF转png抛异常, 代码如下:

import com.aspose.imaging.Image;
import com.aspose.imaging.fileformats.emf.EmfImage;
import com.aspose.imaging.imageoptions.PngOptions;

public class EmgToImage {

public static void toPng2(String fromPath, String toPath) {
	EmfImage metafile = (EmfImage) Image.load(fromPath);
	try {
		metafile.save(toPath, new PngOptions());
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		metafile.dispose();
	}
}

}

Aspose.PDF For JAVA 使用的20.12版本,1.EMF转png是正常的 ,代码如下:

import org.apache.commons.lang3.StringUtils;

import com.aspose.pdf.internal.imaging.fileformats.metafile.EmfMetafileImage;
import com.aspose.pdf.internal.imaging.fileformats.metafile.WmfMetafileImage;
import com.aspose.pdf.internal.imaging.imageoptions.*;

public class EmfToImage {

@SuppressWarnings("resource")
public static boolean convert(String fromPath, String toPath) {		
	EmfMetafileImage emfMetafile = null;
	try {
		emfMetafile = new EmfMetafileImage(fromPath);
		if (StringUtils.endsWithIgnoreCase(toPath, ".jpg")) {
			emfMetafile.save(toPath, new JpegOptions());
		} else {
			emfMetafile.save(toPath, new PngOptions());
		}
		emfMetafile.close();
		emfMetafile.dispose();
		emfMetafile = null;
		return true;
	} catch (Exception e) {
		if (emfMetafile != null) {
			emfMetafile.close();
			emfMetafile.dispose();
			emfMetafile = null;
		}
	}
	return false;
}

}

wmf示例文件.zip (16.2 KB)

将wmf示例文件.zip压缩包里的1.wmf转为png, 使用Aspose.Imaging for Java 效果有偏差,使用 Aspose.PDF For JAVA转换正常,此问题已单独提了,链接如下:

Aspose.Imaging for Java 使用的21.12-jdk16版本,1.wmf转png效果有偏差, 代码如下:

import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.EmfRasterizationOptions;
import com.aspose.imaging.imageoptions.PngOptions;
import com.aspose.imaging.imageoptions.VectorRasterizationOptions;
import com.aspose.imaging.imageoptions.WmfRasterizationOptions;

public class ToImage {
@SuppressWarnings(“resource”)
public static void convert(String fromPath, String toPath) {
Image image = Image.load(fromPath);
try {
VectorRasterizationOptions vectorOption = new VectorRasterizationOptions();
vectorOption.setPageWidth(image.getWidth());
vectorOption.setPageHeight(image.getHeight());

		PngOptions pngOptions = new PngOptions();
		pngOptions.setVectorRasterizationOptions(vectorOption);

		image.save(toPath, pngOptions);
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		image.dispose();
	}
}

}

Aspose.PDF For JAVA 使用的20.12版本,1.wmf转png是正常的 ,代码如下:

import org.apache.commons.lang3.StringUtils;

import com.aspose.pdf.internal.imaging.fileformats.metafile.EmfMetafileImage;
import com.aspose.pdf.internal.imaging.fileformats.metafile.WmfMetafileImage;
import com.aspose.pdf.internal.imaging.imageoptions.*;

public class WmfToImage {

@SuppressWarnings("resource")
public static boolean convert(String fromPath, String toPath) {
	WmfMetafileImage wfmMetafile = null;
	try {
		wfmMetafile = new WmfMetafileImage(fromPath);
		// metafile.setDpi(300);
		wfmMetafile.save(toPath, new PngOptions());
		wfmMetafile.close();
		wfmMetafile.dispose();
		wfmMetafile = null;
		return true;
	} catch (Exception e) {
		if (wfmMetafile != null) {
			wfmMetafile.close();
			wfmMetafile.dispose();
			wfmMetafile = null;
		}
	}
	return false;
}

}

@aaaConvert

我们在问题管理系统中记录了两张调查单,以调查使用“EmfMetaFileImage”类和“WmfMetaFileImage”类将 EMF 和 WMF 转换为 PNG 的可能性。门票 ID 如下:

  • PDFJAVA-41163
  • PDFJAVA-41164

我们将从您的旧代码片段的角度进一步研究故障单的详细信息,并在修复后通知您。请耐心等待,给我们一些时间。

对于 Aspose.Imaging 相关问题,我们请求您创建一个新线程或请在您现有线程中跟进特定 API 相关的问题。

我们对不便表示抱歉。

Aspose.PDF For JAVA 最新的21.11版本已经没有 “EmfMetaFileImage”类和“WmfMetaFileImage”类了,但使用Aspose.Imaging for Java 21.12版本将wmf转png 效果有偏差,速度也比Aspose.PDF For JAVA 20.12版本慢 , emf转png则抛异常,因此当前最新的Aspose.PDF For JAVA 21.11 和Aspose.Imaging for Java 21.12 都用不了。

看以后的Aspose.PDF For JAVA 产品里 “EmfMetaFileImage”类和“WmfMetaFileImage”类继续作为公共成员提供,还是改进Aspose.Imaging for Java产品,修复Aspose.Imaging for Java存在的emf、wmf转图片问题。 希望以后的Aspose.Imaging for Java 产品能解决wmf、emf转图片存在的以上问题,同时转换结束后将占用的内存完全释放掉,避免内存释放不完全问题。

@aaaConvert

如前所述,我们已经记录了两张调查票,以解决与 Aspose.PDF for Java 相关的问题。我们一定会从你刚才提供的信息的角度来调查案件。此外,根据之前的要求 - 请将您对 Aspose.Imaging 的担忧发布在您已经创建的相关线程下,以报告与 Aspose.Imaging 相关的问题。

一旦问题得到解决,我们将进一步通知您。请给我们一些时间。

对于造成的不便,我们深表歉意

补充说明下,使用Aspose.PDF For JAVA 20.12版本用上述代码将wmf、emf转png时,存在内存没有完全释放问题,如下所示:bb399698f25796b6bec55344c93c8a3.png (38.4 KB)
如果Aspose.PDF For JAVA产品新的版本, “EmfMetaFileImage”类和“WmfMetaFileImage”类继续作为公共成员提供,请解决下内存没有完全释放问题

@aaaConvert

我们已将这些信息与故障单一起记录下来,并且在调查问题时一定会考​​虑到这一点。

@SupportDhorde, @aaaConvert

我们从 Aspose.PDF for Java 的角度调查了早期记录的票证。请注意,您应该使用 Aspose.Imaging for Java 项目进行图像转换,以获得更好的特定问题体验。
不应使用 com.aspose.pdf.internal.** 包中的任何内部类,它们将被混淆,并且将来不会作为公共成员提供。