Печать фотографий с использованием VB6 и / или .NET - PullRequest
0 голосов
/ 10 марта 2010

Есть ли у кого-нибудь предложения или примеры кода для печати фотографий (BMP, TIFF или JPEG) с использованием Visual Basic или .NET Framework?

1 Ответ

3 голосов
/ 10 марта 2010

VB6 и .NET обрабатывают печать совершенно по-разному. Эти примеры являются минимальным количеством, просто чтобы дать вам представление о процессе.

В VB6 вы управляете принтером шаг за шагом:

Private Sub PrintMyPicture()

  'Place to store my picture
  Dim myPicture As IPictureDisp
  'Load the picture into the variable
  Set myPicture = LoadPicture("C:\temp\myPictureFile.bmp")

  'Draw the picture on the printer, just off the edge of the page
  Printer.PaintPicture myPicture, 10, 10

  'Done printing!
  Printer.EndDoc
End Sub

И вот, ваша картинка выйдет из принтера по умолчанию. метод PaintPicture принимает ширину, высоту и некоторые другие параметры, чтобы помочь подогнать изображение, а объект «Принтер» предоставляет всю информацию о принтере.

В .Net все наоборот. Вы начнете печатать, и принтер будет вызывать событие для каждой страницы, пока вы не скажете ему остановиться. Каждое событие страницы дает вам в качестве графического объекта, на котором вы можете рисовать, используя все стандартные классы и методы System.Drawing:

'Class variable
Private WithEvents printer As System.Drawing.Printing.PrintDocument


' Kick off the printing process. This will cause the printer_PrintPage event chain to start firing.
Public Sub PrintMyPicture() 
'Set up the printer

    printer.PrinterSettings.PrinterName = "MyPrinterNameInPrintersAndFaxes"
    printer.Print()
End Sub

'This event will keep firing while e.HasMorePages = True.
Private Sub printer_PrintPage(ByVal sender As Object, ByVal e As  System.Drawing.Printing.PrintPageEventArgs) Handles printer.PrintPage



    'Load the picture
    Dim myPicture As System.Drawing.Image = System.Drawing.Image.FromFile("C:\temp\myPictureFile.bmp")

    'Print the Image.  'e' is the Print events that the printer provides.  In e is a graphics object on hwich you can draw.
    '10, 10 is the position to print the picture.  
     e.Graphics.DrawImage(myPicture, 10, 10)

    'Clean up
    myPicture.Dispose()
    myPicture = Nothing

    'Tell the printer that there are no more pages to print.  This will cause the document to be finalised and come out of the printer.
    e.HasMorePages = False
End Sub

Опять же, в DrawImage и объектах PrintDocument намного больше параметров.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...