private void setDeviceImage(
         Size size,
         System.Windows.Forms.ColorDepth colorDepth
         )
      {
         this.size = size;
         this.colorDepth = colorDepth;         
         // Initialise the data:
         BITMAPINFOHEADER bmInfoHdr = new BITMAPINFOHEADER(
            size, colorDepth);
         this.data = new byte[
            this.MaskImageIndex(bmInfoHdr) + this.MaskImageSize(bmInfoHdr)];
         
         MemoryStream mw = new MemoryStream(this.data, 0, this.data.Length,
          true);
         BinaryWriter bw = new BinaryWriter(mw);
         bmInfoHdr.Write(bw);
         // Write the colour indexes if required:
         switch (this.colorDepth)
         {
            case ColorDepth.Depth4Bit:
               write16ColorPalette(bw);
               break;
            case ColorDepth.Depth8Bit:
               write256ColorPalette(bw);
               break;
         }
         bw.Close();

      }
 /// <summary>
 /// Constructs a new icon device image from an array of
 /// bytes in the Icon file format
 /// </summary>
 /// <param name="b">Array of bytes</param>
 internal IconDeviceImage(
    byte[] b
    )
 {
    // store the bytes:
    data = new Byte[b.Length];
    for (int i = 0; i < b.Length; i++)
    {
       data[i] = b[i];
    }
    
    // Read the BitmapInfoHeader structure to get the 
    // size and number of bytes:
    BITMAPINFOHEADER bmInfoHeader = new BITMAPINFOHEADER(data);
    //Console.WriteLine(bmInfoHeader.ToString());
    
    this.size.Width = bmInfoHeader.biWidth;
    this.size.Height = bmInfoHeader.biHeight/2;
    switch (bmInfoHeader.biBitCount)
    {
       case 1:
       case 4:
          this.colorDepth = ColorDepth.Depth4Bit;            
          break;
       case 8:
          this.colorDepth = ColorDepth.Depth8Bit;
          break;
       case 16:
          this.colorDepth = ColorDepth.Depth16Bit;
          break;
       case 24:
          this.colorDepth = ColorDepth.Depth24Bit;
          break;
       case 32:
          this.colorDepth = ColorDepth.Depth32Bit;
          break;
    }
    createIcon();
 }
Пример #3
0
 public IconFormat(System.Drawing.Size size, System.Windows.Forms.ColorDepth colorDepth)
 {
     _Size       = size;
     _ColorDepth = colorDepth;
 }