Beispiel #1
0
 /// <summary>
 /// 初始化视频画刷及显示控件
 /// </summary>
 public void IniVideoRender(BITMAPINFOHEADER BITMAPINFOHEADER)
 {
     drawDib = new DrawDib(this.controlVideo);
     drawDib.BITMAPINFOHEADER = BITMAPINFOHEADER;
     drawDib.BITMAPINFOHEADER.biCompression = (int)BI.BI_RGB;
     drawDib.BITMAPINFOHEADER.biBitCount = 24;
     drawDib.Open();
 }
Beispiel #2
0
        private static byte[] GetControlBitmapArray(Control control)
        {
            control.Capture = true;
            IntPtr hWnd = GetCapture();
            control.Capture = false;
            IntPtr hDC = GetDC(hWnd);
            IntPtr hMemoryDC = CreateCompatibleDC(hDC);

            BITMAPINFOHEADER bih = new BITMAPINFOHEADER();
            bih.biSize = Marshal.SizeOf(bih);
            bih.biBitCount = 24;
            bih.biClrUsed = 0;
            bih.biClrImportant = 0;
            bih.biCompression = 0;
            bih.biHeight = control.Height;
            bih.biWidth = control.Width;
            bih.biPlanes = 1;
            int cb = (int)(bih.biHeight * bih.biWidth * bih.biBitCount / 8);
            bih.biSizeImage = cb;
            bih.biXPelsPerMeter = PelsPerMeter;
            bih.biYPelsPerMeter = PelsPerMeter;

            IntPtr pBits = IntPtr.Zero;
            IntPtr pBIH = LocalAlloc(GPTR, bih.biSize);
            Marshal.StructureToPtr(bih, pBIH, false);
            IntPtr hBitmap = CreateDIBSection(hDC, pBIH, 0, ref pBits, IntPtr.Zero, 0);

            BITMAPINFOHEADER bihMem = (BITMAPINFOHEADER)Marshal.PtrToStructure(pBIH, typeof(BITMAPINFOHEADER));
            IntPtr hPreviousBitmap = SelectObject(hMemoryDC, hBitmap);
            BitBlt(hMemoryDC, 0, 0, bih.biWidth, bih.biHeight, hDC, 0, 0, SRCCOPY);
            byte[] bits = new byte[cb];
            Marshal.Copy(pBits, bits, 0, cb);

            BITMAPFILEHEADER bfh = new BITMAPFILEHEADER();
            bfh.bfSize = (uint)cb + 0x36;
            bfh.bfType = 0x4d42;
            bfh.bfOffBits = 0x36;
            int headerSize = 14;
            byte[] header = new byte[headerSize];
            BitConverter.GetBytes(bfh.bfType).CopyTo(header, 0);
            BitConverter.GetBytes(bfh.bfSize).CopyTo(header, 2);
            BitConverter.GetBytes(bfh.bfOffBits).CopyTo(header, 10);
            byte[] data = new byte[cb + bfh.bfOffBits];
            header.CopyTo(data, 0);
            header = new byte[Marshal.SizeOf(bih)];
            IntPtr pHeader = LocalAlloc(GPTR, Marshal.SizeOf(bih));
            Marshal.StructureToPtr(bihMem, pHeader, false);
            Marshal.Copy(pHeader, header, 0, Marshal.SizeOf(bih));
            LocalFree(pHeader);
            header.CopyTo(data, headerSize);
            bits.CopyTo(data, (int)bfh.bfOffBits);

            DeleteObject(SelectObject(hMemoryDC, hPreviousBitmap));
            DeleteDC(hMemoryDC);
            ReleaseDC(hDC);

            return data;
        }
Beispiel #3
0
        // Methods
        internal IcDvImg(byte[] b)
        {
            this.colorDepth = ColorDepth.Depth4Bit;
            this.hIcon = IntPtr.Zero;
            this.data = new byte[b.Length];
            for (int i = 0; i < b.Length; i++)
            {
                this.data[i] = b[i];
            }
            BITMAPINFOHEADER bitmapinfoheader = new BITMAPINFOHEADER(this.data);
            this.size.Width = bitmapinfoheader.biWidth;
            this.size.Height = bitmapinfoheader.biHeight / 2;
            switch (bitmapinfoheader.biBitCount)
            {
                case 1:
                case 4:
                    this.colorDepth = ColorDepth.Depth4Bit;
                    break;

                case 8:
                    this.colorDepth = ColorDepth.Depth8Bit;
                    break;

                case 0x10:
                    this.colorDepth = ColorDepth.Depth16Bit;
                    break;

                case 0x18:
                    this.colorDepth = ColorDepth.Depth24Bit;
                    break;

                case 0x20:
                    this.colorDepth = ColorDepth.Depth32Bit;
                    break;
            }
            this.createIcon();
        }
      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();

      }
      private void setImageBitsFromBitmap(
         Bitmap bm
         )
      {
         IntPtr hdcc = CreateDC("DISPLAY", IntPtr.Zero, IntPtr.Zero,
          IntPtr.Zero);
         IntPtr hdc = CreateCompatibleDC(hdcc);
         DeleteDC(hdcc);
         IntPtr hBmp = bm.GetHbitmap();

         BITMAPINFOHEADER bmInfoHdr = new BITMAPINFOHEADER(
            this.size, this.colorDepth);

         // Now prepare for GetDIBits call:
         int xorIndex = XorImageIndex(bmInfoHdr);
         int xorImageBytes = XorImageSize(bmInfoHdr);

         // Get the BITMAPINFO header into the pointer:
         IntPtr bitsInfo = Marshal.AllocCoTaskMem(
            xorIndex);
         Marshal.Copy(data, 0, bitsInfo, xorIndex);
         // fix the height:
         Marshal.WriteInt32(bitsInfo, 8, bmInfoHdr.biHeight / 2);

         IntPtr bits = Marshal.AllocCoTaskMem(xorImageBytes);

         int success = GetDIBits(hdc, hBmp, 0, this.size.Height, bits,
          bitsInfo, DIB_RGB_COLORS);

         Marshal.Copy(bits, data, xorIndex, xorImageBytes);

         // Free memory:
         Marshal.FreeCoTaskMem(bits);
         Marshal.FreeCoTaskMem(bitsInfo);

         DeleteObject(hBmp);
         DeleteDC(hdc);

         createIcon();
      }
      private void setMaskBitsFromBitmap(
         Bitmap bm
         )
      {
         IntPtr hdcc = CreateDC("DISPLAY", IntPtr.Zero, IntPtr.Zero,
          IntPtr.Zero);
         IntPtr hdc = CreateCompatibleDC(hdcc);
         DeleteDC(hdcc);
         IntPtr hBmp = bm.GetHbitmap();

         BITMAPINFOHEADER bmInfoHdr = new BITMAPINFOHEADER(
            this.size, this.colorDepth);

         // Now prepare the for GetDIBits call:
         RGBQUAD rgbQuad = new RGBQUAD();
         int monoBmHdrSize = bmInfoHdr.biSize + Marshal.SizeOf(rgbQuad)* 2;

         IntPtr bitsInfo = Marshal.AllocCoTaskMem(
            monoBmHdrSize);
         Marshal.WriteInt32(bitsInfo, Marshal.SizeOf(bmInfoHdr));
         Marshal.WriteInt32(bitsInfo, 4, this.size.Width);
         Marshal.WriteInt32(bitsInfo, 8, this.size.Height);
         Marshal.WriteInt16(bitsInfo, 12, 1);
         Marshal.WriteInt16(bitsInfo, 14, 1);
         Marshal.WriteInt32(bitsInfo, 16, BI_RGB);
         Marshal.WriteInt32(bitsInfo, 20, 0);
         Marshal.WriteInt32(bitsInfo, 24, 0);
         Marshal.WriteInt32(bitsInfo, 28, 0);
         Marshal.WriteInt32(bitsInfo, 32, 0);
         Marshal.WriteInt32(bitsInfo, 36, 0);
         // Write the black and white colour indices:
         Marshal.WriteInt32(bitsInfo, 40, 0);
         Marshal.WriteByte(bitsInfo, 44, 255);
         Marshal.WriteByte(bitsInfo, 45, 255);
         Marshal.WriteByte(bitsInfo, 46, 255);
         Marshal.WriteByte(bitsInfo, 47, 0);

         int maskImageBytes = MaskImageSize(bmInfoHdr);
         IntPtr bits = Marshal.AllocCoTaskMem(maskImageBytes);

         int success = GetDIBits(hdc, hBmp, 0, this.size.Height, bits,
          bitsInfo, DIB_RGB_COLORS);

         Marshal.Copy(bits, data, MaskImageIndex(bmInfoHdr), maskImageBytes);

         // Free memory:
         Marshal.FreeCoTaskMem(bits);
         Marshal.FreeCoTaskMem(bitsInfo);

         DeleteObject(hBmp);
         DeleteDC(hdc);

         createIcon();

      }
Beispiel #7
0
        private int dibNumColors(BITMAPINFOHEADER bmInfoHeader)
        {
            if (bmInfoHeader.biClrUsed != 0)
            {
                return bmInfoHeader.biClrUsed;
            }
            switch (bmInfoHeader.biBitCount)
            {
                case 1:
                    return 2;

                case 4:
                    return 0x10;

                case 8:
                    return 0x100;
            }
            return 0;
        }
 /// <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();
 }
 private int XorImageIndex(
    BITMAPINFOHEADER bmInfoHeader)
 {
    // Returns the position of the DIB bitmap bits within a
    // DIB bitmap array:
    RGBQUAD rgbq = new RGBQUAD();
    return Marshal.SizeOf(bmInfoHeader) + 
       dibNumColors(bmInfoHeader) * Marshal.SizeOf(rgbq);
 }                                            
 private int XorImageSize(
    BITMAPINFOHEADER bmInfoHeader
    )
 {
    int imageBytes = (bmInfoHeader.biHeight/ 2 * 
       WidthBytes(bmInfoHeader.biWidth * bmInfoHeader.biBitCount *
        bmInfoHeader.biPlanes));
    return imageBytes;
 }
Beispiel #11
0
 private void setMaskBitsFromBitmap(Bitmap bm)
 {
     IntPtr hdc = CreateDC("DISPLAY", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
     IntPtr ptr2 = CreateCompatibleDC(hdc);
     DeleteDC(hdc);
     IntPtr hbitmap = bm.GetHbitmap();
     BITMAPINFOHEADER structure = new BITMAPINFOHEADER(this.size, this.colorDepth);
     RGBQUAD rgbquad = new RGBQUAD();
     int cb = structure.biSize + (Marshal.SizeOf(rgbquad) * 2);
     IntPtr ptr = Marshal.AllocCoTaskMem(cb);
     Marshal.WriteInt32(ptr, Marshal.SizeOf(structure));
     Marshal.WriteInt32(ptr, 4, this.size.Width);
     Marshal.WriteInt32(ptr, 8, this.size.Height);
     Marshal.WriteInt16(ptr, 12, (short)1);
     Marshal.WriteInt16(ptr, 14, (short)1);
     Marshal.WriteInt32(ptr, 0x10, 0);
     Marshal.WriteInt32(ptr, 20, 0);
     Marshal.WriteInt32(ptr, 0x18, 0);
     Marshal.WriteInt32(ptr, 0x1c, 0);
     Marshal.WriteInt32(ptr, 0x20, 0);
     Marshal.WriteInt32(ptr, 0x24, 0);
     Marshal.WriteInt32(ptr, 40, 0);
     Marshal.WriteByte(ptr, 0x2c, 0xff);
     Marshal.WriteByte(ptr, 0x2d, 0xff);
     Marshal.WriteByte(ptr, 0x2e, 0xff);
     Marshal.WriteByte(ptr, 0x2f, 0);
     int num2 = this.MaskImageSize(structure);
     IntPtr bits = Marshal.AllocCoTaskMem(num2);
     GetDIBits(ptr2, hbitmap, 0, this.size.Height, bits, ptr, 0);
     Marshal.Copy(bits, this.data, this.MaskImageIndex(structure), num2);
     Marshal.FreeCoTaskMem(bits);
     Marshal.FreeCoTaskMem(ptr);
     DeleteObject(hbitmap);
     DeleteDC(ptr2);
     this.createIcon();
 }
Beispiel #12
0
 private void setImageBitsFromBitmap(Bitmap bm)
 {
     IntPtr hdc = CreateDC("DISPLAY", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
     IntPtr ptr2 = CreateCompatibleDC(hdc);
     DeleteDC(hdc);
     IntPtr hbitmap = bm.GetHbitmap();
     BITMAPINFOHEADER bmInfoHeader = new BITMAPINFOHEADER(this.size, this.colorDepth);
     int cb = this.XorImageIndex(bmInfoHeader);
     int num2 = this.XorImageSize(bmInfoHeader);
     IntPtr destination = Marshal.AllocCoTaskMem(cb);
     Marshal.Copy(this.data, 0, destination, cb);
     Marshal.WriteInt32(destination, 8, bmInfoHeader.biHeight / 2);
     IntPtr bits = Marshal.AllocCoTaskMem(num2);
     GetDIBits(ptr2, hbitmap, 0, this.size.Height, bits, destination, 0);
     Marshal.Copy(bits, this.data, cb, num2);
     Marshal.FreeCoTaskMem(bits);
     Marshal.FreeCoTaskMem(destination);
     DeleteObject(hbitmap);
     DeleteDC(ptr2);
     this.createIcon();
 }
Beispiel #13
0
        private void setDeviceImage(Size size, ColorDepth colorDepth)
        {
            this.size = size;
            this.colorDepth = colorDepth;
            BITMAPINFOHEADER bmInfoHeader = new BITMAPINFOHEADER(size, colorDepth);
            this.data = new byte[this.MaskImageIndex(bmInfoHeader) + this.MaskImageSize(bmInfoHeader)];
            MemoryStream output = new MemoryStream(this.data, 0, this.data.Length, true);
            BinaryWriter bw = new BinaryWriter(output);
            bmInfoHeader.Write(bw);
            switch (this.colorDepth)
            {
                case ColorDepth.Depth4Bit:
                    this.write16ColorPalette(bw);
                    break;

                case ColorDepth.Depth8Bit:
                    this.write256ColorPalette(bw);
                    goto Label_0077;
            }
            Label_0077:
            bw.Close();
        }
Beispiel #14
0
 private int MaskImageSize(BITMAPINFOHEADER bmInfoHeader)
 {
     return ((bmInfoHeader.biHeight / 2) * this.WidthBytes(bmInfoHeader.biWidth));
 }
Beispiel #15
0
 private int MaskImageIndex(BITMAPINFOHEADER bmInfoHeader)
 {
     return (this.XorImageIndex(bmInfoHeader) + this.XorImageSize(bmInfoHeader));
 }
Beispiel #16
0
 private Bitmap getIconBitmap(bool mask, bool returnHandle, ref IntPtr hBmp)
 {
     Bitmap bitmap = null;
     BITMAPINFOHEADER structure = new BITMAPINFOHEADER(this.data);
     if (mask)
     {
         IntPtr hdc = CreateCompatibleDC(IntPtr.Zero);
         hBmp = CreateCompatibleBitmap(hdc, structure.biWidth, structure.biHeight / 2);
         IntPtr hObject = SelectObject(hdc, hBmp);
         RGBQUAD rgbquad = new RGBQUAD();
         int cb = structure.biSize + (Marshal.SizeOf(rgbquad) * 2);
         IntPtr ptr = Marshal.AllocCoTaskMem(cb);
         Marshal.WriteInt32(ptr, Marshal.SizeOf(structure));
         Marshal.WriteInt32(ptr, 4, structure.biWidth);
         Marshal.WriteInt32(ptr, 8, structure.biHeight / 2);
         Marshal.WriteInt16(ptr, 12, (short)1);
         Marshal.WriteInt16(ptr, 14, (short)1);
         Marshal.WriteInt32(ptr, 0x10, 0);
         Marshal.WriteInt32(ptr, 20, 0);
         Marshal.WriteInt32(ptr, 0x18, 0);
         Marshal.WriteInt32(ptr, 0x1c, 0);
         Marshal.WriteInt32(ptr, 0x20, 0);
         Marshal.WriteInt32(ptr, 0x24, 0);
         Marshal.WriteInt32(ptr, 40, 0);
         Marshal.WriteByte(ptr, 0x2c, 0xff);
         Marshal.WriteByte(ptr, 0x2d, 0xff);
         Marshal.WriteByte(ptr, 0x2e, 0xff);
         Marshal.WriteByte(ptr, 0x2f, 0);
         int num2 = this.MaskImageSize(structure);
         IntPtr destination = Marshal.AllocCoTaskMem(num2);
         Marshal.Copy(this.data, this.MaskImageIndex(structure), destination, num2);
         SetDIBitsToDevice(hdc, 0, 0, structure.biWidth, structure.biHeight / 2, 0, 0, 0, structure.biHeight / 2, destination, ptr, 0);
         Marshal.FreeCoTaskMem(destination);
         Marshal.FreeCoTaskMem(ptr);
         SelectObject(hdc, hObject);
         DeleteObject(hdc);
     }
     else
     {
         IntPtr ptr5 = CreateDC("DISPLAY", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
         IntPtr ptr6 = CreateCompatibleDC(ptr5);
         hBmp = CreateCompatibleBitmap(ptr5, structure.biWidth, structure.biHeight / 2);
         DeleteDC(ptr5);
         IntPtr ptr7 = SelectObject(ptr6, hBmp);
         int num3 = this.XorImageIndex(structure);
         int num4 = this.XorImageSize(structure);
         IntPtr ptr8 = Marshal.AllocCoTaskMem(num3);
         Marshal.Copy(this.data, 0, ptr8, num3);
         Marshal.WriteInt32(ptr8, 8, structure.biHeight / 2);
         IntPtr ptr9 = Marshal.AllocCoTaskMem(num4);
         Marshal.Copy(this.data, num3, ptr9, num4);
         SetDIBitsToDevice(ptr6, 0, 0, structure.biWidth, structure.biHeight / 2, 0, 0, 0, structure.biHeight / 2, ptr9, ptr8, 0);
         Marshal.FreeCoTaskMem(ptr9);
         Marshal.FreeCoTaskMem(ptr8);
         SelectObject(ptr6, ptr7);
         DeleteObject(ptr6);
     }
     if (!returnHandle)
     {
         bitmap = Image.FromHbitmap(hBmp);
     }
     return bitmap;
 }
      private Bitmap getIconBitmap(
         bool mask,
         bool returnHandle,
         ref IntPtr hBmp
         )
      {
         // Bitmap to return
         Bitmap bm = null;

         // Get bitmap info:         
         BITMAPINFOHEADER bmInfoHdr = new BITMAPINFOHEADER(data);

         if (mask)
         {
            // extract monochrome mask
            IntPtr hdc = CreateCompatibleDC(IntPtr.Zero);
            hBmp = CreateCompatibleBitmap(hdc, bmInfoHdr.biWidth,
             bmInfoHdr.biHeight / 2);
            IntPtr hBmpOld = SelectObject(hdc, hBmp);

            // Prepare BitmapInfoHeader for mono bitmap:
            RGBQUAD rgbQuad = new RGBQUAD();
            int monoBmHdrSize = bmInfoHdr.biSize + Marshal.SizeOf(rgbQuad)* 2;

            IntPtr bitsInfo = Marshal.AllocCoTaskMem(
               monoBmHdrSize);
            Marshal.WriteInt32(bitsInfo, Marshal.SizeOf(bmInfoHdr));
            Marshal.WriteInt32(bitsInfo, 4, bmInfoHdr.biWidth);
            Marshal.WriteInt32(bitsInfo, 8, bmInfoHdr.biHeight / 2);
            Marshal.WriteInt16(bitsInfo, 12, 1);
            Marshal.WriteInt16(bitsInfo, 14, 1);
            Marshal.WriteInt32(bitsInfo, 16, BI_RGB);
            Marshal.WriteInt32(bitsInfo, 20, 0);
            Marshal.WriteInt32(bitsInfo, 24, 0);
            Marshal.WriteInt32(bitsInfo, 28, 0);
            Marshal.WriteInt32(bitsInfo, 32, 0);
            Marshal.WriteInt32(bitsInfo, 36, 0);
            // Write the black and white colour indices:
            Marshal.WriteInt32(bitsInfo, 40, 0);
            Marshal.WriteByte(bitsInfo, 44, 255);
            Marshal.WriteByte(bitsInfo, 45, 255);
            Marshal.WriteByte(bitsInfo, 46, 255);
            Marshal.WriteByte(bitsInfo, 47, 0);

            // Prepare Mask bits:
            int maskImageBytes = MaskImageSize(bmInfoHdr);
            IntPtr bits = Marshal.AllocCoTaskMem(maskImageBytes);
            Marshal.Copy(data, MaskImageIndex(bmInfoHdr), bits, maskImageBytes);

            int success = SetDIBitsToDevice(
               hdc, 
               0, 0, bmInfoHdr.biWidth, bmInfoHdr.biHeight / 2, 
               0, 0, 0, bmInfoHdr.biHeight / 2, 
               bits, 
               bitsInfo, 
               DIB_RGB_COLORS);

            Marshal.FreeCoTaskMem(bits);
            Marshal.FreeCoTaskMem(bitsInfo);

            SelectObject(hdc, hBmpOld);
            DeleteObject(hdc);

         }
         else
         {
            // extract colour (XOR) part of image:
            
            // Create bitmap:
            IntPtr hdcDesktop = CreateDC("DISPLAY", IntPtr.Zero, IntPtr.Zero,
             IntPtr.Zero);
            IntPtr hdc = CreateCompatibleDC(hdcDesktop);
            hBmp = CreateCompatibleBitmap(hdcDesktop, bmInfoHdr.biWidth,
             bmInfoHdr.biHeight / 2);
            DeleteDC(hdcDesktop);
            IntPtr hBmpOld = SelectObject(hdc, hBmp);
            
            // Find the index of the XOR bytes:
            int xorIndex = XorImageIndex(bmInfoHdr);
            int xorImageSize = XorImageSize(bmInfoHdr);

            // Get Bitmap info header to a pointer:                        
            IntPtr bitsInfo = Marshal.AllocCoTaskMem(xorIndex);
            Marshal.Copy(data, 0, bitsInfo, xorIndex);
            // fix the height:
            Marshal.WriteInt32(bitsInfo, 8, bmInfoHdr.biHeight / 2);

            // Get the XOR bits:            
            IntPtr bits = Marshal.AllocCoTaskMem(xorImageSize);
            Marshal.Copy(data, xorIndex, bits, xorImageSize);

            int success = SetDIBitsToDevice(
               hdc, 
               0, 0, bmInfoHdr.biWidth, bmInfoHdr.biHeight/2, 
               0, 0, 0, bmInfoHdr.biHeight/2, 
               bits, 
               bitsInfo, 
               DIB_RGB_COLORS);

            Marshal.FreeCoTaskMem(bits);
            Marshal.FreeCoTaskMem(bitsInfo);

            SelectObject(hdc, hBmpOld);
            DeleteObject(hdc);
         }

         if (!returnHandle)
         {
            // the bitmap will own the handle and clear
            // it up when it is disposed.  Otherwise
            // need to call DeleteObject on hBmp
            // returned.
            bm = Bitmap.FromHbitmap(hBmp);
         }
         return bm;
      }
 private int MaskImageIndex(
    BITMAPINFOHEADER bmInfoHeader
    )
 {
    int maskImageIndex = XorImageIndex(bmInfoHeader);
    maskImageIndex += XorImageSize(bmInfoHeader);
    return maskImageIndex;
 }
Beispiel #19
0
 private int XorImageIndex(BITMAPINFOHEADER bmInfoHeader)
 {
     RGBQUAD structure = new RGBQUAD();
     return (Marshal.SizeOf(bmInfoHeader) + (this.dibNumColors(bmInfoHeader) * Marshal.SizeOf(structure)));
 }
 private int MaskImageSize(
    BITMAPINFOHEADER bmInfoHeader
    )
 {
    int imageBytes = bmInfoHeader.biHeight / 2 * 
       WidthBytes(bmInfoHeader.biWidth);
    return imageBytes;
 }
Beispiel #21
0
 private int XorImageSize(BITMAPINFOHEADER bmInfoHeader)
 {
     return ((bmInfoHeader.biHeight / 2) * this.WidthBytes((bmInfoHeader.biWidth * bmInfoHeader.biBitCount) * bmInfoHeader.biPlanes));
 }
 private int dibNumColors(
    BITMAPINFOHEADER bmInfoHeader)
 {
    int colorCount = 0;
    if (bmInfoHeader.biClrUsed != 0)
    {
       colorCount = bmInfoHeader.biClrUsed;
    }
    else
    {
       switch (bmInfoHeader.biBitCount)
       {
          case 1:
             colorCount = 2;
             break;
          case 4:
             colorCount = 16;
             break;
          case 8:
             colorCount = 256;
             break;
       }
    }
    return colorCount;      
 }
Beispiel #23
0
        protected void RefreshFakeWnd()
        {
            if (m_bIsRefreshing)
            {
                return;
            }

            if (!NativeMethods.IsWindow(m_FakeWndHandle))
            {
                return;
            }

            m_bIsRefreshing = true;
            POINT         ptSrc    = new POINT(0, 0);
            POINT         ptWinPos = new POINT(this.Left, this.Top);
            SIZE          szWin    = new SIZE(m_BgImg.Width, m_BgImg.Height);
            byte          biAlpha  = 0xFF;
            BLENDFUNCTION stBlend  = new BLENDFUNCTION(BlendOp.AC_SRC_OVER, 0, biAlpha, BlendOp.AC_SRC_ALPHA);

            IntPtr hDC = NativeMethods.GetDC(m_FakeWndHandle);

            if (hDC == IntPtr.Zero)
            {
                m_bIsRefreshing = false;
                Debug.Assert(false, "GetDC failed.");
                return;
            }

            IntPtr hdcMemory = NativeMethods.CreateCompatibleDC(hDC);

            int nBytesPerLine = ((m_BgImg.Width * 32 + 31) & (~31)) >> 3;
            BITMAPINFOHEADER stBmpInfoHeader = new BITMAPINFOHEADER();

            stBmpInfoHeader.Init();
            stBmpInfoHeader.biWidth       = m_BgImg.Width;
            stBmpInfoHeader.biHeight      = m_BgImg.Height;
            stBmpInfoHeader.biPlanes      = 1;
            stBmpInfoHeader.biBitCount    = 32;
            stBmpInfoHeader.biCompression = CompressionType.BI_RGB;
            stBmpInfoHeader.biClrUsed     = 0;
            stBmpInfoHeader.biSizeImage   = (uint)(nBytesPerLine * m_BgImg.Height);

            IntPtr pvBits  = IntPtr.Zero;
            IntPtr hbmpMem = NativeMethods.CreateDIBSection(hDC
                                                            , ref stBmpInfoHeader
                                                            , DIBColorTableIdentifier.DIB_RGB_COLORS
                                                            , out pvBits
                                                            , IntPtr.Zero
                                                            , 0
                                                            );

            Debug.Assert(hbmpMem != IntPtr.Zero, "CreateDIBSection failed.");

            if (hbmpMem != null)
            {
                IntPtr hbmpOld = NativeMethods.SelectObject(hdcMemory, hbmpMem);

                Graphics graphic = Graphics.FromHdcInternal(hdcMemory);

                graphic.DrawImage(m_BgImg, 0, 0, m_BgImg.Width, m_BgImg.Height);

                foreach (Control ctrl in this.Controls)
                {
                    if (!ctrl.Visible)
                    {
                        continue;
                    }

                    using (Bitmap bmp = new Bitmap(ctrl.Width, ctrl.Height))
                    {
                        Rectangle rect = new Rectangle(0, 0, ctrl.Width, ctrl.Height);
                        ctrl.DrawToBitmap(bmp, rect);

                        graphic.DrawImage(bmp, ctrl.Left, ctrl.Top, ctrl.Width, ctrl.Height);
                    }
                }

                GUITHREADINFO stGuiThreadInfo = new GUITHREADINFO();
                stGuiThreadInfo.Init();
                if (NativeMethods.GetGUIThreadInfo((uint)NativeMethods.GetCurrentThreadId(), ref stGuiThreadInfo))
                {
                    if (NativeMethods.IsWindow(stGuiThreadInfo.hwndCaret))
                    {
                        int   height  = stGuiThreadInfo.rcCaret.Bottom - stGuiThreadInfo.rcCaret.Top;
                        POINT ptCaret = new POINT(stGuiThreadInfo.rcCaret.Left, stGuiThreadInfo.rcCaret.Top);

                        NativeMethods.ClientToScreen(stGuiThreadInfo.hwndCaret, ref ptCaret);
                        NativeMethods.ScreenToClient(this.Handle, ref ptCaret);

                        graphic.DrawLine(new Pen(new SolidBrush(Color.Black))
                                         , ptCaret.X
                                         , ptCaret.Y
                                         , ptCaret.X
                                         , ptCaret.Y + height
                                         );
                    }
                }


                NativeMethods.UpdateLayeredWindow(m_FakeWndHandle
                                                  , hDC
                                                  , ref ptWinPos
                                                  , ref szWin
                                                  , hdcMemory
                                                  , ref ptSrc
                                                  , 0
                                                  , ref stBlend
                                                  , UpdateLayerWindowParameter.ULW_ALPHA
                                                  );

                graphic.Dispose();
                NativeMethods.SelectObject(hbmpMem, hbmpOld);
                NativeMethods.DeleteObject(hbmpMem);
            }

            NativeMethods.DeleteDC(hdcMemory);
            NativeMethods.DeleteDC(hDC);

            m_bIsRefreshing = false;
        }
Beispiel #24
0
        private int dibNumColors(
			BITMAPINFOHEADER bmInfoHeader)
        {
            int colorCount = 0;
            //if (bmInfoHeader.biClrUsed != 0)
            //{
            //    colorCount = (int)bmInfoHeader.biClrUsed;
            //}
            //else
            {
                switch (bmInfoHeader.biBitCount)
                {
                    case 1:
                        colorCount = 2;
                        break;
                    case 4:
                        colorCount = 16;
                        break;
                    case 8:
                        colorCount = 256;
                        break;
                    //case 32:
                    //    colorCount = 4294967296;
                    //    break;
                }
            }
            return colorCount;
        }
Beispiel #25
0
		public static extern int AVIStreamSetFormat(
			IntPtr pavi,
			int lPos,
			ref BITMAPINFOHEADER lpFormat,
			int cbFormat);
        protected IntPtr GetPixelInfo(IntPtr bmpptr)
        {
            bmi = new BITMAPINFOHEADER();
            Marshal.PtrToStructure(bmpptr, bmi);

            bmprect.X = bmprect.Y = 0;
            bmprect.Width = bmi.biWidth;
            bmprect.Height = bmi.biHeight;

            if (bmi.biSizeImage == 0)
                bmi.biSizeImage = ((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3) * bmi.biHeight;

            int p = bmi.biClrUsed;
            if ((p == 0) && (bmi.biBitCount <= 8))
                p = 1 << bmi.biBitCount;
            p = (p * 4) + bmi.biSize + (int)bmpptr;
            return (IntPtr)p;
        }
        private IntPtr GetPixelInfo(IntPtr bmpptr)
        {
            BITMAPINFOHEADER bmi = new BITMAPINFOHEADER();
            Marshal.PtrToStructure(bmpptr, bmi);

            Rectangle bmprect = new Rectangle(0, 0, bmi.biWidth, bmi.biHeight);

            if (bmi.biSizeImage == 0)
            {
                bmi.biSizeImage = ((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3) * bmi.biHeight;
            }

            int p = bmi.biClrUsed;

            if ((p == 0) && (bmi.biBitCount <= 8))
            {
                p = 1 << bmi.biBitCount;
            }

            p = (p * 4) + bmi.biSize + (int) bmpptr;

            return (IntPtr) p;
        }