VB中保存图片框中内容
在VB中要怎么保存图片框中的内容,不单单是保存用LINE等函数的内容,还包括图片框中的控件都要保存成一个BMP图片,要怎么样实现?鲸无敌朋友,我试过了,还是不行。保存出来...
在VB中要怎么保存图片框中的内容,不单单是保存用LINE等函数的内容,还包括图片框中的控件都要保存成一个BMP图片,要怎么样实现?
鲸无敌朋友,我试过了,还是不行。
保存出来的效果是这样的:https://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/leman/abpic/item/f57b36d1b552e83a9a50277f.jpg
但我想要的是:
https://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/leman/abpic/item/da7054e7afad7e2cb838207f.jpg
里面那些数字是用文本框显示的。 展开
鲸无敌朋友,我试过了,还是不行。
保存出来的效果是这样的:https://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/leman/abpic/item/f57b36d1b552e83a9a50277f.jpg
但我想要的是:
https://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/leman/abpic/item/da7054e7afad7e2cb838207f.jpg
里面那些数字是用文本框显示的。 展开
展开全部
在我的电脑上测试是成功的,不知道你那里怎么回事。你先新建一个工程来测试代码,等测试好后再放入你的程序中
按Command1按钮保存Picture1区域的图片:
Option Explicit
Private Const BI_RGB = 0&
Private Const DIB_RGB_COLORS = 0 ' color table in RGBs
Private Const BITMAPTYPE = &H4D42
Private Const INVALID_HANDLE_VALUE = (-1)
Private Const GENERIC_WRITE = &H40000000
Private Const CREATE_ALWAYS = 2
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Private Type BITMAPFILEHEADER
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) 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 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 Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Command1_Click()
Dim hmemDC As Long
Dim hmemBMP As Long
Dim lpmemBits As Long
Dim bmp_info As BITMAPINFO
Dim hFile As Long
Dim bmpfile_info As BITMAPFILEHEADER
Dim lpBytesWritten As Long
Picture1.ScaleMode = vbPixels
With bmp_info.bmiHeader
.biSize = LenB(bmp_info.bmiHeader)
.biWidth = Picture1.ScaleWidth
.biHeight = Picture1.ScaleHeight
.biPlanes = 1
.biBitCount = 24
.biCompression = BI_RGB
.biSizeImage = .biHeight * (((.biWidth * .biBitCount + 31) And &HFFFFFFE0) \ 8)
End With
hmemDC = CreateCompatibleDC(Picture1.hdc)
hmemBMP = CreateDIBSection(Picture1.hdc, bmp_info, DIB_RGB_COLORS, lpmemBits, 0, 0)
SelectObject hmemDC, hmemBMP
BitBlt hmemDC, 0, 0, bmp_info.bmiHeader.biWidth, bmp_info.bmiHeader.biHeight, Picture1.hdc, 0, 0, vbSrcCopy
hFile = CreateFile(App.Path & "\test.bmp", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
If hFile <> INVALID_HANDLE_VALUE Then
With bmpfile_info
.bfType = BITMAPTYPE
.bfOffBits = 14 + bmp_info.bmiHeader.biSize
.bfSize = .bfOffBits + bmp_info.bmiHeader.biSizeImage
End With
WriteFile hFile, bmpfile_info.bfType, 2, lpBytesWritten, 0
WriteFile hFile, bmpfile_info.bfSize, 12, lpBytesWritten, 0
WriteFile hFile, bmp_info.bmiHeader, bmp_info.bmiHeader.biSize, lpBytesWritten, 0
WriteFile hFile, ByVal lpmemBits, bmp_info.bmiHeader.biSizeImage, lpBytesWritten, 0
CloseHandle hFile
End If
DeleteObject hmemBMP
DeleteDC hmemDC
End Sub
按Command1按钮保存Picture1区域的图片:
Option Explicit
Private Const BI_RGB = 0&
Private Const DIB_RGB_COLORS = 0 ' color table in RGBs
Private Const BITMAPTYPE = &H4D42
Private Const INVALID_HANDLE_VALUE = (-1)
Private Const GENERIC_WRITE = &H40000000
Private Const CREATE_ALWAYS = 2
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Private Type BITMAPFILEHEADER
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) 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 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 Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Command1_Click()
Dim hmemDC As Long
Dim hmemBMP As Long
Dim lpmemBits As Long
Dim bmp_info As BITMAPINFO
Dim hFile As Long
Dim bmpfile_info As BITMAPFILEHEADER
Dim lpBytesWritten As Long
Picture1.ScaleMode = vbPixels
With bmp_info.bmiHeader
.biSize = LenB(bmp_info.bmiHeader)
.biWidth = Picture1.ScaleWidth
.biHeight = Picture1.ScaleHeight
.biPlanes = 1
.biBitCount = 24
.biCompression = BI_RGB
.biSizeImage = .biHeight * (((.biWidth * .biBitCount + 31) And &HFFFFFFE0) \ 8)
End With
hmemDC = CreateCompatibleDC(Picture1.hdc)
hmemBMP = CreateDIBSection(Picture1.hdc, bmp_info, DIB_RGB_COLORS, lpmemBits, 0, 0)
SelectObject hmemDC, hmemBMP
BitBlt hmemDC, 0, 0, bmp_info.bmiHeader.biWidth, bmp_info.bmiHeader.biHeight, Picture1.hdc, 0, 0, vbSrcCopy
hFile = CreateFile(App.Path & "\test.bmp", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
If hFile <> INVALID_HANDLE_VALUE Then
With bmpfile_info
.bfType = BITMAPTYPE
.bfOffBits = 14 + bmp_info.bmiHeader.biSize
.bfSize = .bfOffBits + bmp_info.bmiHeader.biSizeImage
End With
WriteFile hFile, bmpfile_info.bfType, 2, lpBytesWritten, 0
WriteFile hFile, bmpfile_info.bfSize, 12, lpBytesWritten, 0
WriteFile hFile, bmp_info.bmiHeader, bmp_info.bmiHeader.biSize, lpBytesWritten, 0
WriteFile hFile, ByVal lpmemBits, bmp_info.bmiHeader.biSizeImage, lpBytesWritten, 0
CloseHandle hFile
End If
DeleteObject hmemBMP
DeleteDC hmemDC
End Sub
展开全部
Private Sub Command1_Click()
CommonDialog1.DefaultExt = ".BMP"
CommonDialog1.Filter = "Bitmap Image (*.bmp)|*.bmp"
CommonDialog1.ShowSave
If CommonDialog1.FileName <> "" Then
SavePicture Picture1.Picture, CommonDialog1.FileName
End If
End Sub
CommonDialog1.DefaultExt = ".BMP"
CommonDialog1.Filter = "Bitmap Image (*.bmp)|*.bmp"
CommonDialog1.ShowSave
If CommonDialog1.FileName <> "" Then
SavePicture Picture1.Picture, CommonDialog1.FileName
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询