CxImage* ScaleImageBy9PNG(CxImage *pRawImage, int nDstWidth,int nDstHeight)
{
if(NULL == pRawImage) return NULL; CDC *pDC = CDC::FromHandle(::GetDC(NULL));
CDC memDC;
memDC.CreateCompatibleDC(pDC); const UINT nBMPWidth = nDstWidth;
const UINT nBMPHeight= nDstHeight;
const UINT nRawWidth = pRawImage->GetWidth();
const UINT nRawHeight = pRawImage->GetHeight(); BITMAPINFO bitmapinfo;
bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfo.bmiHeader.biBitCount = ;
bitmapinfo.bmiHeader.biHeight = nBMPHeight;
bitmapinfo.bmiHeader.biWidth = nBMPWidth;
bitmapinfo.bmiHeader.biPlanes = ;
bitmapinfo.bmiHeader.biCompression=BI_RGB;
bitmapinfo.bmiHeader.biXPelsPerMeter=;
bitmapinfo.bmiHeader.biYPelsPerMeter=;
bitmapinfo.bmiHeader.biClrUsed=;
bitmapinfo.bmiHeader.biClrImportant=;
bitmapinfo.bmiHeader.biSizeImage = bitmapinfo.bmiHeader.biWidth * bitmapinfo.bmiHeader.biHeight * bitmapinfo.bmiHeader.biBitCount / ;
HBITMAP hBitmap = ::CreateDIBSection (memDC.m_hDC,&bitmapinfo, ,NULL, , ); CxImage *newImage = new CxImage();
newImage->CreateFromHBITMAP(hBitmap);
if (hBitmap != NULL)
{
DeleteObject(hBitmap);
}
::ReleaseDC(NULL, pDC->m_hDC);
if(memDC.m_hDC) ::DeleteDC(memDC.m_hDC); int newImageHeight = newImage->GetHeight();
int newImageWidth = newImage->GetWidth();
if(FALSE == newImage->AlphaIsValid())
{
newImage->AlphaCreate();
}
if(newImageHeight > nRawHeight && newImageWidth > nRawWidth)
{
for(int iH=;iH<newImageHeight;++iH)
for(int iW=;iW<newImageWidth;++iW)
{
int rawH = iH,rawW = iW;
if(rawH >= (newImageHeight-nRawHeight/))
{
rawH = rawH - (newImageHeight - nRawHeight);
}
if(rawW >= (newImageWidth-nRawWidth/))
{
rawW = rawW - (newImageWidth - nRawWidth);
} if((iH < nRawHeight/ || iH>=(newImageHeight-nRawHeight/))&&
(iW < nRawWidth/ || iW>= (newImageWidth-nRawWidth/)))
{
//4块源
RGBQUAD argb = pRawImage->GetPixelColor(rawW,rawH,true);
newImage->SetPixelColor(iW,iH,RGB(argb.rgbRed,argb.rgbGreen,argb.rgbBlue));
newImage->AlphaSet(iW,iH,argb.rgbReserved);
}
else
{
if((iH < nRawHeight/ || iH>=(newImageHeight-nRawHeight/))&&iW->=)
{
RGBQUAD argb = newImage->GetPixelColor(iW-,iH,true);
newImage->SetPixelColor(iW,iH,RGB(argb.rgbRed,argb.rgbGreen,argb.rgbBlue));
newImage->AlphaSet(iW,iH,argb.rgbReserved);
}
else
{
if(iH - >= )
{
RGBQUAD argb = newImage->GetPixelColor(iW,iH-,true);
newImage->SetPixelColor(iW,iH,RGB(argb.rgbRed,argb.rgbGreen,argb.rgbBlue));
newImage->AlphaSet(iW,iH,argb.rgbReserved);
}
}
}
}
}
return newImage;
}

9PNG的意思就是绘制时按9块区域绘制,左上左下右上右下是源,其他是拉伸的部分。CxImage主要使用像素点的方式来进行拉伸,并且每个像素都有copy透明信息。

最新文章

  1. eclipse安装spring的插件
  2. ArcGIS将Nodata区设置为0
  3. 如何去定义一个jquery插件
  4. Android四大组件之Activity &amp; Fragement
  5. 编译x264 for ios
  6. 【LeetCode 236】Lowest Common Ancestor of a Binary Tree
  7. Activiti源码浅析:Activiti的活动授权机制
  8. windows 查看端口被占用
  9. 静态网页VS动态网页
  10. 直接插入排序、折半插入排序、Shell排序、冒泡排序,选择排序
  11. 【卷一】正则四 |&gt; 练习
  12. Spring Resource配置
  13. 无需激活直接同步登入discuz,php代码(直接可用)
  14. iOS 拨打电话三种方式
  15. c#中用lua脚本执行redis命令
  16. 安装astrixx firefox插件
  17. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验二:按键模块① - 消抖
  18. $ sudo python -m pip install pylint 出错解决方法
  19. django使用session报错:no such table: django_session
  20. @postconstruct初始化的操作(转载)

热门文章

  1. HDU 4451 容斥原理
  2. POJ 2142 TheBalance 模线性方程求解
  3. validate针对checkbox、radio、select标签的验证
  4. loginitem
  5. Oracle中的 row_number() over (partition by order by ) 用法
  6. Dalvik虚拟机总结
  7. Open Flash Chart2 常用的参数
  8. ios9--UIImageView的帧动画
  9. hibernate缓存机制详细分析(一级、二级、查询缓存,非常清晰明白)
  10. openStack Packages yum upgrade