CxImage实现9PNG
2024-08-30 23:59:42
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透明信息。
最新文章
- eclipse安装spring的插件
- ArcGIS将Nodata区设置为0
- 如何去定义一个jquery插件
- Android四大组件之Activity &; Fragement
- 编译x264 for ios
- 【LeetCode 236】Lowest Common Ancestor of a Binary Tree
- Activiti源码浅析:Activiti的活动授权机制
- windows 查看端口被占用
- 静态网页VS动态网页
- 直接插入排序、折半插入排序、Shell排序、冒泡排序,选择排序
- 【卷一】正则四 |>; 练习
- Spring Resource配置
- 无需激活直接同步登入discuz,php代码(直接可用)
- iOS 拨打电话三种方式
- c#中用lua脚本执行redis命令
- 安装astrixx firefox插件
- 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验二:按键模块① - 消抖
- $ sudo python -m pip install pylint 出错解决方法
- django使用session报错:no such table: django_session
- @postconstruct初始化的操作(转载)
热门文章
- HDU 4451 容斥原理
- POJ 2142 TheBalance 模线性方程求解
- validate针对checkbox、radio、select标签的验证
- loginitem
- Oracle中的 row_number() over (partition by order by ) 用法
- Dalvik虚拟机总结
- Open Flash Chart2 常用的参数
- ios9--UIImageView的帧动画
- hibernate缓存机制详细分析(一级、二级、查询缓存,非常清晰明白)
- openStack Packages yum upgrade