请教一下,谁知道怎样编程控制打印机打印照片? 用 vc, python 为佳,多谢 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
hfeeki
V2EX    程序员

请教一下,谁知道怎样编程控制打印机打印照片? 用 vc, python 为佳,多谢

  •  
  •   hfeeki 2014-06-10 15:41:26 +08:00 5887 次点击
    这是一个创建于 4151 天前的主题,其中的信息可能已经有所发展或是发生改变。
    请教一下,谁知道怎样编程控制打印机打印照片? 用vc, python为佳,多谢
    操作系统是windows
    8 条回复    2014-06-11 13:22:36 +08:00
    hfeeki
        1
    hfeeki  
    OP
       2014-06-10 15:43:49 +08:00
    假设只提供一个图片文件的全路径名,怎样开发一个把图片打印出来的函数?
    mhycy
        2
    mhycy  
       2014-06-10 15:49:10 +08:00
    貌似要调用打印机驱动。。。具体非常复杂,困难,麻烦。。。。
    hfeeki
        3
    hfeeki  
    OP
       2014-06-10 16:55:40 +08:00
    貌似不是很负责、困难、麻烦。。。 我已经知道怎样做了
    librehat
        4
    librehat  
       2014-06-10 18:15:19 +08:00
    用Qt吧,有现成函数库可以打印。QPrinter
    Comdex
        5
    Comdex  
       2014-06-10 18:18:53 +08:00
    @hfeeki 请问一下楼主能分享一下吗
    loading
        6
    loading  
       2014-06-10 18:25:57 +08:00 via iPhone
    LZ 没品
    hfeeki
        7
    hfeeki  
    OP
       2014-06-10 19:24:00 +08:00
    import win32print
    import win32ui
    from PIL import Image, ImageWin

    #
    # Constants for GetDeviceCaps
    #
    #
    # HORZRES / ERTRES = printable area
    #
    HORZRES = 8
    VERTRES = 10
    #
    # LOGPIXELS = dots per inch
    #
    LOGPIXELSX = 88
    LOGPIXELSY = 90
    #
    # PHYSICALWIDTH/HEIGHT = total area
    #
    PHYSICALWIDTH = 110
    PHYSICALHEIGHT = 111
    #
    # PHYSICALOFFSETX/Y = left / top margin
    #
    PHYSICALOFFSETX = 112
    PHYSICALOFFSETY = 113

    printer_name = win32print.GetDefaultPrinter ()
    file_name = "test.jpg"

    #
    # You can only write a Device-independent bitmap
    # directly to a Windows device context; therefore
    # we need (for ease) to use the Python Imaging
    # Library to manipulate the image.
    #
    # Create a device context from a named printer
    # and assess the printable size of the paper.
    #
    hDC = win32ui.CreateDC ()
    hDC.CreatePrinterDC (printer_name)
    printable_area = hDC.GetDeviceCaps (HORZRES), hDC.GetDeviceCaps (VERTRES)
    printer_size = hDC.GetDeviceCaps (PHYSICALWIDTH), hDC.GetDeviceCaps (PHYSICALHEIGHT)
    printer_margins = hDC.GetDeviceCaps (PHYSICALOFFSETX), hDC.GetDeviceCaps (PHYSICALOFFSETY)

    #
    # Open the image, rotate it if it's wider than
    # it is high, and work out how much to multiply
    # each pixel by to get it as big as possible on
    # the page without distorting.
    #
    bmp = Image.open (file_name)
    if bmp.size[0] > bmp.size[1]:
    bmp = bmp.rotate (90)

    ratios = [1.0 * printable_area[0] / bmp.size[0], 1.0 * printable_area[1] / bmp.size[1]]
    scale = min (ratios)

    #
    # Start the print job, and draw the bitmap to
    # the printer device at the scaled size.
    #
    hDC.StartDoc (file_name)
    hDC.StartPage ()

    dib = ImageWin.Dib (bmp)
    scaled_width, scaled_height = [int (scale * i) for i in bmp.size]
    x1 = int ((printer_size[0] - scaled_width) / 2)
    y1 = int ((printer_size[1] - scaled_height) / 2)
    x2 = x1 + scaled_width
    y2 = y1 + scaled_height
    dib.draw (hDC.GetHandleOutput (), (x1, y1, x2, y2))

    hDC.EndPage ()
    hDC.EndDoc ()
    hDC.DeleteDC ()
    tywtyw2002
        8
    tywtyw2002  
       2014-06-11 13:22:36 +08:00 via iPhone
    pdflatex。 然后用cups。
    python生成一个latex脚本,运行下pdflatex编译,剩下的cmd call lpr去打印。
    没想折腾cups api。
    linux上面没问题。

    以前做过一键重排版ppt,然后打印。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2881 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 21ms UTC 00:22 PVG 08:22 LAX 17:22 JFK 20:22
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86