实现代码:
VERSION 5.00
BeginVB.FormForm1
Caption="使用PictureBox控件实现图像放大和缩小"
ClientHeight=5580
ClientLeft=60
ClientTop=345
ClientWidth=7935
LinkTopic="Form1"
ScaleHeight=5580
ScaleWidth=7935
StartUpPosition=3'窗口缺省
BeginVB.PictureBoxPicture1
AutoRedraw=-1'True
AutoSize=-1'True
Height=3960
Left=-15
Picture="Form1.frx":0000
ScaleHeight=3900
ScaleWidth=6240
TabIndex=2
Top=15
Width=6300
End
BeginVB.CommandButtonCommand2
Caption="放大"
Height=360
Left=6540
TabIndex=1
Top=5070
Width=1140
End
BeginVB.CommandButtonCommand1
Caption="缩小"
Height=360
Left=5160
TabIndex=0
Top=5070
Width=1140
End
End
AttributeVB_Name="Form1"
AttributeVB_GlobalNameSpace=False
AttributeVB_Creatable=False
AttributeVB_PredeclaredId=True
AttributeVB_Exposed=False
DimiAsInteger
DimjAsInteger
PrivateSubCommand1_Click()
Picture1.Cls
i=i-100:j=j-100
Picture1.PaintPicturePicture1.Picture,0,0,i,j
Picture1.Width=i:Picture1.Height=j
EndSub
PrivateSubCommand2_Click()
Picture1.Cls
Picture1.Width=i:Picture1.Height=j
i=i+100:j=j+100
Picture1.PaintPicturePicture1.Picture,0,0,i,j
EndSub
PrivateSubForm_Load()
i=Picture1.Width:j=Picture1.Height
Picture1.Cls
EndSub
VB6.0通过PictureBox控件实现图片放大和图片缩小功能
扩展资料:其它方法:
例子前请先下载Gdiplus.tlb,并将其放置到C:\Windows\System32中
Gdiplus.tlb下载
VisualBasiccode
使用Gdiplus.tlb,将其放到system32中,然后添加对其的引用
手动设置Form的AutoRedraw=True,ScaleMode=Pixels
OptionExplicit
DimlngGraphicsAsLong
DimlngImageHandleAsLong
DimlngTextureBrushAsLong
DimgpPAsGpStatus
DimlngPen1AsLong
DimlngTokenAsLong
DimGpInputAsGdiplusStartupInput
PrivateSubCommand1_Click()
DimintPAsInteger
gpP=GdipCreateFromHDC(Me.hDC,lngGraphics)'创建绘图区域设备场景
gpP=GdipLoadImageFromFile(App.Path&"\启动.png",lngImageHandle)'读取图片到内存
gpP=GdipDrawImage(lngGraphics,lngImageHandle,0,0)'等大小绘制
gpP=GdipDrawImageRect(lngGraphics,lngImageHandle,200,0,300,300)'在指定的区域内绘制(放大或缩小)
gpP=GdipDrawImageRectRectI(lngGraphics,lngImageHandle,550,0,400,400,20,20,80,80,UnitPixel)'在400*400的区域内显示图片部分区域
gpP=GdipCreateTexture(lngImageHandle,WrapModeTile,lngTextureBrush)'设置一定排列方式的刷子平铺方式
gpP=GdipFillRectangle(lngGraphics,lngTextureBrush,0,300,400,300)'在指定区域内按指定的格式绘制图片
IflngGraphics<>0ThenGdipDeleteGraphicslngGraphics
IflngImageHandle<>0ThenGdipDisposeImagelngImageHandle
IflngTextureBrush<>0ThenGdipDeleteBrushlngTextureBrush
Me.Refresh
EndSub
PrivateSubForm_Load()
DimbolPAsBoolean
WithMe
.Caption="GDIPlus范例"
.Width=960*15
.Height=720*15
.Left=(Screen.Width-.Width)*0.5
.Top=(Screen.Height-.Height)*0.5
EndWith
GpInput.GdiplusVersion=1
IflngToken=0ThenbolP=(GdiplusStartup(lngToken,GpInput)=Ok)
EndSub
简单一点的方式是,在mdi主窗体内添加一个picturebox控件,然后在这个picturebox中添加一个image控件。picture1的属性:
1.align=top
2.appearance=flat
3.bordestyle=none
4.tabstop=false
image1的属性:
1.stretch=true
在mdi窗体的resize事件中添加如下代码:
private
sub
mdiform_resize()
me.picture1.height
=
me.height
end
sub
在picture1控件的resize事件中添加如下代码:
private
sub
picture1_resize()
me.image1.move
0,
0,
me.picture1.width,
me.picture1.height
end
sub
上面的代码是比较粗略的代码,至于在resize的时候picture1和image1的宽和高的精确数值可以自己调试,以便图像显示的最为完整和精确。
这个方法的缺点是,由于窗体大小可以随意调节,所以背景图形可能会变形。当然也可以考虑控制窗体大小的变化,使窗体按照图片的纵横比放大和缩小,但是相应的控制代码会增加一些。
改变图片大小,建议使用Image控件,并设置它的Stretch
属性为
True。
移动位置:就是改变控件的:Left属性和Top属性
使边框所谓的润滑,就是设置控件的BorderStyle
属性
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)