當前位置: 首頁>>代碼示例>>C#>>正文


C# BITMAPINFO類代碼示例

本文整理匯總了C#中BITMAPINFO的典型用法代碼示例。如果您正苦於以下問題:C# BITMAPINFO類的具體用法?C# BITMAPINFO怎麽用?C# BITMAPINFO使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BITMAPINFO類屬於命名空間,在下文中一共展示了BITMAPINFO類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateBuffer

 /// <summary>
 /// Creates a new <see cref="NativeBuffer"/> with the given dimensions.
 /// </summary>
 /// <param name="buffer">The storage location for the buffer object.</param>
 /// <param name="w">The width.</param>
 /// <param name="h">The height.</param>
 /// <param name="isDIB">True if the buffer should be DIB backed, false for Marshal.</param>
 /// <returns>Returns the data buffer.</returns>
 public static ARGB* CreateBuffer(out NativeBuffer buffer, int w, int h, bool isDIB)
 {
     ARGB* pixels;
     IntPtr handle;
     DeviceContext context = null;
     if(isDIB)
     {
         context = new DeviceContext();
         //create info
         BITMAPINFO info = new BITMAPINFO();
         //init with size
         info.init(w, h);
         //create DIB
         handle = CreateDIBSection(context.Handle, ref info, DIB_RGB_COLORS, out pixels, IntPtr.Zero, 0);
         WinAPIUtils.Assert(handle != IntPtr.Zero);
         //select the DIB into the DC
         context.Push(handle);
     }else
     {
         handle = Marshal.AllocHGlobal(w * h * 4);
         pixels = (ARGB*)handle;
     }
     //create buffer wrapper
     buffer = new NativeBuffer{isDIB = isDIB, Handle = handle, Context = context};
     //return the data
     return pixels;
 }
開發者ID:jonhartnett,項目名稱:IROM-Util,代碼行數:35,代碼來源:NativeBuffer.cs

示例2: Create24bppDIBSection

 public static IntPtr Create24bppDIBSection(int nWidth, int nHeight)
 {
     BITMAPINFO bmi = new BITMAPINFO(nWidth, nHeight, 24);
     IntPtr pBits;
     return CreateDIBSection(IntPtr.Zero, bmi, DIB_RGB_COLORS, out pBits,
     IntPtr.Zero, 0);
 }
開發者ID:edisonh,項目名稱:Forex-Strategy-Trader,代碼行數:7,代碼來源:DIBSection.cs

示例3: Resize

        /// <summary>
        /// Resizes the section.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitCount">The bit count.</param>
        public void Resize(int width, int height, int bitCount)
        {
            //	Destroy existing objects.
            Destroy();

            //  Set parameters.
            Width = width;
            Height = height;

            //	Create a bitmap info structure.
            BITMAPINFO info = new BITMAPINFO();
            info.Init();

            //	Set the data.
            info.biBitCount = (short)bitCount;
            info.biPlanes = 1;
            info.biWidth = width;
            info.biHeight = height;

            //	Create the bitmap.
            HBitmap = Win32.CreateDIBSection(parentDC, ref info, Win32.DIB_RGB_COLORS,
                out bits, IntPtr.Zero, 0);

            Win32.SelectObject(parentDC, HBitmap);
        }
開發者ID:Mofangbao,項目名稱:CSharpGL,代碼行數:31,代碼來源:DIBSection.cs

示例4: Create

        /// <summary>
        /// Creates the specified width.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitCount">The bit count.</param>
        /// <returns></returns>
        public virtual bool Create(IntPtr hDC, int width, int height, int bitCount)
        {
            this.Width = width;
            this.Height = height;
            parentDC = hDC;

            //	Destroy existing objects.
            Destroy();

            //	Create a bitmap info structure.
            BITMAPINFO info = new BITMAPINFO();
            info.Init();

            //	Set the data.
            info.biBitCount = (short)bitCount;
            info.biPlanes = 1;
            info.biWidth = width;
            info.biHeight = height;

            //	Create the bitmap.
            HBitmap = Win32.CreateDIBSection(hDC, ref info, Win32.DIB_RGB_COLORS,
                out bits, IntPtr.Zero, 0);

            Win32.SelectObject(hDC, HBitmap);

            //	Set the OpenGL pixel format.
            SetPixelFormat(hDC, bitCount);

            return true;
        }
開發者ID:Mofangbao,項目名稱:CSharpGL,代碼行數:37,代碼來源:DIBSection.cs

示例5: DrawText

        public static void DrawText(Graphics graphics, string text, Font font, Rectangle bounds, Color color, TextFormatFlags flags, TextStyle textStyle)
        {
            if (!VisualStyleRenderer.IsSupported) {
                TextRenderer.DrawText(graphics, text, font, bounds, color, flags);
                return;
            }

            IntPtr primaryHdc = graphics.GetHdc();

            // Create a memory DC so we can work offscreen
            IntPtr memoryHdc = CreateCompatibleDC(primaryHdc);

            // Create a device-independent bitmap and select it into our DC
            BITMAPINFO info = new BITMAPINFO();
            info.biSize = Marshal.SizeOf(info);
            info.biWidth = bounds.Width;
            info.biHeight = -bounds.Height;
            info.biPlanes = 1;
            info.biBitCount = 32;
            info.biCompression = 0; // BI_RGB
            IntPtr dib = CreateDIBSection(primaryHdc, info, 0, 0, IntPtr.Zero, 0);
            SelectObject(memoryHdc, dib);

            // Create and select font
            IntPtr fontHandle = font.ToHfont();
            SelectObject(memoryHdc, fontHandle);

            // Draw glowing text
            VisualStyleRenderer renderer = new VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
            DTTOPTS dttOpts = new DTTOPTS();
            dttOpts.dwSize = Marshal.SizeOf(typeof(DTTOPTS));

            if (textStyle == TextStyle.Glowing) {
                dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE | DTT_TEXTCOLOR;
            }
            else {
                dttOpts.dwFlags = DTT_COMPOSITED | DTT_TEXTCOLOR;
            }
            dttOpts.crText = ColorTranslator.ToWin32(color);
            dttOpts.iGlowSize = 8; // This is about the size Microsoft Word 2007 uses
            RECT textBounds = new RECT(0, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top);
            DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, -1, (int)flags, ref textBounds, ref dttOpts);

            // Copy to foreground
            const int SRCCOPY = 0x00CC0020;
            BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY);

            // Clean up
            DeleteObject(fontHandle);
            DeleteObject(dib);
            DeleteDC(memoryHdc);

            graphics.ReleaseHdc(primaryHdc);
        }
開發者ID:kzys,項目名稱:Gmail-Notifier-Plus,代碼行數:54,代碼來源:GlassHelper.cs

示例6: VideoEncoder

        /// <summary>
        /// 初始化視頻編解碼器
        /// </summary>
        /// <param name="bitmapInfoHeader">圖像頭信息</param>
        /// <param name="isEncode">標識完成編碼還是解碼功能</param>
        public VideoEncoder(BITMAPINFOHEADER bitmapInfoHeader, bool isEncode)
        {
            #region
            //BITMAPINFOHEADER bmi = new BITMAPINFOHEADER ();
            //bmi.biWidth = bitmapInfoHeader.biWidth;
            //bmi.biHeight = bitmapInfoHeader.biHeight;
            //if (isEncode)
            //{
            //    bmi.biCompression =bitmapInfoHeader.biCompression;
            //}
            //else
            //{
            //    bmi.biCompression = FOURCC.MP42;
            //}
            //bmi.biSizeImage =bitmapInfoHeader.biSizeImage;
            //bmi.biPlanes = bitmapInfoHeader.biPlanes;
            //bmi.biBitCount =   bitmapInfoHeader.biBitCount;
            //bmi.biXPelsPerMeter = bitmapInfoHeader.biXPelsPerMeter;
            //bmi.biYPelsPerMeter = bitmapInfoHeader.biYPelsPerMeter;
            //bmi.biClrUsed = bitmapInfoHeader.biClrUsed;
            //bmi.biClrImportant = bitmapInfoHeader.biClrImportant;
            //bmi.biSize = bitmapInfoHeader.biSize;
            //bitmapInfo.bmiHeader = bmi;
            #endregion

            BITMAPINFO bitmapInfo = new BITMAPINFO();
            bitmapInfo.bmiHeader = bitmapInfoHeader;

            this.IsEncode = isEncode;
            if (isEncode)
            {
                COMPVARS compvars = new COMPVARS();
                compvars.cbSize = Marshal.SizeOf(compvars);
                compvars.dwFlags = 1;
                compvars.fccHandler = FOURCC.MP42;
                compvars.fccType = FOURCC.ICTYPE_VIDEO;
                compvars.lDataRate = 780;
                compvars.lKey = 15;
                compvars.lQ = -1;
                compvars.lQ = 500;

                this.Compressor = new ICCompressor(compvars, bitmapInfo, FOURCC.MP42);
                this.Compressor.Open();//打開編碼器
            }
            else
            {
                bitmapInfo.bmiHeader.biCompression = FOURCC.MP42;
                this.Decompressor = new ICDecompressor(new COMPVARS(), bitmapInfo, FOURCC.MP42);
                this.Decompressor.Open();
            }
        }
開發者ID:songques,項目名稱:CSSIM_Solution,代碼行數:56,代碼來源:VideoEncoder.cs

示例7: Display

        public Display()
        {
            InitializeComponent();

            bmi = new BITMAPINFO
            {
                biHeader =
                {
                    bihBitCount = 32,
                    bihPlanes = 1,
                    bihSize = 40,
                    bihWidth = 320,
                    bihHeight = 240,
                    bihSizeImage = 320 * 240 * 4
                }
            };

            g = pbDisplay.CreateGraphics();
            display = pbDisplay;

            stopWatch.Start();
        }
開發者ID:Sasha7b9,項目名稱:Osci,代碼行數:22,代碼來源:Display.cs

示例8: PixelBuffer

    public PixelBuffer(int width, int height)
    {
        // Create a MemoryDC to hold the bitmap.  Use IntPtr.Zero 
        // to create a device context that is compatible with the screen.
        
        fMemoryDC = GDI32.CreateCompatibleDC(IntPtr.Zero);


        // Create a bitmap compatible with the screen
        fBitmapInfo = new BITMAPINFO();
        fBitmapInfo.Init();


        fBitmapInfo.bmiHeader.biWidth = width;
        fBitmapInfo.bmiHeader.biHeight = -height;
        fBitmapInfo.bmiHeader.biPlanes = 1;
        fBitmapInfo.bmiHeader.biBitCount = 32;
        fBitmapInfo.bmiHeader.biClrImportant = 0;
        fBitmapInfo.bmiHeader.biClrUsed = 0;
        fBitmapInfo.bmiHeader.biCompression = GDI32.BI_RGB;
        fBitmapInfo.bmiColors = IntPtr.Zero;
        
        fBitmapHandle = GDI32.CreateDIBSection(User32.GetDC(IntPtr.Zero),
            ref fBitmapInfo, GDI32.DIB_RGB_COLORS, ref fBits, IntPtr.Zero, 0);

        fPixelData = new PixelData(width, height, 32, width * 4, fBits);

        // Get the bitmap structure back out so we can 
        // get our hands on the created pointer and whatnot
        //GDI32.GetBitmap(fBitmapHandle, ref fBitmapStructure);
        //fBits = fBitmapStructure.bmBits;

        // Select the bitmap into the memoryDC
        fOldBitmapHandle = GDI32.SelectObject(fMemoryDC, fBitmapHandle);
        fAlpha = 255;
    }
開發者ID:Wiladams,項目名稱:NewTOAPIA,代碼行數:36,代碼來源:PixelBuffer.cs

示例9: AddHelper

        /// <summary>
        /// Add or replace an entry in the given image list
        /// </summary>
        /// <param name="bm">The image</param>
        /// <param name="il">The image list to modify</param>
        /// <param name="replace">If true replace the existing index with the one given</param>
        /// <param name="replaceIndex">The replacement index</param>
        private static void AddHelper( Bitmap bm, ImageList il, bool replace, int replaceIndex )
        {
            IntPtr hBitmap, ppvBits;
            BITMAPINFO bmi = new BITMAPINFO();

            // Resize the image to dimensions of imagelist before adding
            if( bm.Size != il.ImageSize ) {
                bm = new Bitmap( bm, il.ImageSize.Width, il.ImageSize.Height );
            }

            // Required due to the way bitmap is copied and read
            bmi.biSize = 40;            // Needed for RtlMoveMemory()
            bmi.biBitCount = 32;        // Number of bits
            bmi.biPlanes = 1;           // Number of planes
            bmi.biWidth = bm.Width;     // Width of our new bitmap
            bmi.biHeight = bm.Height;   // Height of our new bitmap
            bm.RotateFlip( RotateFlipType.RotateNoneFlipY );

            // Create our new bitmap
            hBitmap = CreateDIBSection( new IntPtr( 0 ), bmi, 0,
                      out ppvBits, new IntPtr( 0 ), 0 );

            // Copy the bitmap
            BitmapData bitmapData = bm.LockBits( new Rectangle( 0, 0,
                       bm.Width, bm.Height ), ImageLockMode.ReadOnly,
                       PixelFormat.Format32bppArgb );
            RtlMoveMemory( ppvBits, bitmapData.Scan0,
                           bm.Height * bitmapData.Stride );
            bm.UnlockBits( bitmapData );

            // Adds the new bitmap to the imagelist control or replaces the existing bitmap
            if( replace )
                ImageList_Replace( il.Handle, replaceIndex, hBitmap, new IntPtr( 0 ) );
            else
                ImageList_Add( il.Handle, hBitmap, new IntPtr( 0 ) );
        }
開發者ID:ClassroomPresenter,項目名稱:CP3,代碼行數:43,代碼來源:ImageListHelper.cs

示例10: CreateDIBSection

		static public extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFO bmi, uint Usage, out IntPtr bits, IntPtr hSection, uint dwOffset);
開發者ID:ratsil,項目名稱:bethe.helpers,代碼行數:1,代碼來源:WinAPI.cs

示例11: CreateDIBSection

 internal static extern IntPtr CreateDIBSection(IntPtr hDC, BITMAPINFO pBMI, uint iUsage, int ppvBits, IntPtr hSection, uint dwOffset);
開發者ID:ComponentFactory,項目名稱:Krypton,代碼行數:1,代碼來源:PlatformInvoke.cs

示例12: SetDIBitsToDevice

 private static extern int SetDIBitsToDevice(IntPtr hdc,
                                             int xDest,
                                             int yDest,
                                             UInt32 dwWidth,
                                             UInt32 dwHeight,
                                             int xSrc,
                                             int ySrc,
                                             UInt32 uStartScan,
                                             UInt32 cScanLines,
                                             IntPtr lpvBits,
                                             ref BITMAPINFO lpbmi,
                                             UInt32 fuColorUse);
開發者ID:hardborn,項目名稱:MonitorManager,代碼行數:12,代碼來源:UC_StandarAndSimpleLayout.cs

示例13: SendBitmapMessage

 static extern int SendBitmapMessage(int hWnd, uint wMsg, int wParam, ref BITMAPINFO lParam);
開發者ID:JohannesHoppe,項目名稱:clustered-neuronal-network,代碼行數:1,代碼來源:WebCameraDevice.cs

示例14: SetDIBitsToDevice

 private static extern int SetDIBitsToDevice(HandleRef hDC, int xDest, int yDest, int dwWidth, int dwHeight, int XSrc, int YSrc, int uStartScan, int cScanLines, ref int lpvBits, ref BITMAPINFO lpbmi, uint fuColorUse);
開發者ID:Ring-r,項目名稱:sandbox,代碼行數:1,代碼來源:RazorBitmap.cs

示例15: CreateDIBSection

 private static extern IntPtr CreateDIBSection(IntPtr hdc,ref BITMAPINFO pbmi, uint iUsage, int ppvBits, IntPtr hSection, uint dwOffset);
開發者ID:SweetX,項目名稱:ARKS-Translator,代碼行數:1,代碼來源:TextOnGlass.GlassText.cs


注:本文中的BITMAPINFO類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。