如何将一张小图片充满 picturebox 的背景
如何将一张小图片充满 picturebox 的背景?就是把一张小图片(宽度是1像素)做PictureBox的背景。
给源代码。谢谢! --------------------编程问答-------------------- '假设背景图片是 e:\1.jpg
Dim p As New StdPicture
Set p = LoadPicture("e:\1.jpg")
Picture1.PaintPicture p, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight --------------------编程问答-------------------- 楼上是将宽度1像素的图片放大充满整个图片框吧,那还看得清吗?楼上误解了楼主的意思吧!
楼主的意思是将宽度1像素的图片一张一张地铺满整个图片框!必须用API函数BitBlt才能解决! --------------------编程问答-------------------- 假设小图片框为: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
--------------------编程问答-------------------- 哦,错啦, BitBlt Picture1.hdc,j*ws,i*hs,w,h,SmallPicture.hdc,0,0,SRCCOPY 里面的w,h分别改为ws,hs
--------------------编程问答-------------------- 宽度为 "1" 的图像 平铺 和 拉伸 有区别吗? --------------------编程问答-------------------- ...没什么区别 1象素?楼主有没有搞错? --------------------编程问答-------------------- --------------------编程问答-------------------- 我要的就是一楼这样的东西
感谢! --------------------编程问答-------------------- 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楼的方法根本不行. --------------------编程问答-------------------- SRCCOPY=&HCC0020 --------------------编程问答-------------------- 我试了一下,你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
--------------------编程问答-------------------- 上面这个代码,要事先在SmallPicture中加载一张小图片。
Private Sub Form_Load()
SmallPicture.Picture=LoadPicture("c:\qq.bmp")
SmallPicture.ScaleMode=3
Picture1.ScaleMode=3
End Sub
--------------------编程问答-------------------- 高手
补充:VB , 基础类