19,468
社区成员
发帖
与我相关
我的任务
分享
void StretchImage( CImage &image, int width, int height, CBitmap &bitmap )
{
CImage memImage;
memImage.Create(width, height, 32);
float oriWidth = image.GetWidth(), oriHeight = image.GetHeight();
float scale = MIN(width / oriWidth, height / oriHeight);
image.Draw(memImage.GetDC(), 0, 0, oriWidth * scale, oriHeight * scale);
memImage.ReleaseDC();
HBITMAP hBitmap = memImage.Detach();
bitmap.Attach(hBitmap);
}
image.TransparentBlt(hdc, 200 + (width - scaledW) / 2, (height - scaledH) / 2, scaledW, scaledH, 0);
image.Draw(hdc, 0, 0);
image.TransparentBlt(memImage.GetDC(), (width - scaledW) / 2, (height - scaledH) / 2, scaledW, scaledH, 0);
memImage.ReleaseDC();
memImage.Draw(hdc, 200, 0);
void CImagePane::StretchImage( CImage &image, int width, int height, CBitmap &bitmap )
{
CImage memImage;
memImage.Create(width, height, 32);
float oriWidth = image.GetWidth(), oriHeight = image.GetHeight();
float scale = MIN(width / oriWidth, height / oriHeight);
float scaledW = oriWidth * scale;
float scaledH = oriHeight * scale;
image.StretchBlt(memImage.GetDC(), (width - scaledW) / 2, (height - scaledH) / 2, scaledW, scaledH);
memImage.ReleaseDC();
HBITMAP hBitmap = memImage.Detach();
bitmap.Attach(hBitmap);
}
StretchImage(image, PHY_TEMPLATE_ACTOR_ICON_SIZE, PHY_TEMPLATE_ACTOR_ICON_SIZE, bitmap);
m_imgList.Add(&bitmap, RGB(0, 0, 0));
image.TransparentBlt(memImage.GetDC(), (width - scaledW) / 2, (height - scaledH) / 2, scaledW, scaledH, 0);
最后一个参数,只要不是-1 效果都一样(默认值-1会触发assert) CImage image;
CBitmap bitmap;
image.Load("some_image.png");
StretchImage(image, PHY_TEMPLATE_ACTOR_ICON_SIZE, PHY_TEMPLATE_ACTOR_ICON_SIZE, bitmap);
m_imgList.Add(&bitmap, RGB(0, 0, 0));