PDA

View Full Version : پرینت تصاویر



a.1397
چهارشنبه 23 بهمن 1398, 14:21 عصر
دوستان یه سری عکس داخل یه فولدر دارم که میخام با یه کیلیک همه عکسارو پرینت بگیرم. بدون اینکه بازشون کنم. اول پنجره تنظیمات پرینتر باز بشه که کاربر پرینتر و تنظیمات رو انتخاب کنه بعد عکسا پشت سرهم پرینت بشن

the king
چهارشنبه 23 بهمن 1398, 15:29 عصر
دوستان یه سری عکس داخل یه فولدر دارم که میخام با یه کیلیک همه عکسارو پرینت بگیرم. بدون اینکه بازشون کنم. اول پنجره تنظیمات پرینتر باز بشه که کاربر پرینتر و تنظیمات رو انتخاب کنه بعد عکسا پشت سرهم پرینت بشن

عکسی که باز نشه پرینت نمیشه. برای پرینت شدن باید محتویات فایل خونده بشه و بصورت تصویر در بیاد.

Imports System.Drawing.Drawing2D
Imports System.Drawing.Printing
Imports System.IO

Public Class Form1

Private ReadOnly _files As New List(Of String)
Private _fileIndex As Integer
Private WithEvents _document As New PrintDocument

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using browserDlg As New FolderBrowserDialog
If browserDlg.ShowDialog(Me) <> DialogResult.OK Then Exit Sub
Dim files = Directory.GetFiles(browserDlg.SelectedPath)
_files.Clear()
For Each file In files
Select Case Path.GetExtension(file).ToLowerInvariant()
Case ".jpg", ".jpe", ".jpeg", ".png", ".bmp", ".gif"
_files.Add(file)
End Select
Next
If _files.Count = 0 Then Exit Sub
End Using
Using printDlg As New PrintDialog
printDlg.UseEXDialog = True
printDlg.Document = _document
If printDlg.ShowDialog(Me) <> DialogResult.OK Then Exit Sub
_fileIndex = 0
_document.Print()
End Using
End Sub

Private Sub _document_PrintPage(sender As Object, e As PrintPageEventArgs) Handles _document.PrintPage
Using stream = File.OpenRead(_files(_fileIndex))
Using img = Image.FromStream(stream)
e.Graphics.PageUnit = GraphicsUnit.Display
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor
e.Graphics.DrawImage(img, e.MarginBounds)
End Using
_fileIndex += 1
e.HasMorePages = _fileIndex < _files.Count
End Using
End Sub
End Class