Memory Exception in C #

I am new to C #. Thus, I am not sure what the problem is with my program. The program works with a small image, but it shows “Memory Exception” when it works with a large image about A4 in size. However, the program will be useless if it cannot work with a large image. How can i solve the problem? With thanks.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;


namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            //Bitmap objects

            //input image
            Bitmap bmOrg = (Bitmap)Bitmap.FromFile(@"C:\B.png");  
            Bitmap bmTransparentLayover = new Bitmap(bmOrg.Width, bmOrg.Height);

            //Create Graphic Objects.
            Graphics gOriginal = Graphics.FromImage(bmOrg);
            Graphics gTransparentLayover = Graphics.FromImage(bmTransparentLayover);

            //Set Transparent Graphics back ground to an "odd" color 
            //     that hopefully won't be used to
            //Be changed to transparent later.
            gTransparentLayover.FillRectangle
                                ( Brushes.Pink, 
                                  new Rectangle
                                  (0, 
                                   0, 
                                   bmTransparentLayover.Width, 
                                   bmTransparentLayover.Height
                                  )
                                );

            //Draw "transparent" graphics that will look through 
            //  the overlay onto the original.
            //Using LimeGreen in hopes that it not used.

            Point[] points = new Point[5];
            points[0] = new Point(130, 140);
            points[1] = new Point(130, 370);
            points[2] = new Point(420, 370);
            points[3] = new Point(420, 140);
            points[4] = new Point(130, 140);
            System.Drawing.Drawing2D.GraphicsPath gp = new
            System.Drawing.Drawing2D.GraphicsPath();
            gp.AddPolygon(points);
            gTransparentLayover.FillPath(Brushes.LimeGreen, gp);

            //Now make the LimeGreen Transparent to see through overlay.
            bmTransparentLayover.MakeTransparent(Color.LimeGreen);

            //draw the overlay on top of the original.
            gOriginal.DrawImage(bmTransparentLayover, 
             new Rectangle(0, 0, bmTransparentLayover.Width, bmTransparentLayover.Height));

            //Create new image to make the overlays background tranparent
            Bitmap bm3 = new Bitmap(bmOrg);
            bm3.MakeTransparent(Color.Pink);

            //Save file.
            //to save the output image 
            bm3.Save(@"save.png",System.Drawing.Imaging.ImageFormat.Png);  

            Image img = new Bitmap(480, 480);

            //the background image 
            img = Image.FromFile(@"a.png");  
            Graphics g = Graphics.FromImage(img);

            //to save the combined image 
            g.DrawImage(Image.FromFile(@"save.png"), new Point(-50, -70));
            img.Save(@"final.png", ImageFormat.Png); 
        }
    }
}
+5
source share
3 answers

this image is 9992x8750

, 32- . , 334 . , , . 650 , .

, . , . DLL . , , . 90 . , , , 50 .

, , Bitmap . , 64- Windows . , . , VM

+8

, , .

, , , .Dispose() , .

0

Windows 64-bit, .

0

All Articles