图片问题----------------------------------急!

feiqinfeiwhw 2005-09-26 09:51:57
1、用API生成规定大小的图片
2、用API把指定区域的图片复制到另一个图片的指定区域
3、将窗体上的布局生成一个图片



...全文
262 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
kmlxk0 2005-09-27
  • 打赏
  • 举报
回复
Public Function Screen2Picture(ByVal hDCSrc As Long, ByVal _
LeftSrc As Long, ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc _
As Long) As Picture
Dim hDCMemory As Long
Dim hBmp As Long
Dim hBmpPrev As Long
Dim r As Long
Dim hPal As Long
Dim hPalPrev As Long
Dim RasterCapsScrn As Long
Dim HasPaletteScrn As Long
Dim PaletteSizeScrn As Long
Dim LogPal As LOGPALETTE
hDCMemory = CreateCompatibleDC(hDCSrc)
hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
hBmpPrev = SelectObject(hDCMemory, hBmp)
'获得屏幕属性
RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS)
HasPaletteScrn = RasterCapsScrn And RC_PALETTE
PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE)
'如果屏幕对象有调色板则获得屏幕调色板
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
'建立屏幕调色板的拷贝
LogPal.palVersion = &H300
LogPal.palNumEntries = 256
r = GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
hPal = CreatePalette(LogPal)
'将新建立的调色板选如建立的内存绘图句柄中
hPalPrev = SelectPalette(hDCMemory, hPal, 0)
r = RealizePalette(hDCMemory)
End If
'拷贝图像
r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, vbSrcCopy)
hBmp = SelectObject(hDCMemory, hBmpPrev)
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
hPal = SelectPalette(hDCMemory, hPalPrev, 0)
End If
'释放资源
r = DeleteDC(hDCMemory)
r = ReleaseDC(hWndSrc, hDCSrc)
'//////////////Function CreateBitmapPicture(ByVal hBmp As Long, ByVal hPal As Long) As Picture
Dim Pic As PicBmp
Dim IPic As IPicture
Dim IID_IDispatch As GUID
IID_IDispatch.Data1 = &H20400
IID_IDispatch.Data4(0) = &HC0
IID_IDispatch.Data4(7) = &H46
Pic.Size = Len(Pic) ' Pic结构长度
Pic.Type = vbPicTypeBitmap ' 图像类型
Pic.hBmp = hBmp ' 位图句柄
Pic.hPal = hPal ' 调色板句柄
Call OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic) '建立Picture图像
Set Screen2Picture = IPic '返回Picture对象
End Function


kmlxk0 2005-09-27
  • 打赏
  • 举报
回复
Private Type PALETTEENTRY
peRed As Byte
peGreen As Byte
peBlue As Byte
peFlags As Byte
End Type
Private Type LOGPALETTE
palVersion As Integer
palNumEntries As Integer
palPalEntry(255) As PALETTEENTRY
End Type
' Private Type GUID
' Data1 As Long
' Data2 As Integer
' Data3 As Integer
' Data4(7) As Byte
' End Type
Private Const RASTERCAPS As Long = 38
Private Const RC_PALETTE As Long = &H100
Private Const SIZEPALETTE As Long = 104
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Long, _
ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Long, ByVal iCapabilitiy As Long) As Long
Private Declare Function GetSystemPaletteEntries Lib "GDI32" (ByVal hDC As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries _
As PALETTEENTRY) As Long
Private Declare Function CreatePalette Lib "GDI32" (lpLogPalette As LOGPALETTE) _
As Long
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Long, ByVal hObject _
As Long) As Long
Private Declare Function BitBlt Lib "GDI32" (ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hDCSrc As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Long) As Long
Private Declare Function SelectPalette Lib "GDI32" (ByVal hDC As Long, ByVal hPalette _
As Long, ByVal bForceBackground As Long) As Long
Private Declare Function RealizePalette Lib "GDI32" (ByVal hDC As Long) As Long
Private Declare Function GetWindowDC Lib "USER32" (ByVal hWnd As Long) As Long
Private Declare Function GetDC Lib "USER32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "USER32" (ByVal hWnd As Long, ByVal hDC As _
Long) As Long
Private Type PicBmp
Size As Long
Type As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
'Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As _
PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
feiqinfeiwhw 2005-09-27
  • 打赏
  • 举报
回复
hdhai9451(新新人类):你是先把它放入Image控件中,可是我不要这样的
我要全部通过代码实现!
feiqinfeiwhw 2005-09-27
  • 打赏
  • 举报
回复
各位帮忙啦
西雀 2005-09-26
  • 打赏
  • 举报
回复
API不是代码吗:--(
Andy__Huang 2005-09-26
  • 打赏
  • 举报
回复
用代碼完成的

Private Sub Command1_Click()
Dim ZX As Single
Dim ZY As Single
With Image1
.Stretch = False
.Visible = False
.Picture = LoadPicture("D:\PrintPhoto\Image\24115.jpg")
ZX = .Width / 3000 '°²³]¥Ø¼Ð¼e«×155¹Ï¤¸
ZY = .Height / 3500 '°²³]¥Ø¼Ð°ª«×165¹Ï¤¸

If ZX > ZY Then
ZY = ZX
Else
ZX = ZY
End If
.Stretch = True
.Height = Int(.Height / ZY)
.Width = Int(.Width / ZX)

.Visible = True
End With

End Sub
Andy__Huang 2005-09-26
  • 打赏
  • 举报
回复
用API生成规定大小的图片
------------------------------

用API做不會?用代碼完成還會一些

northwolves 2005-09-26
  • 打赏
  • 举报
回复
paintpicture ,bitbilt

1,486

社区成员

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

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