Ejemplo n.º 1
0
        /// <summary>
        ///     An existing bitmap file.
        /// </summary>
        /// <param name="filename">A file in a .bmp format.</param>
        public BitmapFile(string filename)
        {
            var data = File.ReadAllBytes(filename);

            var pFileHeaderData = Marshal.AllocHGlobal(Marshal.SizeOf(_header));
            try {
                Marshal.Copy(data, 0, pFileHeaderData, Marshal.SizeOf(_header));
                _header = (BitmapFileHeader)Marshal.PtrToStructure(pFileHeaderData, typeof (BitmapFileHeader));
            } finally {
                Marshal.FreeHGlobal(pFileHeaderData);
            }

            var size = data.Length - Marshal.SizeOf(_header);
            var bitmapData = new byte[size];
            Buffer.BlockCopy(data, Marshal.SizeOf(_header), bitmapData, 0, size);
            Bitmap = new DeviceIndependentBitmap(bitmapData);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Create a new icon image resource from a file icon.
 /// </summary>
 /// <param name="icon">File icon.</param>
 /// <param name="type">Resource type.</param>
 /// <param name="name">Resource id.</param>
 /// <param name="language">Resource language.</param>
 public IconImageResource(IconFileIcon icon, ResourceId type, ResourceId name, UInt16 language)
 {
     _name = name;
     _type = type;
     _language = language;
     _header.bColors = icon.Header.bColors;
     _header.bHeight = icon.Header.bHeight;
     _header.bReserved = icon.Header.bReserved;
     _header.bWidth = icon.Header.bWidth;
     _header.dwImageSize = icon.Header.dwImageSize;
     _header.wBitsPerPixel = icon.Header.wBitsPerPixel;
     _header.wPlanes = icon.Header.wPlanes;
     _header.nID = (UInt16)name.Id;
     _image = new DeviceIndependentBitmap(icon.Image);
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Read the resource.
 /// </summary>
 /// <param name="hModule">Module handle.</param>
 /// <param name="lpRes">Pointer to the beginning of a resource.</param>
 /// <returns>Pointer to the end of the resource.</returns>
 internal override IntPtr Read(IntPtr hModule, IntPtr lpRes)
 {
     var data = new byte[_size];
     Marshal.Copy(lpRes, data, 0, data.Length);
     Bitmap = new DeviceIndependentBitmap(data);
     return new IntPtr(lpRes.ToInt32() + _size);
 }
 /// <summary>
 ///     Create a copy of an image.
 /// </summary>
 /// <param name="image">Source image.</param>
 public DeviceIndependentBitmap(DeviceIndependentBitmap image)
 {
     _data = new byte[image._data.Length];
     Buffer.BlockCopy(image._data, 0, _data, 0, image._data.Length);
     Header = image.Header;
 }