在pb程序中如何控制图片的翻转浏览?API有类似的函数吗?

starcloudmountain 2006-02-21 08:20:23
在pb程序中如何控制图片的翻转浏览?API有类似的函数吗?
...全文
227 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
starcloudmountain 2006-02-22
  • 打赏
  • 举报
回复
代码

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中为正面图片的文件名
picname="F:\temp\pb\jpeg\code\nwlogo.bmp";
//picname1=trim(sle_4.text) //sle_4.text中为背面图片的文件名
picname1="F:\temp\pb\jpeg\code\setup.bmp";
//back=trim(sle_2.text) //sle_2.text中为背景图片的文件名
back="F:\temp\pb\jpeg\code\SCN00891A.bmp"


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)//这个地方返回0值,hdc是非0值。以下均是。
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中进行"复制"操作
StretchBlt(hmdc1,diff*i,pixelwidth,diff*i*2,pixelheight,hmdc,0,0,pixelwidth,pixelheight,scrcopy)
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中进行"与复制"操作
StretchBlt(hmdc1,diff*i,pixelwidth,diff*i*2,pixelheight,hmdc,0,0,pixelwidth,pixelheight,scrcopy)
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
WorldMobile 2006-02-21
  • 打赏
  • 举报
回复
笔者设计的动画特效包括图片的逐渐放大和图片的翻转两大功能。

  我们在窗口上放一个tab控件,在tab控件上分图象放大与图象翻转两个tab标签页。

  在图象放大tab标签页,有一单行编辑器〔显示选择图片的路径与名称〕、一个picture控件、一个选择图片按钮〔用于选择显示的图片〕,另外就是从左上向右下、从左下向右上、从右上向左下、从右下向左上、从左向右、从右向左、从上向下、从下向上、从中央向四周九个功能按钮。

  在图片翻转tab标签页上,有三个单行编辑器〔显示选择的背景图片、正面图片、背面图片的路径与名称〕、一个选择背景图片按钮、一个选择正面图片按钮、一个选择背面图片按钮、一个picture控件、一个翻转按钮。

  在这里假定窗口上picture控件的宽为width,高为height。

  1. 图片逐渐放大

  将要显示的图片从小到大依次延迟复制到picture控件中,直到占据整个控件为止。

  以从左上角向右下角放大为例:先将要显示的图片放入内存DC(设备环境)中,再依次延时将尺寸为1/8 width *1/8 height,2/8 width *2/8 height,3/8 width *3/8 height,4/8 width *4/8 height,5/8 width *5/8 height,6/8 width *6/8 height,7/8 width *7/8 height,整个控件大小的8幅图片复制到picture控件DC中即可。代码如下:

int i,i1,dx,dy,pixelwidth,pixelheight,xz,yz,div,mode
uint hdc,hpicture
ulong scrcopy,hmdc
string picname
div=8//图片描绘的次数
mode=16//代表从指定的文件装入图片
p_2.picturename=""
picname=trim(sle_1.text)//sle_1.text中为要显示的图片的文件名
scrcopy=13369376//代表图片转移时的操作方式为覆盖
pixelwidth=UnitsToPixels(p_2.width,XUnitsToPixels!)//将picture控件在pb下的宽度转换为以象素为单位的宽度
pixelheight=UnitsToPixels(p_2.height,yUnitsToPixels!)// 将picture控件在pb下的高度转换为以象素为单位的高度
dx=pixelwidth/div
dy=pixelheight/div
hdc=GetDC(handle(p_2))//取得p_2控件的DC
hpicture=LoadImageA(0,picname,0,pixelwidth,pixelheight,mode)//将图片以宽度pixelwidth高度pixelheight的尺寸装入内存
hmdc=CreateCompatibleDC(hdc)//创建与hdc兼容的内存设备描述表hmdc
SelectObject(hmdc,hpicture)//将位图对象选入hmdc
for i=1 to div
xz=0
yz=0
StretchBlt(hdc,xz,yz,dx*i,dy*i,hmdc,0,0,pixelwidth,pixelheight,scrcopy)//将左上角坐标为〔0,0〕,宽度为pixelwidth,高度为pixelheight的hmdc的图象转移到左上角坐标为〔xz,yz〕宽度为dx*I, 高度为dy*I的hdc中
for i1=1 to 20000//用于延迟时间
next
next
ReleaseDC(0,hdc)
DeleteDC(hmdc)
DeleteObject(hpicture)

p_2.picturename=picname//注意此句可防止点击图片时,图象从picture控件中消失

  其它几种放大方式与此类似,只要注意改变源设备描述表中图象的左上角的坐标、高度、宽度即可。限于篇幅,在此省略。

  2. 图片翻转特效

  1)将背景图片放入内存DC(hmdc)中,正面图片放入内存DC(hmdc1)中,依次将正面图片以大小为整个控件、7/8 width *7/8 height,6/8 width *6/8 height,5/8 width *5/8 height,4/8 width*4/8 height,3/8 width *3/8 height,2/8 width *2/8 height,1/8 width *1/8 height、零尺寸覆盖到存放背景图片的hmdc中,再从hmdc中复制到picture控件DC中。

  2) 将背景图片放入内存DC(hmdc)中,背面图片放入内存DC(hmdc1)中,依次将背面图片以大小为零、1/8 width *1/8 height,2/8 width *2/8 height,3/8 width *3/8 height,4/8 width *4/8 height,5/8 width *5/8 height,6/8 width *6/8 height,7/8 width *7/8 height,整个控件的尺寸覆盖到存放背景图片的hmdc中,再从hmdc中复制到picture控件DC中。

  代码如下:

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下调试通过。
starcloudmountain 2006-02-21
  • 打赏
  • 举报
回复
请教如何实现?谢谢
WorldMobile 2006-02-21
  • 打赏
  • 举报
回复
PB本身没有提供这个功能,但API函数可以实现
WorldMobile 2006-02-21
  • 打赏
  • 举报
回复
你的hdc对不对?

代码应该没有问题

可能和你写的代码有问题,建议仔细查对
starcloudmountain 2006-02-21
  • 打赏
  • 举报
回复
以上代码已试过,但是编译运行后看不出任何效果。我用的是pb9 for winXp。我在调试执行的时候发现CreateCompatibleDC(hdc)总返回0值,这是否正常?还会有其他原因吗?

681

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder API 调用
社区管理员
  • API 调用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧