コード例 #1
0
ファイル: PnmImage.cs プロジェクト: zer09/Cosmos
                public override Image ReadImageData(IPnmDataReader dr, int width, int height)
                {
                    Image image;

                    try
                    {
                        Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                        System.Drawing.Imaging.BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                        byte[] data = new byte[height * bitmapdata.Stride];
                        for (int i = 0; i < height; i++)
                        {
                            dr.Read(data, i * bitmapdata.Stride, width * 3);
                        }
                        System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length);
                        bitmap.UnlockBits(bitmapdata);
                        image = bitmap;
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        dr.Close();
                    }
                    return(image);
                }
コード例 #2
0
ファイル: PnmImage.cs プロジェクト: zer09/Cosmos
                public override Image ReadImageData(IPnmDataReader dr, int width, int height)
                {
                    Image image;

                    try
                    {
                        int    count  = (dr is ASCIIDataReader) ? width : ((int)Math.Ceiling((double)(((double)width) / 8.0)));
                        Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                        System.Drawing.Imaging.BitmapData   bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                        System.Drawing.Imaging.ColorPalette palette    = bitmap.Palette;
                        palette.Entries[0] = Color.Black;
                        palette.Entries[1] = Color.White;
                        bitmap.Palette     = palette;
                        byte[] data = new byte[height * bitmapdata.Stride];
                        for (int i = 0; i < height; i++)
                        {
                            dr.Read(data, i * bitmapdata.Stride, count);
                        }
                        System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length);
                        bitmap.UnlockBits(bitmapdata);
                        image = bitmap;
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        dr.Close();
                    }
                    return(image);
                }
コード例 #3
0
ファイル: PnmImage.cs プロジェクト: zer09/Cosmos
                public override Image ReadImageData(IPnmDataReader dr, int width, int height)
                {
                    Image image;

                    try
                    {
                        Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                        System.Drawing.Imaging.BitmapData   bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                        System.Drawing.Imaging.ColorPalette palette    = bitmap.Palette;
                        for (int i = 0; i < palette.Entries.Length; i++)
                        {
                            palette.Entries[i] = Color.FromArgb(i, i, i);
                        }
                        bitmap.Palette = palette;
                        byte[] data = new byte[height * bitmapdata.Stride];
                        for (int j = 0; j < height; j++)
                        {
                            dr.Read(data, j * bitmapdata.Stride, width);
                        }
                        System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length);
                        bitmap.UnlockBits(bitmapdata);
                        image = bitmap;
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        dr.Close();
                    }
                    return(image);
                }
コード例 #4
0
ファイル: PnmImage.cs プロジェクト: zer09/Cosmos
            public static Image ReadPnm(Stream inputStream)
            {
                char   ch;
                string str;
                string magicWord = ((char)inputStream.ReadByte()).ToString() + ((char)inputStream.ReadByte()).ToString();

                inputStream.ReadByte();
                PnmEncoding    pNMEncoding    = PnmFactory.GetPNMEncoding(magicWord);
                IPnmDataReader iPNMDataReader = PnmFactory.GetIPNMDataReader(inputStream, pNMEncoding);

                if (iPNMDataReader == null)
                {
                    throw new Exception("Currently only Binary and ASCII encoding is supported");
                }
                IPnmReader iPNMReader = PnmFactory.GetIPNMReader(PnmFactory.GetPNMType(magicWord));

                if (iPNMReader == null)
                {
                    throw new Exception("Currently only PBM, PGM and PNM Image Types are supported");
                }
                do
                {
                    str = iPNMDataReader.ReadLine();
                    if (str.Length == 0)
                    {
                        ch = '#';
                    }
                    else
                    {
                        ch = str.Substring(0, 1).ToCharArray(0, 1)[0];
                    }
                }while (ch == '#');
                string[] strArray = str.Split(new char[] { ' ' });
                int      width    = int.Parse(strArray[0]);
                int      height   = int.Parse(strArray[1]);

                if (magicWord != "P1")
                {
                    do
                    {
                        str = iPNMDataReader.ReadLine();
                        if (str.Length == 0)
                        {
                            ch = '#';
                        }
                        else
                        {
                            ch = str.Substring(0, 1).ToCharArray(0, 1)[0];
                        }
                    }while (ch == '#');
                    if (int.Parse(str) != 0xff)
                    {
                        Console.WriteLine("Warning, max value for pixels in this image is not 255");
                    }
                }
                return(iPNMReader.ReadImageData(iPNMDataReader, width, height));
            }
コード例 #5
0
ファイル: PnmImage.cs プロジェクト: zer09/Cosmos
 public abstract Image ReadImageData(IPnmDataReader dr, int width, int height);
コード例 #6
0
ファイル: PnmImage.cs プロジェクト: ChrisJamesSadler/Cosmos
 public override Image ReadImageData(IPnmDataReader dr, int width, int height)
 {
     Image image;
     try
     {
         Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
         System.Drawing.Imaging.BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
         byte[] data = new byte[height * bitmapdata.Stride];
         for (int i = 0; i < height; i++)
         {
             dr.Read(data, i * bitmapdata.Stride, width * 3);
         }
         System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length);
         bitmap.UnlockBits(bitmapdata);
         image = bitmap;
     }
     catch
     {
         throw;
     }
     finally
     {
         dr.Close();
     }
     return image;
 }
コード例 #7
0
ファイル: PnmImage.cs プロジェクト: ChrisJamesSadler/Cosmos
 public override Image ReadImageData(IPnmDataReader dr, int width, int height)
 {
     Image image;
     try
     {
         Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
         System.Drawing.Imaging.BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
         System.Drawing.Imaging.ColorPalette palette = bitmap.Palette;
         for (int i = 0; i < palette.Entries.Length; i++)
         {
             palette.Entries[i] = Color.FromArgb(i, i, i);
         }
         bitmap.Palette = palette;
         byte[] data = new byte[height * bitmapdata.Stride];
         for (int j = 0; j < height; j++)
         {
             dr.Read(data, j * bitmapdata.Stride, width);
         }
         System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length);
         bitmap.UnlockBits(bitmapdata);
         image = bitmap;
     }
     catch
     {
         throw;
     }
     finally
     {
         dr.Close();
     }
     return image;
 }
コード例 #8
0
ファイル: PnmImage.cs プロジェクト: ChrisJamesSadler/Cosmos
 public override Image ReadImageData(IPnmDataReader dr, int width, int height)
 {
     Image image;
     try
     {
         int count = (dr is ASCIIDataReader) ? width : ((int)Math.Ceiling((double)(((double)width) / 8.0)));
         Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
         System.Drawing.Imaging.BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
         System.Drawing.Imaging.ColorPalette palette = bitmap.Palette;
         palette.Entries[0] = Color.Black;
         palette.Entries[1] = Color.White;
         bitmap.Palette = palette;
         byte[] data = new byte[height * bitmapdata.Stride];
         for (int i = 0; i < height; i++)
         {
             dr.Read(data, i * bitmapdata.Stride, count);
         }
         System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length);
         bitmap.UnlockBits(bitmapdata);
         image = bitmap;
     }
     catch
     {
         throw;
     }
     finally
     {
         dr.Close();
     }
     return image;
 }
コード例 #9
0
ファイル: PnmImage.cs プロジェクト: ChrisJamesSadler/Cosmos
 public abstract Image ReadImageData(IPnmDataReader dr, int width, int height);