谁会呀? 本人想要用一个Picture控件放一张照片。可是照片有大有小,怎样让这些大小不一的照片按的我控件大小等比例放大或缩小。请详细说明实现过程如有源代码那更好。[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 建议用image控件stretch属性为True 会自动适应控件大小 照你的意思最好是用image控件,Image1.Stretch = True image控件 把Image的属性Stretch 设为 True image控件 把Image的属性Stretch 设为 True image控件不会应照片太大大小也会发生改变吗? 等比例缩放是不是按照照片的大小等比例?如果简单的话就按照上面大侠们的方法吧.如果想复杂一些就可以直接使用API函数StretchBlt一个例子,放大图片同理Private Function smallPic() '将图片缩小至缩略图Dim PicErr As LongIf Picture1.Width <= Picture2.Width And Picture1.Height <= Picture2.Height Then '显示原有大小 PicErr = BitBlt(Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, SRCCOPY)Else '将图片缩小 Dim C_Width, C_Height As Integer If Picture1.Width > Picture1.Height Then '缩小宽度 '计算比例 C_Width = Picture2.ScaleWidth C_Height = C_Width * (Picture1.ScaleHeight / Picture1.ScaleWidth) Else '计算比例 C_Height = Picture2.ScaleHeight C_Width = C_Height * (Picture1.ScaleWidth / Picture1.ScaleHeight) End If PicErr = StretchBlt(Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, C_Width, C_Height, SRCCOPY)End IfEnd Function 1.用Frame做容器2.在Frame上放一个Image控件,主要要灵活运用Image的Stretch属性.载入图片前设为TRUE先获取宽和高,再FALSE设置需要的宽和高。3.与容器做比较再定位. Picture2 = LoadPicture(FileName) 'Picture1.AutoRedraw = True '判断 Picture2 图片大小,调整后,打印到 Picture1 Dim sHW1 As Single sHW1 = Picture1.Height / Picture1.Width If Picture2.Height / Picture2.Width > sHW1 Then '如果源图片高与宽比例大于需求比例,取原宽度和高度的中间区域 Picture1.PaintPicture Picture2.Picture, 0, 0, Picture1.Width, Picture1.Height, _ 0, (Picture2.Height - Picture2.Width * sHW1) / 2, Picture2.Width, Picture2.Width * sHW1 Else '否则,取宽度的中间区域和原高度 Picture1.PaintPicture Picture2.Picture, 0, 0, Picture1.Width, Picture1.Height, _ (Picture2.Width - Picture2.Height / sHW1) / 2, 0, Picture2.Height / sHW1, Picture2.Height End If Set Picture2.Picture = LoadPicture("") 【Timer控件】问题 哈哈哈,笑死我了,不小心写了个i=i++ 访问这里的速度为什么慢了?? 如何在当前目录下建立文件? 關於VB的編輯環境設定的奇怪現象 VB中的窗体是类还是对象?谢谢,立刻给分 如何判断网络是否连接正常,如何设置超时时间,如果超时,怎样捕获这个错误?急,在线!!! 两个odbc连接,如何保证其中一个事务完整性 请看看这段代码 我用Select Into 表1 From 表0 Where .... 如何的判断 ADO 是否处于活动状态? 在线等,一个打开应用程序的问题
如果简单的话就按照上面大侠们的方法吧.
如果想复杂一些就可以直接使用API函数
StretchBlt
一个例子,放大图片同理
Private Function smallPic() '将图片缩小至缩略图
Dim PicErr As Long
If Picture1.Width <= Picture2.Width And Picture1.Height <= Picture2.Height Then
'显示原有大小
PicErr = BitBlt(Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, SRCCOPY)
Else
'将图片缩小
Dim C_Width, C_Height As Integer
If Picture1.Width > Picture1.Height Then '缩小宽度
'计算比例
C_Width = Picture2.ScaleWidth
C_Height = C_Width * (Picture1.ScaleHeight / Picture1.ScaleWidth)
Else
'计算比例
C_Height = Picture2.ScaleHeight
C_Width = C_Height * (Picture1.ScaleWidth / Picture1.ScaleHeight)
End If
PicErr = StretchBlt(Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, C_Width, C_Height, SRCCOPY)
End If
End Function
2.在Frame上放一个Image控件,主要要灵活运用Image的Stretch属性.载入图片前设为TRUE先获取宽和高,再FALSE设置需要的宽和高。
3.与容器做比较再定位.
'Picture1.AutoRedraw = True '判断 Picture2 图片大小,调整后,打印到 Picture1
Dim sHW1 As Single
sHW1 = Picture1.Height / Picture1.Width
If Picture2.Height / Picture2.Width > sHW1 Then
'如果源图片高与宽比例大于需求比例,取原宽度和高度的中间区域
Picture1.PaintPicture Picture2.Picture, 0, 0, Picture1.Width, Picture1.Height, _
0, (Picture2.Height - Picture2.Width * sHW1) / 2, Picture2.Width, Picture2.Width * sHW1
Else
'否则,取宽度的中间区域和原高度
Picture1.PaintPicture Picture2.Picture, 0, 0, Picture1.Width, Picture1.Height, _
(Picture2.Width - Picture2.Height / sHW1) / 2, 0, Picture2.Height / sHW1, Picture2.Height
End If
Set Picture2.Picture = LoadPicture("")