代码如下:
| int i,i1,dx,dy,pixelwidth,pixelheight,xz,yz,div,mode,diff uint hdc,hpicture,hback ulong scrcopy,hmdc,hmdc1 string picname,picname1,back div=8 mode=16 p_1.picturename="" picname=trim(sle_3.text) //sle_3.text中为正面图片的文件名 picname1=trim(sle_4.text) //sle_4.text中为背面图片的文件名 back=trim(sle_2.text) //sle_2.text中为背景图片的文件名 scrcopy=13369376 pixelwidth=UnitsToPixels(p_1.width,XUnitsToPixels!) pixelheight=UnitsToPixels(p_1.height,yUnitsToPixels!) dx=pixelwidth/div dy=pixelheight/div hdc=GetDC(handle(p_1)) hpicture=LoadImageA(0,picname,0,pixelwidth,pixelheight,mode)// 装入正面图片 hmdc=CreateCompatibleDC(hdc) SelectObject(hmdc,hpicture) diff=dx/2 for i=0 to div hback=LoadImageA(0,back,0,pixelwidth,pixelheight,mode)//装入背景图片 hmdc1=CreateCompatibleDC(hdc) SelectObject(hmdc1,hback) StretchBlt(hmdc1,diff*i,0,pixelwidth,diff*i*2,pixelheight,hmdc,0,0,pixelwidth,pixelheight, scrcopy)//将正面图片与背景图片在背景图片DC中进行"复制"操作 BitBlt(hdc,0,0,pixelwidth,pixelheight,hmdc1,0,0, scrcopy)//将hmdc1中的合成图片转移到picture控件的hdc中 DeleteDC(hmdc1) DeleteObject(hback) for i1=1 to 15000 next next DeleteDC(hmdc) DeleteObject(hpicture) hpicture=LoadImageA(0,picname1,0,pixelwidth,pixelheight,mode)// 装入背面图片 hmdc=CreateCompatibleDC(hdc) SelectObject(hmdc,hpicture) for i=div to 0 step -1 hback=LoadImageA(0,back,0,pixelwidth,pixelheight,mode) hmdc1=CreateCompatibleDC(hdc) SelectObject(hmdc1,hback) StretchBlt(hmdc1,diff*i,0,pixelwidth,diff*i*2,pixelheight,hmdc,0,0,pixelwidth,pixelheight, scrcopy) //将背面图片与背景图片在背景图片Dc中进行"与复制"操作 BitBlt(hdc,0,0,pixelwidth,pixelheight,hmdc1,0,0, scrcopy) //将hmdc1中的合成图片转移到picture控件的hdc中 DeleteDC(hmdc1) DeleteObject(hback) for i1=1 to 15000 next next DeleteDC(hmdc) DeleteObject(hpicture) ReleaseDC(0,hdc) p_1.picturename=picname1 |
五、结束语
通过上述方法,我们实现了图片变换时的动画特效,为程序增色不少。
以上代码在powerbuilder6.0 for windows98下调试通过。