我们通过使用以下代码绘制和编辑PDF,但是当我们使用11MB大小文件播放时,我们会摆脱内存例外,我们是否可以解决问题,我已经使用了System.Drawing.Image.FromFile
而不是从斯特里姆,但没有运气。
public static string ImageCar()
{
string FileName = HttpContext.Current.Session["filename"].ToString();
Document doc = new Document(FileName);
ArrayList arrFiles = new ArrayList();
string strFileName = "";
for (int pageCount = 1; pageCount <= TotalPages; pageCount++)
{
using (FileStream imageStream = new FileStream(HttpContext.Current.Server.MapPath("Input/image_" + strDateTime + "_" + pageCount + ".png"), FileMode.Create, FileAccess.ReadWrite))
{
strFileName = HttpContext.Current.Server.MapPath("Path" + strDateTime + "_" + pageCount + ".png");
arrFiles.Add(strFileName);
PngDevice pngDevice = new PngDevice();
//Convert a particular page and save the image to stream
pngDevice.Process(doc.Pages[pageCount], imageStream);
using (System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream))
{
ScaleImage(image, 1189, 835, HttpContext.Current.Server.MapPath("Input/image1_" + strDateTime + "_" + pageCount + ".png"), out height, out Aratio);
image.Dispose();
imageStream.Close();
if (pageCount == 1)
fields = CheckFields(doc, pageCount, "image1_" + strDateTime + "_" + pageCount + ".png", fields, Convert.ToDouble(Aratio), licensed);
pages = pages + "," + "image1_" + strDateTime + "_" + pageCount + ".png";
Ratios = Ratios + "," + Aratio;
Allheights = Allheights + "," + height;
// Delete file from image folder
try
{
if (File.Exists(strFileName))
{
File.Delete(strFileName);
}
}
catch (Exception ex)
{
}
}
}
}
Ratios = Ratios.Substring(1, Ratios.Length - 1);
pages = pages.Substring(1, pages.Length - 1);
Allheights = Allheights.Substring(1, Allheights.Length - 1);
if (fields != "")
{
fields = fields.Substring(3, fields.Length - 3);
}
return pages + "%#" + Ratios + "%#" + Allheights + "%#" + fields;
}
system.DRAWING在ASP站点中具有已知的内存泄漏,因此不应使用。它最终会出现OOM错误,虽然您可以通过每隔一段时间重新启动服务器来避免它,或者对其进行更多内存,但没有真实的长期修复。在图像操纵部分中使用其他一些库,您应该有更少的问题。
请参阅此页面的底部:https://msdn.microsoft.com/en-us/library/system.drawing(v = vs.110(.aspx
系统中的类。在Windows或ASP.NET服务中不支持Drawing名称空间。尝试从这些应用程序类型之一中使用这些类别可能会产生意外的问题,例如服务性能降低和运行时间异常。有关支持的替代方案,请参阅Windows成像组件。