1

我正在尝试将巨大的图像(1200mm * 1800mm)保存在文件夹中,但出现“内存不足”的异常,所以请给我建议..

提前致谢

protected void btncreateimage_Click(object sender, ImageClickEventArgs e)
{
    string finalImage = null;
    //lblXY.Value=":"download- x + "-" + y + ";";
    pos = lblXY.Value;
    //if (pos != "")
    {
        //get all the files in a directory
        string[] files = Directory.GetFiles(Server.MapPath(@"Upload\"));
        //combine them into one image
        System.Drawing.Bitmap stitchedImage = Combine(files);
        try
        {
            if (finalImage == null)
            {
                Guid g;
                // Create and display the value of two GUIDs.
                g = Guid.NewGuid();
                //save the new image

                Session["guid"] = "output" + g + ".jpg";
                stitchedImage.Save(Server.MapPath(@"Upload\mergeimage\" + Session["guid"].ToString() + ""), System.Drawing.Imaging.ImageFormat.Jpeg);

                stitchedImage.Dispose();
                lblXY.Value = "";
                if (Generate.GenerateWM(Server.MapPath(@"Upload\mergeimage"), Session["guid"].ToString()))
                {
                    string imgname = Session["guid"].ToString();
                    string OriginalFile = Server.MapPath(@"Upload\mergeimage") + "\\" + imgname.Substring(0, imgname.LastIndexOf('.')) + "wm.jpg";
                    System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);

                    MemoryStream ms = new MemoryStream();
                    FullsizeImage.Save(ms, ImageFormat.Jpeg);

                    //byte[] contentBuffer = new byte[ms.Length];
                    //ms.Position = 0;//Reset the position at the start
                    //ms.Read(contentBuffer, 0, (int)ms.Length);
                    //Response.ContentType = "image/jpeg";
                    //Response.BinaryWrite(contentBuffer);

                    FullsizeImage = System.Drawing.Image.FromStream(ms, true, false);
                    System.Drawing.Bitmap NewImage = (Bitmap)FullsizeImage.GetThumbnailImage(14173, 21260, null, IntPtr.Zero);

                    FullsizeImage.Dispose();
                    //ms.Close();

                    NewImage.SetResolution(300, 300);

                    NewImage.Save(Server.MapPath(@"Upload\mergeimage") + "\\" + imgname.Substring(0, imgname.LastIndexOf('.')) + "wm.jpg", ImageFormat.Jpeg);



                    Response.Redirect("SignEditor1.aspx");
                }
            }

        }
        catch (Exception ex)
        {
            throw ex;
        }


    }

}
4

0 回答 0