如何将一张小图片充满 picturebox 的背景

redsuntv 2007-12-05 05:36:36
如何将一张小图片充满 picturebox 的背景?
就是把一张小图片(宽度是1像素)做PictureBox的背景。


给源代码。谢谢!
...全文
232 点赞 收藏 13
写回复
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhh0086 2007-12-19
高手
回复
东方之珠 2007-12-14
上面这个代码,要事先在SmallPicture中加载一张小图片。

Private Sub Form_Load()
SmallPicture.Picture=LoadPicture("c:\qq.bmp")
SmallPicture.ScaleMode=3
Picture1.ScaleMode=3
End Sub
回复
东方之珠 2007-12-14
我试了一下,你9楼那个根本不行。原因是没有用像素座标,我以为你是内行,结果你没有用像素座标!
下面这个代码我已经调试过了,完全没问题。只需在Form1窗体中添加一个命令按钮Command1,2个图片框SmallPicture、Picture1:

Option Explicit

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source

Private Sub Command1_Click()
Dim i As Long, j As Long
Dim hs As Long, ws As Long, w As Long, h As Long
hs = SmallPicture.ScaleHeight
ws = SmallPicture.ScaleWidth
h = Picture1.Height
w = Picture1.Width

For i = 0 To h / hs
For j = 0 To w / ws
BitBlt Picture1.hDC, j * ws, i * hs, ws, hs, SmallPicture.hDC, 0, 0, SRCCOPY
Next
Next
End Sub

Private Sub Form_Load()
SmallPicture.ScaleMode = 3
Picture1.ScaleMode = 3
End Sub
回复
东方之珠 2007-12-14
SRCCOPY=&HCC0020
回复
redsuntv 2007-12-13
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long

Private Sub Form_Click()
Dim i As Long, j As Long
hs = SmallPicture.Height
ws = SmallPicture.Width
h = Picture1.Height
w = Picture1.Width

For i = 0 To h / hs
For j = 0 To w / ws
BitBlt Picture1.hDC, j * ws, i * hs, ws, hs, SmallPicture.hDC, 0, 0, SRCCOPY
Next
Next
End Sub


按3楼 4楼的方法根本不行.
回复
redsuntv 2007-12-13
我要的就是一楼这样的东西
感谢!
回复
tingting1123 2007-12-06
...没什么区别 1象素?楼主有没有搞错?
回复
宽度为 "1" 的图像 平铺 和 拉伸 有区别吗?
回复
东方之珠 2007-12-05
哦,错啦, BitBlt Picture1.hdc,j*ws,i*hs,w,h,SmallPicture.hdc,0,0,SRCCOPY 里面的w,h分别改为ws,hs
回复
东方之珠 2007-12-05
假设小图片框为:SmallPicture 高度为hs,宽度为ws;Picture1高度为h,宽度为w。

代码如下:
dim i as long,j as long
for i=0 to h/hs
for j=0 to w/ws
BitBlt Picture1.hdc,j*ws,i*hs,w,h,SmallPicture.hdc,0,0,SRCCOPY
next
next




回复
东方之珠 2007-12-05
楼上是将宽度1像素的图片放大充满整个图片框吧,那还看得清吗?楼上误解了楼主的意思吧!
楼主的意思是将宽度1像素的图片一张一张地铺满整个图片框!必须用API函数BitBlt才能解决!
回复
'假设背景图片是 e:\1.jpg
Dim p As New StdPicture
Set p = LoadPicture("e:\1.jpg")
Picture1.PaintPicture p, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告