怎么做到将一个jpg图片按指定的大小 输出在picturbox控件中,或是其它输出也行.

rednod 2004-12-07 10:22:56
如题了
...全文
320 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hideal 2005-01-05
  • 打赏
  • 举报
回复
Sorry,我錯了.
Hideal 2005-01-05
  • 打赏
  • 举报
回复
上樓的:
Dim p As StdPicture

Set p = LoadPicture("H:\My Documents\Img15644950.jpg")
好象不行吧.有沒測試過?
韧恒 2004-12-23
  • 打赏
  • 举报
回复
'***************************************************
' 将图片在PictureBox控件中按比例缩放后,居中显示
'***************************************************
Public Sub PictureToCenter(tPic As Picture, PicBox As PictureBox)
Dim PicH As Long, PicW As Long
Dim PicBoxW As Long, PicBoxH As Long
Dim PicRate As Single, PicBoxRate As Single
Dim NewH As Long, NewW As Long

PicBoxH = PicBox.ScaleHeight
PicBoxW = PicBox.ScaleWidth
PicBoxRate = PicBoxW / PicBoxH

PicW = ScaleX(tPic.Width, vbHimetric, PicBox.ScaleMode)
PicH = ScaleY(tPic.Height, vbHimetric, PicBox.ScaleMode)
PicRate = PicW / PicH

PicBox.Cls
If PicH <= PicBoxH And PicW <= PicBoxW Then
PicBox.PaintPicture tPic, (PicBoxW - PicW) / 2, (PicBoxH - PicH) / 2
Exit Sub
End If
If PicBoxRate < PicRate Then
NewH = PicBoxW / PicRate
PicBox.PaintPicture tPic, 0, (PicBoxH - NewH) / 2, PicBoxW, NewH
Else
NewW = PicBoxH * PicRate
PicBox.PaintPicture tPic, (PicBoxW - NewW) / 2, 0, NewW, PicBoxH
End If
End Sub

'这个过程是我在工程中使用的,可以适应任何比例的图片
Private Sub Picture1_Click()
Dim p As StdPicture

Set p = LoadPicture("H:\My Documents\Img15644950.jpg")
PictureToCenter p, Picture1
End Sub
aohan 2004-12-21
  • 打赏
  • 举报
回复
顶了
chelseawu 2004-12-21
  • 打赏
  • 举报
回复
這個要學一下﹐收藏﹗
wfhlxl 2004-12-08
  • 打赏
  • 举报
回复
picture.paintpicture stdpicture,x1,y1,width,height
AprilSong 2004-12-07
  • 打赏
  • 举报
回复
用PaintPicture就够了~

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Me.PaintPicture LoadPicture("0.gif"), 0, 0, X, Y

End Sub
78777675 2004-12-07
  • 打赏
  • 举报
回复
你也可以放一个image控件在picturbox里,控制他们的大小就可以了
laviewpbt 2004-12-07
  • 打赏
  • 举报
回复
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long

Private Sub Command1_Click()
'利用picture2作为缓冲
Picture2.Picture = LoadPicture("F:\pictures\sniper\awp_a.jpg")
StretchBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, vbSrcCopy
Picture1.Refresh
End Sub

Private Sub Form_Load()
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
Picture2.AutoSize = True
Picture2.Visible = False
End Sub
78777675 2004-12-07
  • 打赏
  • 举报
回复
picturbox不行 使用image控件,strech属性设为为true
aiur2000 2004-12-07
  • 打赏
  • 举报
回复
使用image控件,strech为true
Andy__Huang 2004-12-07
  • 打赏
  • 举报
回复
Dim ZX As Single, ZY As Single
Dim i As Integer, j As Integer

With Image1
.Stretch = False
.Visible = False
.Picture = LoadPicture("\\SWEB\datafile\photo\employee\24115.jpg")
ZX = .Width / 3000 '假設目標寬度155圖元
ZY = .Height / 3500 '假設目標高度165圖元

.Stretch = True
.Height = Int(.Height / ZY)
.Width = Int(.Width / ZX)
End With
wwqna 2004-12-07
  • 打赏
  • 举报
回复
LoadPicture([filename], [size], [colordepth],[x,y]) ,直接用这个函数就行了
熊孩子开学喽 2004-12-07
  • 打赏
  • 举报
回复
方法1:使用IMAGE控件加载,设置Stretch属性为True,再调整IMAGE控件的大小

方法2:使用PICTURE控件加载,再用PaintPicture方法将图像缩放到指定大小。

方法3:使用PICTURE控件加载,在使用StretchBlt这个API来将图像缩放到指定大小。
homezj 2004-12-07
  • 打赏
  • 举报
回复
两种方案:
1、完全用VB,如 AprilSong(X)介绍的PaintPicture法,
2、完全用API,不建议VB与API混用,问题倒没什么,只是感觉:要速度没速度,要节源也没节源,两头都靠不上,没必要如此。虽然,VB自带的示例中也是混用的,但我还是坚持这个观点。
laviewpbt(人一定要靠自己)说的StretchBlt法,用Picture2做缓冲,就是VB与API混用绘图,为了一个图片就加上个PictureBox,的确浪费,资源不能释放不说,而且PictureBox是耗源大户,还是越少越好。这样用API,还不如直接用PaintPicture。

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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