我觉得关于这个问题没有必要用算法。如果你不要用算法也可以用的 话,我到是可以提供给你一个方法。
把两个图片的TRANSPARENT设为TRUE;
然后让两个图片的左上角的坐标一致,也就是LEFT和TOP坐标一样。
然后用COPYRECT拷贝那一个区域就可以了。
把两个图片的TRANSPARENT设为TRUE;
然后让两个图片的左上角的坐标一致,也就是LEFT和TOP坐标一样。
然后用COPYRECT拷贝那一个区域就可以了。
解决方案 »
- 在Delphi7中如何使用apd组件拨号并播放wav?
- 已经得到了一个外部程式的进程ID,我怎么样得到窗体类名为Edit的窗体句柄?
- 请问各位大虾,如何实现象csdn小助手登录类型的小程序(100分不够再加)
- 如何解决动态库不兼容(delphi 编写的动态库,参数是string型的,我用C++调用是老异常,请高人指点)
- 如何操作只读属性的文件?
- 各位過來看看﹕ 一個很有挑戰性的SQL排序語句﹗急-----Waiting online!!
- 怎样获得窗口客户区的大小?
- 动态生成数据库表?@@@ select?
- 怎么设置Form使其运行不随鼠标调整大小。谢谢
- 国家计算机等级考试是程序员考试吗?有程序员考试吗?什么时候?如何报名?有什么要求?
- 如何控制一个字段值唯一呢?
- 如何取得Database的登陆密码?(小Case了,希不吝赐教)
COPYRECT可以吗?
1.TansparentColor: 透明色;
2.PixelFormat:指明每一象点颜色所占的二进位数;
pf16bit: 点2字节;
pf24bit: 3字节;
pf32bit: 4字节;
3.ScanLine[行号];每一行象素缓冲的首址,即数组
的首址,每一象点占连续字节;有了上面的3个属性,就可以写出合成2幅图象的算法; 算法:
for 第0行 到 最后一行
for 第0列 TO 最后一列
begin
1.取第一幅一个象点c1;
2.取第二幅一个象点c2;
3.如果c1是透明色,c3:=c2;
如果c2是透明色,c3:=c1;
4.送c3
end
通过算法设置出象photoshop里一幅图象在另一幅图象上如何透明地显示,
并且可以设置透明度,如50%的透明度。并不是单幅图象的透明性。
关键在于象BCB提示的begin语句中第3段如何实现?
请各位高手指点,谢谢。
for 第0行 到 最后一行
for 第0列 TO 最后一列
begin
1.取第一幅一个像点c1的R色 c1R;
2.取第二幅一个像点c2的R色 c2R;
3.新像点的R色 cR := (c1R*K+c2R*(1-K)); 4.取第一幅一个像点c1的G色 c1G;
5.取第二幅一个像点c2的G色 c2G;
6.新像点的G色 cG := (c1G*K+c2G*(1-K)); 7.取第一幅一个像点c1的B色 c1B;
8.取第二幅一个像点c2的B色 c2B;
9.新像点的B色 cB := (c1B*K+c2B*(1-K)); 10.新像点的RGB色 cRGB := RGB(cR,cG,cB); end
其中 K 是2个图合并时,第一幅图的全重。改变这个 K 值可以得到一个渐变的效果。
我也希望有更快的算法(我的程序中也有个地方要用这个,现在只好换成另一个效果了),我想,不同算法的结果应该是一样的(类似我给出的算法的结果。呵呵)。
Windows2000中有个API函数是修改窗体的透明度,好象叫什么α效果(记不太清楚了),速度比较快,PhotoShop中的透明度调整效果也很快。这应该是个标准的图象算法。
http://www.applevb.com/sourcecode/halftran.zip
CBitmap &cBitmap=m_bmpDraw;
CBitmap* pOldMemBmp = NULL;
COLORREF col,colMask;
CRect cRect;
int x, y;
CRgn wndRgn, rgnTemp; GetWindowRect(&cRect);
CPoint ptOrg=cRect.TopLeft(); BITMAP bmInfo;
cBitmap.GetObject(sizeof(bmInfo),&bmInfo);
CRect rcNewWnd=CRect(ptOrg,CSize(bmInfo.bmWidth,bmInfo.bmHeight)); memDC.CreateCompatibleDC(pDC);
pOldMemBmp = memDC.SelectObject(&cBitmap);
colMask=memDC.GetPixel(0,0); wndRgn.CreateRectRgn(0, 0, rcNewWnd.Width(), rcNewWnd.Height());
for(x=0; x<=rcNewWnd.Width(); x++)
{
for(y=0; y<=rcNewWnd.Height(); y++)
{
col = memDC.GetPixel(x, y);
if(col == colMask)
{
rgnTemp.CreateRectRgn(x, y, x+1, y+1);
wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_XOR);
rgnTemp.DeleteObject();
}
}
}
if (pOldMemBmp) memDC.SelectObject(pOldMemBmp);
SetWindowRgn((HRGN)wndRgn, TRUE);
MoveWindow(rcNewWnd);
nononono的方法是可行的,但是使用了太多的乘法,还要用到浮点,在16位位图游戏编程中,大家通常使用这样的方法来进行Alpha混合:
1先分色并移位
2进行混色:(混色深度为32,足够了)
DestColor= (RscColor-DestColor)*Alpha_Depth〉〉5+DestColor;(R.G.B分别计算)
3最后合色
欢迎到我的业余游戏制作主页看看,上面有相关的文章:http://calfsoft.51.net
我的Email:[email protected]
当然如果你特别需要实现特定透明度的话,我认为LingWeiTao and APIer的方式是最好的了.
[email protected]
如果你要做动画, 速度重要.当然要利用硬件加速了. 通用的MS 平台当然是DIRECT X了.算法一样,但速度不凡. & :-)
如:如果是按32级,A图的权重 K = n/32,则B图的权重 = (32-n)/32,
可以得到这样的算法: cR := (c1R*n+c2R*(32-n));
再对cR右移4位。
这样的算法要快很多。
http://www.applevb.com/art/alphablend.txt
介绍利用AlphaBlend函数实现的透明混合
这个问题其实很简单:如果你是在Windows98以上系统下工作,那么可以用
Windows GDI的一个函数实现:AlphaBlend,函数说明就在下面,(请参考最新的MSDN)==========================================================================
Platform SDK: Windows GDI
AlphaBlend
The AlphaBlend function displays bitmaps that have transparent or semitransparent pixels.BOOL AlphaBlend(
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of upper-left corner
int nYOriginDest, // y-coord of upper-left corner
int nWidthDest, // destination width
int nHeightDest, // destination height
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of upper-left corner
int nYOriginSrc, // y-coord of upper-left corner
int nWidthSrc, // source width
int nHeightSrc, // source height
BLENDFUNCTION blendFunction // alpha-blending function
);
Parameter
hdcDest
[in] Handle to the destination device context.
nXOriginDest
[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nYOriginDest
[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nWidthDest
[in] Specifies the width, in logical units, of the destination rectangle.
nHeightDest
[in] Specifies the height, in logical units, of the destination rectangle.
hdcSrc
[in] Handle to the source device context.
nXOriginSrc
[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the source rectangle.
nYOriginSrc
[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the source rectangle.
nWidthSrc
[in] Specifies the width, in logical units, of the source rectangle.
nHeightSrc
[in] Specifies the height, in logical units, of the source rectangle.
blendFunction
[in] Specifies the alpha-blending function for source and destination bitmaps, a global alpha value to be applied to the entire source bitmap, and format information for the source bitmap. The source and destination blend functions are currently limited to AC_SRC_OVER. See the BLENDFUNCTION and EMRALPHABLEND structures.
Return Values
If the function succeeds, the return value is TRUE.If the function fails, the return value is FALSE. Windows NT/ 2000: To get extended error information, call GetLastError. This can return the following value.Value Meaning
ERROR_INVALID_PARAMETER One or more of the input parameters is invalid.
Res
If the source rectangle and destination rectangle are not the same size, the source bitmap is stretched to match the destination rectangle. If the SetStretchBltMode function is used, the iStretchMode value is automatically converted to COLORONCOLOR for this function (that is, BLACKONWHITE, WHITEONBLACK, and HALFTONE are changed to COLORONCOLOR). The destination coordinates are transformed by using the transformation currently specified for the destination device context. The source coordinates are transformed by using the transformation currently specified for the source device context. An error occurs (and the function returns FALSE) if the source device context identifies an enhanced metafile device context. If destination and source bitmaps do not have the same color format, AlphaBlend converts the source bitmap to match the destination bitmap. AlphaBlend does not support mirroring. If either the width or height of the source or destination is negative, this call will fail. If the source and destination are the same surface—that is, they are both the screen or the same memory bitmap—and the source and destination rectangles overlap, an error occurs and the function returns FALSE. The source rectangle must lie completely within the source surface, otherwise an error occurs and the function returns FALSE.AlphaBlend fails if the width or height of the source or destination is negative.Note The SourceConstantaAlpha member of BLENDFUNCTION specifies an alpha transparancy value to be used on the entire source bitmap. The SourceConstantAlpha value is combined with any per-pixel alpha values. If SourceConstantAlpha is 0, it is assumed that the image is transparent. Set the SourceConstantAlpha value to 255 (which indicates that the image is opaque) when you only want to use per-pixel alpha values. Requirements
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 98.
Header: Declared in Wingdi.h; include Windows.h.
Library: Included as a resource in Msimg32.dll.See Also
Bitmaps Overview, Bitmap Functions Built on Thursday, May 11, 2000Requirements
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 98.
Header: Declared in Wingdi.h; include Windows.h.
Library: Included as a resource in Msimg32.dll.
See Also
Bitmaps Overview, Bitmap Functions
====================================================================
Platform SDK: Windows GDI
BLENDFUNCTION
The BLENDFUNCTION structure controls blending by specifying the blending functions for source and destination bitmaps. typedef struct _BLENDFUNCTION {
BYTE BlendOp;
BYTE BlendFlags;
BYTE SourceConstantAlpha;
BYTE AlphaFormat;
}BLENDFUNCTION, *PBLENDFUNCTION, *LPBLENDFUNCTION;
Members
BlendOp
Specifies the source blend operation. Currently, the only source and destination blend operation that has been defined is AC_SRC_OVER. For details, see the following Res section.
BlendFlags
Must be zero.
SourceConstantAlpha
Specifies an alpha transparency value to be used on the entire source bitmap. The SourceConstantAlpha value is combined with any per-pixel alpha values in the source bitmap. If you set SourceConstantAlpha to 0, it is assumed that your image is transparent. Set the SourceConstantAlpha value to 255 (opaque) when you only want to use per-pixel alpha values.
AlphaFormat
This member controls the way the source and destination bitmaps are interpreted. AlphaFormat has the following value. Value Meaning
AC_SRC_ALPHA This flag is set when the bitmap has an Alpha channel (that is, per-pixel alpha). Note that the APIs use premultiplied alpha, which means that the red, green and blue channel values in the bitmap must be premultiplied with the alpha channel value. For example, if the alpha channel value is x, the red, green and blue channels must be multiplied by x and divided by 0xff prior to the call.
Res
When the AlphaFormat parameter is AC_SRC_ALPHA, the source bitmap must be 32 bpp. If it is not, the AlphaBlend function will fail. When the BlendOp parameter is AC_SRC_OVER , the source bitmap is placed over the destination bitmap based on the alpha values of the source pixels. If the source bitmap has no per-pixel alpha value, the blend is based on the SourceConstantAlpha value, as shown in the following table.Dst.Red
= Src.Red
* SourceConstantAlpha + (1 - SourceConstantAlpha) * Dst.Red
Dst.Green
= Src.Green
* SourceConstantAlpha + (1 - SourceConstantAlpha) * Dst.Green
Dst.Blue
= Src.Blue
* SourceConstantAlpha + (1 - SourceConstantAlpha) * Dst.Blue
If the source bitmap has per-pixel alpha and the SourceConstantAlpha is not used (that is, it equals 0xff), the blend is based on the per-pixel alpha, as shown in the following table.Dst.Red
= Src.Red
+ (1 - Src.Alpha) * Dst.Red
Dst.Green
= Src.Green
+ (1 - Src.Alpha) * Dst.Green
Dst.Blue
= Src.Blue
+ (1 - Src.Alpha) * Dst.Blue
If the destination bitmap has an alpha channel, then: Dest.alpha
= Src.Alpha
+ (1 - SrcAlpha) * Dst.Alpha
If the source has per-pixel alpha and the SourceConstantAlpha is used (that is, it is not 0xff), the source is pre-multiplied by the SourceConstantAlpha and then the blend is based on the per-pixel alpha. The following tables show this.Src.Red
= Src.Red
* SourceConstantAlpha;
Src.Green
= Src.Green
* SourceConstantAlpha;
Src.Blue
= Src.Blue
* SourceConstantAlpha;
Src.Alpha
= Src.Alpha
* SourceConstantAlpha;
Dst.Red
= Src.Red
+ (1 - Src.Alpha) * Dst.Red
Dst.Green
= Src.Green
+ (1 - Src.Alpha) * Dst.Green
Dst.Blue
= Src.Blue
+ (1 - Src.Alpha) * Dst.Blue
Dst.Alpha
= Src.Alpha
+ (1 - Src.Alpha) * Dst.Alpha
Requirements
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 98.
Header: Declared in Wingdi.h; include Windows.h.See Also
Bitmaps Overview, Bitmap Structures, AlphaBlend Built on Thursday, May 11, 2000Requirements
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 98.
Header: Declared in Wingdi.h; include Windows.h.
See Also
Bitmaps Overview, Bitmap Structures, AlphaBlend