只要將VB窗口內(nèi)的需要部分保存成圖片文件就可以了
民豐ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!
要用到API函數(shù)的:
Private Type POINTAPI
x As Long
y As Long
End Type
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 GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Sub Command1_Click()
Dim hdc As Long
Dim sw As Integer
Dim sh As Integer
Dim CurPos As POINTAPI
Dim Cur As Long
Me.Hide
DoEvents
Picture1.AutoRedraw = True
hdc = GetDC(0)
GetCursorPos CurPos
Cur = GetCursor
Picture1.Width = Screen.Width
Picture1.Height = Screen.Height
sw = Screen.Width / Screen.TwipsPerPixelX
sh = Screen.Height / Screen.TwipsPerPixelY
BitBlt Picture1.hdc, 0, 0, sw, sh, hdc, 0, 0, vbSrcCopy
Me.Show
DrawIcon Picture1.hdc, CurPos.x - 10, CurPos.y - 10, Cur
ReleaseDC 0, hdc
Picture1.AutoRedraw = False
以下放到模塊里:
Option Explicit
Type RECT_Type
left As Long
top As Long
right As Long
bottom As Long
End Type
'The following declare statements are case sensitive.
Declare Function GetActiveWindow Lib "User32" () As Long
Declare Function GetDesktopWindow Lib "User32" () As Long
Declare Sub GetWindowRect Lib "User32" (ByVal Hwnd As Long, _
lpRect As RECT_Type)
Declare Function GetDC Lib "User32" (ByVal Hwnd As Long) As Long
Declare Function CreateCompatibleDC Lib "Gdi32" (ByVal hdc As Long) _
As Long
Declare Function CreateCompatibleBitmap Lib "Gdi32" (ByVal hdc _
As Long, ByVal nWidth As Long, _
ByVal nHeight As Long) As Long
Declare Function SelectObject Lib "Gdi32" (ByVal hdc As Long, _
ByVal hObject As Long) As Long
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
Declare Function OpenClipboard Lib "User32" (ByVal Hwnd As Long) As Long
Declare Function EmptyClipboard Lib "User32" () As Long
Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, _
ByVal hMem As Long) As Long
Declare Function CloseClipboard Lib "User32" () As Long
Declare Function ReleaseDC Lib "User32" (ByVal Hwnd As Long, _
ByVal hdc As Long) As Long
Declare Function DeleteDC Lib "Gdi32" (ByVal hdc As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Global Const SRCCOPY = HCC0020
Global Const CF_BITMAP = 2
Function ScreenDump()
Dim AccessHwnd As Long, DeskHwnd As Long
Dim hdc As Long
Dim hdcMem As Long
Dim rect As RECT_Type
Dim junk As Long
Dim fwidth As Long, fheight As Long
Dim hBitmap As Long
' DoCmd.Hourglass True
'---------------------------------------------------
' Get window handle to Windows and Microsoft Access
'---------------------------------------------------
DoEvents
DeskHwnd = GetDesktopWindow()
AccessHwnd = GetActiveWindow()
'---------------------------------------------------
' Get screen coordinates of Microsoft Access
'---------------------------------------------------
Call GetWindowRect(AccessHwnd, rect)
fwidth = rect.right - rect.left
fheight = rect.bottom - rect.top
'---------------------------------------------------
' Get the device context of Desktop and allocate memory
'---------------------------------------------------
hdc = GetDC(DeskHwnd)
hdcMem = CreateCompatibleDC(hdc)
hBitmap = CreateCompatibleBitmap(hdc, fwidth, fheight)
If hBitmap 0 Then
junk = SelectObject(hdcMem, hBitmap)
'---------------------------------------------
' Copy the Desktop bitmap to memory location
' based on Microsoft Access coordinates.
'---------------------------------------------
junk = BitBlt(hdcMem, 0, 0, fwidth, fheight, hdc, rect.left, _
rect.top, SRCCOPY)
'---------------------------------------------
' Set up the Clipboard and copy bitmap
'---------------------------------------------
junk = OpenClipboard(DeskHwnd)
junk = EmptyClipboard()
junk = SetClipboardData(CF_BITMAP, hBitmap)
junk = CloseClipboard()
End If
'---------------------------------------------
' Clean up handles
'---------------------------------------------
junk = DeleteDC(hdcMem)
junk = ReleaseDC(DeskHwnd, hdc)
' DoCmd.Hourglass False
End Function
這里是拖動鼠標(biāo)的框里內(nèi)容截取,你也可以改成固定范圍的截取。
REM?假設(shè)存在Image類型變量img?
Dim?bmp?As?Bitmap?=?CType(img,?Bitmap)?'先將Image類型強(qiáng)制轉(zhuǎn)換為Bitmap類型?
bmp.Save("C:\1.png",?System.Drawing.Imaging.ImageFormat.Png)?'以PNG格式存儲到C:\1.png
Private?Sub?Button1_Click(sender?As?Object,?e?As?EventArgs)?Handles?Button1.Click
'建立新的系統(tǒng)進(jìn)程????
Dim?process?As?New?System.Diagnostics.Process()
If?RadioButton1.Checked?Then
'設(shè)置文件名,此處為圖片的真實(shí)路徑+文件名????
process.StartInfo.FileName?=?"c:\a.bmp"
'設(shè)置進(jìn)程運(yùn)行參數(shù)????
process.StartInfo.Arguments?=?"rundll32.exe?shimgvw.dll"
Else
process.StartInfo.FileName?=?"mspaint.exe"
process.StartInfo.Arguments?=?"c:\a.bmp"
End?If
'此項(xiàng)為是否使用Shell執(zhí)行程序,因系統(tǒng)默認(rèn)為true,此項(xiàng)也可不設(shè),但若設(shè)置必須為true????
'process.StartInfo.UseShellExecute?=?True
'此處可以更改進(jìn)程所打開窗體的顯示樣式,可以不設(shè)????
'process.StartInfo.WindowStyle?=?System.Diagnostics.ProcessWindowStyle.Hidden
process.Start()
process.Close()
End?Sub
用一個全局變量保存這個1.jpg,如變量a,你按按鈕2時,可以簡單的在a中插入一個"A",如a.SubString(0, a.Length-4) "A" a.SubString(a.Length-4),這樣就能把例如"C:/Images/1.jpg"變成"C:/Images/1A.jpg"
本文標(biāo)題:vb.net如何輸出圖片 vbnet printdocument
網(wǎng)站地址:http://www.muchs.cn/article22/dohiecc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、企業(yè)建站、網(wǎng)站營銷、電子商務(wù)、品牌網(wǎng)站建設(shè)、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)