使用 aspose 转换后图像未打开

Image is not opening after converting with aspose

我使用下面的代码将 url 流转换为 tiff 图像。但是转换后,转换后的图像无法打开进行预览。有什么想法吗?

var myRequest = (HttpWebRequest)WebRequest.Create("http://www.google.com");

myRequest.Method = "GET";

var myResponse = myRequest.GetResponse();
var responseStream = myResponse.GetResponseStream();
var memoryStream = new MemoryStream();

responseStream.CopyTo(memoryStream);

var loadOptions = new LoadOptions();

loadOptions.LoadFormat = LoadFormat.Html;

var doc = new Document(memoryStream, loadOptions);
var htmlOptions = new HtmlFixedSaveOptions();

htmlOptions.ExportEmbeddedCss = true;
htmlOptions.ExportEmbeddedFonts = true;
htmlOptions.ExportEmbeddedImages = true;
doc.Save(@"C:\out.tif", htmlOptions); 

您在 Save() 方法中使用了 HtmlFixedSaveOptions,因此它将保存为 HTML。尝试在任何文本编辑器中打开 out.tif,您将看到 HTML 个标签。

请在 Save() 方法中使用 ImageSaveOptions,以图像格式保存。即使这样,如果您手动从流中的 URL 获取网页,它也只会获取 HTML。如果没有 css,保存的图像将不好看。我建议让 Aspose 处理 URL.

// If you provide a URL in string, Aspose will load the web page
var doc = new Aspose.Words.Document("http://www.google.com");
// If you just provide the TIF extension, it will save as TIFF image
doc.Save(@"c:\out.tif");
// TO customize, you can use save options in save method

我在 Aspose 工作,担任开发人员布道师。