java png 叠加,如何叠加两个png?

hi all:-)

I have the following question:

I have two CBitMap objects, which represent 2 .png-Files.

Now i want to overlay them the following way, where the 2nd cbitmap is over the first Bitmap:

if a pixel of the 2nd cbitmap is white, i want to display the pixel of the first cbitmap. if it is not white, i want to display the pixel of the 2nd cbitmap.

Is this possible to achieve?

I tried it with the Alphablend() function, where i set the alpha-value of the white pixels of the 2nd cbitmap to zero.

Always, only the second png is displayed...

Any ideas?

Thanks for any help!

[edit]

Here is my code, for future visitors:void PngImage::DrawOverlayedBitmap(CBitmap* pBitmapUnder, CBitmap* pBitmapUpper, CWnd* pWnd, CPoint Offset)

{

//get bitmap information

BITMAP bmpInfo;

pBitmapUnder->GetObject(sizeof(bmpInfo), &bmpInfo);

//get size

CSize size;

size.cx = bmpInfo.bmWidth;

size.cy = bmpInfo.bmHeight;

//get window's client device context

CClientDC* pDC = new CClientDC(pWnd);

//create memory device context

CDC* memDC = new CDC; memDC->CreateCompatibleDC(pDC);

//buffer bitmap

CBitmap* old = memDC->SelectObject(pBitmapUnder);

//copy bitmap bits

pDC->BitBlt

(

Offset.x,//specifies the x-coordinate (in logical units) of the upper-left corner of the destination rectangle

Offset.y,//specifies the y-coordinate (in logical units) of the upper-left corner of the destination rectangle

size.cx,//specifies the width (in logical units) of the destination rectangle

size.cy,//specifies the height (in logical units) of the destination rectangle

memDC,//specifies the source device context

0,//specifies the x-coordinate (in logical units) of the upper-left corner of the source rectangle

0,//specifies the x-coordinate (in logical units) of the upper-left corner of the source rectangle

SRCCOPY//specifies the raster operation to be performed

);

//reselect first bitmap

memDC->SelectObject(pBitmapUpper);

//copy bitmap bits

pDC->BitBlt

(

Offset.x,//specifies the x-coordinate (in logical units) of the upper-left corner of the destination rectangle

Offset.y,//specifies the y-coordinate (in logical units) of the upper-left corner of the destination rectangle

size.cx,//specifies the width (in logical units) of the destination rectangle

size.cy,//specifies the height (in logical units) of the destination rectangle

memDC,//specifies the source device context

0,//specifies the x-coordinate (in logical units) of the upper-left corner of the source rectangle

0,//specifies the x-coordinate (in logical units) of the upper-left corner of the source rectangle

SRCAND//specifies the raster operation to be performed

);

//delete device context and reset pointer

delete memDC; memDC = 0;

//delete device context and reset pointer

delete pDC; pDC = 0;

}

[/edit]

解决方案

You should load your first image into a DC then load the second into a memory DC, and then blit the second one into the first, using the appropriate operation code as described in https://msdn.microsoft.com/en-us/library/windows/desktop/dd183370%28v=vs.85%29.aspx[^].

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值