vb在红色图片上打字,结果在红色的图片上打字的背景上出现白色小方块,怪难看的。请问如何解决?谢谢

解决方案 »

  1.   

    不用api也可以,先说说你怎么打字的吧,及控件的设置
      

  2.   

    我先把图片打印    Call PrintHead
    再在图片imgHead中心加字,当然字会变的。是从txtCustomer里取出来的
    Private Sub PrintHead()
        PrintPic imgHead, 0, lngPOSiITION_NowY 
        PrintFont Int_CONST_X * 4, lngPOSiITION_NowY + imgHead.Height * 0.8, frmCoil.txtCustomer, 16
        PrintFont Int_CONST_X * 25.8, lngPOSiITION_NowY + imgHead.Height * 0.8, frmCoil.txtPlace, 16
    End Sub'打印文字,同时预览和打印
    Private Sub PrintFont(ByVal X As Integer, ByVal Y As Long, ByVal strPrint, ByVal intSize As Integer) 
        If intPrintOrView = 1 Then ‘预览
            picPrint.CurrentX = intLeftStartX + X
            picPrint.CurrentY = Y
            picPrint.Font.Size = intSize
            picPrint.Print strPrint
        Else ’打印
            Printer.CurrentX = intLeftStartX + X
            Printer.CurrentY = Y
            Printer.Font.Size = intSize
            Printer.Print strPrint
        End If
    End Sub'打印图片,同时预览和打印
    Private Sub PrintPic(ByVal ImgObject As Object, ByVal X As Integer, ByVal Y As Long)
        If intPrintOrView = 1 Then
            picPrint.PaintPicture ImgObject.Picture, intLeftStartX + X, Y, ImgObject.Width, ImgObject.Height
        Else
            Printer.PaintPicture ImgObject.Picture, intLeftStartX + X, Y, ImgObject.Width, ImgObject.Height
        End If
    End Sub我不知道有没有说清楚。
    在pictrue控件上打印是正常的,但是打印机打出来后,就rt所说了
      

  3.   

    无须用API,请试下列代码:
    Option Explicit
    Dim xx, yy As Integer
    Dim fnt As Long
    Dim txt As String
    Dim colvb As String
    Dim wp As VariantPublic Function xp(colvb As Variant, xx As Variant, yy As Variant, fnt As Variant, txt As Variant)
    Picture1.ForeColor = colvb 'QBColor(14)
    Picture1.CurrentX = xx
    Picture1.CurrentY = yy
    Picture1.FontSize = fnt
    Picture1.Print txt '
    End FunctionPrivate Sub Form_Load()
    Picture1.AutoRedraw = True
    xx = 500
    yy = 500
    fnt = 24
    colvb = vbRed
    txt = "这是VB对PICTURE图片框的图片上写字的演示"
    wp = xp(colvb, xx, yy, fnt, txt)
    xx = 500
    yy = 2500
    fnt = 48
    colvb = vbGreen
    txt = "字号调大的演示"
    wp = xp(colvb, xx, yy, fnt, txt)
    End Sub
      

  4.   

    用API保存图片,然后通过画图板打开图片后打印:
    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
        Dim xx, yy As Integer
        Dim fnt As Long
        Dim txt As String
        Dim colvb As String
        Dim wp As VariantPublic Function xp(colvb As Variant, xx As Variant, yy As Variant, fnt As Variant, txt As Variant)
        Picture1.ForeColor = colvb 'QBColor(14)
        Picture1.CurrentX = xx
        Picture1.CurrentY = yy
        Picture1.FontSize = fnt
        Picture1.Print txt '
    End FunctionPrivate Sub Form_Load()
        Picture1.AutoRedraw = True
        xx = 500
        yy = 500
        fnt = 24
        colvb = vbRed
        txt = "这是VB对PICTURE图片框的图片上写字的演示"
        wp = xp(colvb, xx, yy, fnt, txt)
        xx = 500
        yy = 2500
        fnt = 48
        colvb = vbGreen
        txt = "字号调大的演示"
        wp = xp(colvb, xx, yy, fnt, txt)
    End Sub
    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
      

  5.   

    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
    Dim xx, yy As Integer
    Dim fnt As Long
    Dim txt As String
    Dim colvb As String
    Dim wp As VariantPublic Function xp(colvb As Variant, xx As Variant, yy As Variant, fnt As Variant, txt As Variant)
    Picture1.ForeColor = colvb 'QBColor(14)
    Picture1.CurrentX = xx
    Picture1.CurrentY = yy
    Picture1.FontSize = fnt
    Picture1.Print txt '
    End FunctionPrivate Sub Command1_Click() '打印图片
        Picture1.Width = Picture1.Width
        Picture1.Height = Picture1.Height
        Picture1.AutoRedraw = True
        BitBlt Picture1.hDC, 0, 0, Picture1.Width / Screen.TwipsPerPixelX, Picture1.Height / Screen.TwipsPerPixelY, Picture1.hDC, 0, 0, SRCCOPY
        Picture1.AutoRedraw = False
        Picture1.Refresh
        Printer.PaintPicture Picture1.Image, 1000, 1000
        Printer.EndDoc
    End Sub
    Private Sub Form_Load()
    Picture1.AutoRedraw = True
    xx = 500
    yy = 500
    fnt = 24
    colvb = vbBlue
    txt = "这是VB对PICTURE图片框的图片上写字的演示"
    wp = xp(colvb, xx, yy, fnt, txt)
    xx = 500
    yy = 2500
    fnt = 48
    colvb = vbGreen
    txt = "字号调大的演示"
    wp = xp(colvb, xx, yy, fnt, txt)
    End Sub
      

  6.   

    要看楼主用的是什么控件了,如果是TEXT,那么你可以把TEXT的BACKCOLOR属性也改成红色.如果用的是LABEL控件,只要把LABEL的BACKSTYLE属性改成0-TRANSPARENT.
      

  7.   

    疯了  发错了  楼主抱歉......一般简单的  同意  YAKEEBZYC复杂的  再用你说那个长代码就好
      

  8.   

    楼上的没关系的,我已经有老婆了,不用谢我,呵呵
    to:人一定靠自己和rainstormmaster(暴风雨 v2.0)两位大哥:
        SetBkMode Printer.hdc, TRANSPARENT '=1
        SetBkMode Printer.hdc, OPAQUE '=2
    都不行?why?thks