コード例 #1
0
 /// <summary>
 /// Creates a bitmap from a filestream.
 /// </summary>
 /// <param name="reader">The System.IO.BinaryReader to use.</param>
 /// <param name="amount">The size in bytes of the image.</param>
 /// <returns>A new bitmap object.</returns>
 public Bitmap LoadFromStream(BinaryReader reader, int amount)
 {
     byte[] bmpBytes = reader.ReadBytes(amount);
     Marshal.Copy(bmpBytes, 0, _data.Scan0, amount);
     _fastImg.LockImage();
     unsafe
     {
         byte *ptr = (byte *)_data.Scan0;
         for (int y = 0; y < _copy.Height; ++y)
         {
             for (int x = 0; x < _copy.Width; ++x)
             {
                 int value = *(ptr);
                 _fastImg.SetPixel(x, y, Color.FromArgb(*(ptr + 3), value, *(ptr + 1), *(ptr + 2)));
                 ptr += 4;
             }
         }
     }
     _fastImg.UnlockImage();
     return(new Bitmap(_image));
 }
コード例 #2
0
ファイル: FastBitmap.cs プロジェクト: slagusev/spherestudio
        /// <summary>
        /// Draws another bitmap into this image using straight-up pixel data.
        /// Not as fast as the Graphics.DrawImage();
        /// </summary>
        /// <param name="img">The source image.</param>
        /// <param name="x">x location in pixels.</param>
        /// <param name="y">y location in pixels.</param>
        public void DrawImage(Bitmap img, int x, int y)
        {
            FastBitmap fastSource = new FastBitmap(img);

            fastSource.LockImage();
            for (int y0 = y; y0 < _image.Height; ++y0)
            {
                if (y0 == Height)
                {
                    continue;
                }
                for (int x0 = x; x0 < _image.Width; ++x0)
                {
                    if (x0 == Width)
                    {
                        continue;
                    }
                    SetPixel(x0, y0, fastSource.GetPixel(x0 - x, y0 - y));
                }
            }
            fastSource.UnlockImage();
        }