Пример #1
0
        public static void WritePNM(string FilePath, System.Drawing.Image im, PNMEncoding encoding, PNMType ptype)
        {
            FileStream fs = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None);

            IPNMDataWriter dw = PNMFactory.GetIPNMDataWriter(fs, encoding);

            if (dw == null)
            {
                throw new Exception
                          ("Currently only Binary and ASCII encoding is supported");
            }

            try
            {
                //write image header
                dw.WriteLine(PNMFactory.GetMagicWord(ptype, encoding));
                dw.WriteLine(im.Width.ToString() + " " + im.Height.ToString());
                if (ptype != PNMType.PBM)
                {
                    dw.WriteLine("255");
                }

                IPNMWriter imWriter = PNMFactory.GetIPNMWriter(ptype);
                imWriter.WriteImageData(dw, im);
            }
            catch { throw; }
        }
Пример #2
0
        public static IPNMWriter GetIPNMWriter(PNMType ptype)
        {
            IPNMWriter imWriter = null;

            switch (ptype)
            {
            case PNMType.PBM:
                imWriter = new PBMWriter();
                break;

            case PNMType.PGM:
                imWriter = new PGMWriter();
                break;

            case PNMType.PPM:
                imWriter = new PPMWriter();
                break;
            }

            return(imWriter);
        }