当前位置:首页 > 代码 > 正文

vb打印照片代码(vb打印图形程序是什么)

admin 发布:2022-12-19 16:34 177


今天给各位分享vb打印照片代码的知识,其中也会对vb打印图形程序是什么进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

vb6.0 打印picturebox

这实现要分两步走:

步骤一)先要将含各种控件的Picturebox图像保存为图片。

步骤二)用画图板软件打印或编辑VB程序加载图片打印。

提供步骤一的代码:

Option Explicit

    Private Const BI_RGB = 0

    Private Const DIB_RGB_COLORS = 0

    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 CmdSave_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

如何用VB将图片输出到打印机上打印?

给你个思路吧:

1、把电脑图片加载到picturebox1 上,picturebox1的autosize 设置为auto。这样,picturebox1的高度和宽度就是原图的高和宽。

2、判断picturebox1的宽度和高度,这样就可以和A4知的宽高比较了。

3、再用一个picturebox2,用StretchBlt把picturebox1上图按比例缩小画到picturebox2

4、打印picturebox2。

求一个VB图片打印功能代码

最简单的办法,

打开一个新窗口,

在上面画个image

载入图片到image控件

调整窗口和image控件大小一样

然后用form1.printform打印窗口就行了

求"打印"的VB代码!

是本人关于数据库查询输出的代码,可供参考:

VB下数据报表打印输出方法有多种,一是通过自己的设计和编程完成报表打印输出。二是通过MS OFFICE实现报表打印输出。三是应用数据报表设计器的报表打印输出。本人经常使用第一种方法,它具有根据需要灵活应用的特点,但需编写程序。下附代码,第一段代码定义基本变量,第二段代码定义打印函数,第三段代码是具体打印代码,含数据转换。第四段代码是窗体加载代码,具体连接数据库和打印代码根据你所涉及的数据要求进行修改。

Option Explicit

Private n As Integer

Private m As Integer

Private zh_dm(10) As Double

Private dy_dm(3000, 10) As Variant

Private zsl As Integer

Private y As Integer

Private x As Integer

Private i As Integer

Private k As Integer

Private p As Integer

Private pa As Integer

Private j As Integer

Private txt As String

Private fnt As Integer

Private dd As Variant

'打印文字函数

Public Function prnt(x As Variant, y As Variant, fnt As Variant, txt0 As Variant)

Printer.CurrentX = x

Printer.CurrentY = y

Printer.FontSize = fnt

Printer.Print txt0

End Function

Private Sub cmdPrint_Click()

Adodc1.Recordset.MoveFirst

For i = 0 To zsl - 1

For j = 0 To 7

dy_dm(i, j) = Adodc1.Recordset(j)

Next j

Adodc1.Recordset.MoveNext

Next i

'确定页数

k = Int(zsl / 80)'80为每页行数

If k - zsl / 80 0 Then

k = k + 1

End If

fnt = 8

For p = 0 To k - 1

pa = p + 1

y = 300

x = 4500

txt = "机物料库存"

dd = prnt(x, y, fnt, txt)

x = 8500

txt = "第" p + 1 "页"

dd = prnt(x, y, fnt, txt)

y = 500

x = 600

txt = "备件代码"

dd = prnt(x, y, fnt, txt)

x = 1500

txt = "备件名称"

dd = prnt(x, y, fnt, txt)

x = 3500

txt = "备件规格"

dd = prnt(x, y, fnt, txt)

x = 5500

txt = "进口计算机号"

dd = prnt(x, y, fnt, txt)

x = 7500

txt = "最低储备量"

dd = prnt(x, y, fnt, txt)

x = 9000

txt = "库存量"

dd = prnt(x, y, fnt, txt)

For i = 0 + p * 80 To 79 + p * 80

y = 700 + 180 * (i - p * 80)

x = 600

txt = dy_dm(i, 1)

dd = prnt(x, y, fnt, txt)

x = 1500

txt = dy_dm(i, 2)

dd = prnt(x, y, fnt, txt)

x = 3500

txt = dy_dm(i, 3)

dd = prnt(x, y, fnt, txt)

x = 5500

txt = dy_dm(i, 4)

dd = prnt(x, y, fnt, txt)

x = 7500

txt = dy_dm(i, 5)

dd = prnt(x, y, fnt, txt)

x = 9000

txt = dy_dm(i, 6)

dd = prnt(x, y, fnt, txt)

'打印分隔线条

If Int(i / 10) - i / 10 = 0 Then

Printer.Line (500, 695 + (i - p * 80) * 180)-(10000, 695 + (i - p * 80) * 180)

End If

Next i

If zsl - p * 80 80 Then

Printer.Line (500, 695 + 180 * 80)-(10000, 695 + 180 * 80)

Printer.NewPage

End If

Next p

Printer.EndDoc ' 打印完成。

Cls

End Sub

'查询代码

Private Sub Form_Load()

Adodc1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=jwl_dbf"

Adodc1.RecordSource = "select cs.js_dm,cs.备件代码,cs.备件名称,cs.备件规格,cs.进口计算机号,cs.最低库存量,sl.结存数量,sl.结存金额,sl.结存单价,sl.类别代码 from JWCK_BM as cs,jwl_jiec as sl" _

" where cs.备件代码 = sl.备件代码" " and cs.备件代码" "''" " order by sl.类别代码,sl.备件代码"

Adodc1.Refresh

DataGrid1.Refresh

zsl = Adodc1.Recordset.RecordCount

Adodc3.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=jwl_dbf"

Adodc3.RecordSource = "select sum(结存金额) as hj from jwl_jiec"

Adodc3.Refresh

End Sub

以上供参考。其它请参考西安交通大学出版社出版的“VISUAL BASIC 6.0 高级编程技巧-ADO数据访问篇“

vb怎么调用WINDOWS的照片打印向导

1、vb6里可以用Printer对象的PaintPicture 方法实现打印picturebox里的图片。 2、vb6示例: Private Sub Form_DblClick()'实现打印图像到打印机Printer.PaintPicture Picture1.Picture, 0, 0Printer.EndDocEnd Sub

如何用VB打印数据库中的图片

1、在窗体中用Picture 控件做为数据库中图片字段的呈现控件

Picture.DataSource =数据控件 (如:Data)

Picture.DataField =字段名

2、直接打印图片

Printer.PaintPicture Picture, 0, 0

Printer.EndDoc

这样就直接打印出图片了

Printer.PaintPicture 命令参数可以自己设置,确定图片的打印位置(x,y坐标)及图片是否缩放...

关于vb打印照片代码和vb打印图形程序是什么的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/13285.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载