zoukankan      html  css  js  c++  java
  • 关于内存DC

    使用CreateCompatibleDC 创建了内存DC之后,要再调用SelectObject选择一张位图放入此DC,然后才可以使用此DC进行绘制,之后绘制的数据会保存在内存中,

    详细说明看后文。

    在MFC中使用内存DC例子:

              // 创建内存DC
                    CDC mMemDc;
                    mMemDc.CreateCompatibleDC( &dc );
    
                    // 创建兼容位图
                    CBitmap bmpMemBmp;
                    bmpMemBmp.CreateCompatibleBitmap( &mMemDc, 100, 100 );
                    CBitmap* pOldBmp = mMemDc.SelectObject( &bmpMemBmp );
    
                    // 在内存DC上绘图
                    BOOL bRet = mMemDc.Ellipse( 0, 0, 100, 100 );
    
                    // 从内存DC上拷贝至显示DC
                    dc.BitBlt( 0, 0, 100, 100, &mMemDc, 0, 0, SRCCOPY );
    
                    // 恢复
                    // When you finish with the CBitmap object created with the
                    // CreateCompatibleBitmap function, first select the bitmap out of the device context, then delete the CBitmap object.
                    mMemDc.SelectObject( pOldBmp );

    以下内容来自msdn:

    CreateCompatibleDC

    The CreateCompatibleDC function creates a memory device context (DC) compatible with the specified device.

    HDC CreateCompatibleDC(
      HDC hdc   // handle to DC
    );

    Remarks

    A memory DC exists only in memory. When the memory DC is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Before an application can use a memory DC for drawing operations, it must select a bitmap of the correct width and height into the DC. To select a bitmap into a DC, use the CreateCompatibleBitmap function, specifying the height, width, and color organization required.

    When a memory DC is created, all attributes are set to normal default values. The memory DC can be used as a normal DC. You can set the attributes; obtain the current settings of its attributes; and select pens, brushes, and regions.

    Memory Device Contexts

    To enable applications to place output in memory rather than sending it to an actual device, use a special device context for bitmap operations called a memory device context. A memory DC enables the system to treat a portion of memory as a virtual device. It is an array of bits in memory that an application can use temporarily to store the color data for bitmaps created on a normal drawing surface. Because the bitmap is compatible with the device, a memory DC is also sometimes referred to as a compatible device context.

    The memory DC stores bitmap images for a particular device. An application can create a memory DC by calling the CreateCompatibleDC function.

    The original bitmap in a memory DC is simply a placeholder. Its dimensions are one pixel by one pixel. Before an application can begin drawing, it must select a bitmap with the appropriate width and height into the DC by calling the SelectObject function. To create a bitmap of the appropriate dimensions, use the CreateBitmap, CreateBitmapIndirect, or CreateCompatibleBitmap function. After the bitmap is selected into the memory DC, the system replaces the single-bit array with an array large enough to store color information for the specified rectangle of pixels.

    When an application passes the handle returned by CreateCompatibleDC to one of the drawing functions, the requested output does not appear on a device's drawing surface. Instead, the system stores the color information for the resultant line, curve, text, or region in the array of bits. The application can copy the image stored in memory back onto a drawing surface by calling the BitBlt function, identifying the memory DC as the source device context and a window or screen DC as the target device context.

    When displaying a DIB or a DDB created from a DIB on a palette device, you can improve the speed at which the image is drawn by arranging the logical palette to match the layout of the system palette. To do this, call GetDeviceCaps with the NUMRESERVED value to get the number of reserved colors in the system. Then call GetSystemPaletteEntries and fill in the first and last NUMRESERVED/2 entries of the logical palette with the corresponding system colors. For example, if NUMRESERVED is 20, you would fill in the first and last 10 entries of the logical palette with the system colors. Then fill in the remaining 256-NUMRESERVED colors of the logical palette (in our example, the remaining 236 colors) with colors from the DIB and set the PC_NOCOLLAPSE flag on each of these colors.

    For more information about color and palettes, see Colors. For more information about bitmaps and bitmap operations, see Bitmaps

  • 相关阅读:
    Flash/Flex学习笔记(30):不用startDrag和stopDrag的对象拖动
    Flash/Flex学习笔记(33):如何用As3协同Flash CS IDE控制MovieClip实例
    Flash/Flex学习笔记(26):AS3自定义右键菜单
    Flash/Flex学习笔记(32):播放音乐并同步显示lyc歌词(适用于Silverlight)
    Flash/Flex学习笔记(35):如何正确监听Stage对象的事件
    jQuery autoComplete 自动完成 支持中文
    黑马程序员视频学习下载地址记录一下
    汉语分词系统 网址
    【转】Lucene.Net 详解
    MongoDB开发学习 开天辟地,经典入门 解决关系型数据库大数据量处理的瓶颈问题
  • 原文地址:https://www.cnblogs.com/shanql/p/6575915.html
Copyright © 2011-2022 走看看