链接参考:http://www.cnblogs.com/juncheng/articles/1600730.html

CImage是MFC和ATL共享的新类,它能从外部磁盘中调入一个JPEG、GIF、BMP和PNG格式的图像文件加以显示,而且这些文件格式可以相互转换。例如通过简单的几句,就可以实现CImage类和CBitmap类实例的转换:

HBITMAP hBitmap=image.Detach();

CBitmap bmp;

bmp.Attach(hBitmap);

这样一来,就又回归到以前操纵CBitmap的方式了.CImage本身封装了DIB(设备无关位图)的功能,因而能够处理每个位图像素。

它具有下列最酷特性:

  1、AlphaBlend支持像素级的颜色混合,从而实现透明和半透明的效果。

  2、PlgBlt能使一个矩形区域的位图映射到一个平行四边形区域中,而且还可能使用位屏蔽操作。

  3、TransparentBlt在目标区域中产生透明图像,SetTransparentColor用来设置某种颜色是透明色。

  4、MaskBlt在目标区域中产生源位图与屏蔽位图合成的效果。

由于CImage在不同的Windows操作系统中其某些性能是不一样的,因此在使用时要特别注意。例如,CImage::PlgBlt和CImage::MaskBlt只能在 Windows NT 4.0 或更高版本中使用,但不能运行在Windows 95/98 应用程序中。CImage::AlphaBlend和CImage::TransparentBlt也只能在 Windows 2000/98或其更高版本中使用。即使在Windows 2000运行程序还必须将stdafx.h文件中的WINVER和_WIN32_WINNT的预定义修改成0x0500才能正常使用。

(1):MFC中显示图像的类CImage:

我使用的函数:

void CAviTestDlg::showCimage(CImage &image)
{
//CImage image; //创建图片类
//image.Load(rphoto); //根据图片路径加载图片
CRect rect;//定义矩形类
int cx = image.GetWidth();//获取图片宽度
int cy = image.GetHeight();//获取图片高度
GetDlgItem(IDC_SHOWPIC)->GetWindowRect(&rect);//将窗口矩形选中到picture控件上
ScreenToClient(&rect);//将客户区选中到Picture控件表示的矩形区域内
GetDlgItem(IDC_SHOWPIC)->MoveWindow(rect.left, rect.top, cx, cy, TRUE);//将窗口移动到Picture控
CWnd *pWnd=GetDlgItem(IDC_SHOWPIC);//获得pictrue控件窗口的句柄
pWnd->GetClientRect(&rect);//获得pictrue控件所在的矩形区域
CDC *pDC=pWnd->GetDC();//获得pictrue控件的DC
image.Draw(pDC->m_hDC, rect); //将图片画到Picture控件表示的矩形区域
ReleaseDC(pDC);//释放picture控件的DC
}

(2):CImage(MFC) 加载剪贴板图像数据

CView *cv=this;
CImage* m_image;
OpenClipboard(NULL);
HANDLE h=::GetClipboardData(CF_BITMAP);
if(h==0)
{
CloseClipboard();
return;
}
BITMAP bm;
GetObject(h,sizeof(bm),&bm);
if(m_image!=NULL)
{
delete m_image;
m_image=NULL;
}
m_image=new CImage();
m_image->Create(bm.bmWidth,bm.bmHeight,32,0);
HDC hdc=m_image->GetDC();
CDC imgDC;
imgDC.Attach(hdc);
CBitmap *pBmp=new CBitmap;
pBmp->Attach(h);
CClientDC dc(cv);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap *pOldBitmap=memDC.SelectObject(pBmp);
imgDC.BitBlt(0,0,bm.bmWidth,bm.bmHeight,&memDC,0,0,SRCCOPY);
memDC.SelectObject(pOldBitmap);
pBmp->Detach();
delete pBmp;
imgDC.Detach();
m_image->ReleaseDC();

(3):微软官方说明:http://technet.microsoft.com/zh-cn/magazine/k826sz5e(en-us,VS.80).aspx

类的使用:http://msdn.microsoft.com/zh-cn/library/bwea7by5(v=vs.80)

CImage::Create 

Creates a CImage bitmap and attach it to the previously constructed CImage object.

BOOL Create(
int nWidth,
int nHeight,
int nBPP,
DWORD dwFlags = 0
) throw( );

Parameters

nWidth

The width of the CImage bitmap, in pixels.

nHeight

The height of the CImage bitmap, in pixels. If nHeight is
positive, the bitmap is a bottom-up DIB and its origin is the lower left corner. If nHeight is
negative, the bitmap is a top-down DIB and its origin is the upper left corner.

nBPP

The numbers of bits per pixel in the bitmap. Usually 4, 8, 16, 24, or 32. Can be 1 for monochrome bitmaps or masks.

dwFlags

Specifies if the bitmap object has an alpha channel. Can be a combination of zero or more of the following values:

  • createAlphaChannel   Can only be used if nBPP is 32, and eCompression is BI_RGB.
    If specified, the created image has an alpha (transparency) value for each pixel, stored in the 4th byte of each pixel (unused in a non-alpha 32-bit image). This alpha channel is automatically used when callingCImage::AlphaBlend.

CImage类的使用介绍!的更多相关文章

  1. CImage类的介绍与使用

    CImage类的介绍与使用 程序代码下载处:http://download.csdn.net/source/2098910 下载处:http://hi.baidu.com/wangleitongxin ...

  2. 用CImage类来显示PNG、JPG等图片

    系统环境:Windows 7软件环境:Visual Studio 2008 SP1本次目的:实现VC单文档.对话框程序显示图片效果 CImage 是VC.NET中定义的一种MFC/ATL共享类,也是A ...

  3. GDI 总结三: CImage类使用

    前言          CImage类是基于GDI+的.可是这里为什么要讲归于GDI? 主要是基于这种考虑: 在GDI+环境中,我们能够直接使用GDI+ ,没多少必要再使用CImage类 可是,假设再 ...

  4. CImage类

    CImage封装了DIB(设备无关位图)的功能,因而可以让我们能够处理每个位图像素.这里介绍GDI+和CImage的一般使用方法和技巧. TAG: GDI  CImage  后处理   我们知道,Vi ...

  5. CImage类提供了GetBits()函数原理及实现

    CImage类提供了GetBits()函数来读取数据区,GetBits()函数返回的是图片最后一行第一个像素的地址,网上有人说返回指针的起始位置是不同的,有些图片返回的是左上角像素的地址,有些是左下角 ...

  6. c++ MFC图像处理CImage类常用操作代码

    原文作者:aircraft 原文地址:https://www.cnblogs.com/DOMLX/p/9598974.html MFC图像处理CImage类常用操作 CImage类头文件为#inclu ...

  7. 【VS开发】GDI+ 用CImage类来显示PNG、JPG等图片

    系统环境:Windows 7 软件环境:Visual Studio 2008 SP1 本次目的:实现VC单文档.对话框程序显示图片效果 CImage 是VC.NET中定义的一种MFC/ATL共享类,也 ...

  8. 一个比CBitmap更优秀的类 -- CImage类

    Visual C++的CBitmap类的功能是比较弱的,它只能显示出在资源中的图标.位图.光标以及图元文件的内容,而不像VB中的Image控件可以显示出绝大多数的外部图像文件(BMP.GIF.JPEG ...

  9. android.hardware.Camera类及其标准接口介绍

    android.hardware.Camera类及其标准接口介绍,API level 19 http://developer.android.com/reference/android/hardwar ...

随机推荐

  1. 51nod1242斐波那契数列的第N项 【矩阵快速幂】

    斐波那契数列的定义如下: F(0) = 0 F(1) = 1 F(n) = F(n - 1) + F(n - 2) (n >= 2) (1, 1, 2, 3, 5, 8, 13, 21, 34, ...

  2. [luogu2576 SCOI2010] 幸运数字 (容斥原理)

    传送门 Description 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的"幸运号码"是十进制表示中只包含数字6和8的那些号码,比如68,66 ...

  3. Tensorflow 0.8.0 安装配置方法

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51280087 折腾了一下,给工作站配置 ...

  4. 通过Sqoop实现Mysql / Oracle 与HDFS / Hbase互导数据

    通过Sqoop实现Mysql / Oracle 与HDFS / Hbase互导数据\ 下文将重点说明通过Sqoop实现Mysql与HDFS互导数据,Mysql与Hbase,Oracle与Hbase的互 ...

  5. POJ 1198/HDU 1401

    双向广搜... 呃,双向广搜一般都都用了HASH判重,这样可以更快判断两个方向是否重叠了.这道题用了双向的BFS,有效地减少了状态.但代码太长了,不写,贴一个别人的代码.. #include<i ...

  6. ps -ef与ps aux的区别

    ps -ef与ps aux的区别 学习:http://www.linuxidc.com/Linux/2016-07/133515.htm ps aux可以查看其内存使用情况:

  7. [Angular] Increasing Performance by using Pipe

    For example you make a function to get rating; getRating(score: number): string { let rating: string ...

  8. C++编程-&gt;pair(对组)

    pair 是 一种模版类型.每一个pair 能够存储两个值.这两种值无限制,能够是tuple.vector ,string,struct等等. 首先来看一下pair的函数 初始化.复制等相关操作例如以 ...

  9. jmeter函数和变量

    函数和变量广泛的应用在JMeter的传参过程,其中函数可以被认为是某种特殊的变量,它们可以被采样器或者其他测试元件所引用. 常用函数 1.__RamdomString() / __Ramdom() 获 ...

  10. 实战c++中的vector系列--vector应用之STL的find、find_if、find_end、find_first_of、find_if_not(C++11)

    使用vector容器,即避免不了进行查找,所以今天就罗列一些stl的find算法应用于vector中. find() Returns an iterator to the first element ...