示例#1
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)
 {
     byte[] data = new byte[_size];
     Marshal.Copy(lpRes, data, 0, data.Length);
     _bitmap = new DeviceIndependentBitmap(data);
     return(new IntPtr(lpRes.ToInt32() + _size));
 }
示例#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);
 }
示例#3
0
        /// <summary>
        /// An existing bitmap file.
        /// </summary>
        /// <param name="filename">A file in a .bmp format.</param>
        public BitmapFile(string filename)
        {
            byte[] data = File.ReadAllBytes(filename);

            IntPtr pFileHeaderData = Marshal.AllocHGlobal(Marshal.SizeOf(_header));

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

            Int32 size = data.Length - Marshal.SizeOf(_header);

            byte[] bitmapData = new byte[size];
            Buffer.BlockCopy(data, Marshal.SizeOf(_header), bitmapData, 0, size);
            _bitmap = new DeviceIndependentBitmap(bitmapData);
        }
示例#4
0
 /// <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;
 }