PDA

View Full Version : [vb.net 2010] problemi stampa fotografica


fucfra
04-07-2013, 20:43
Buonasera a tutti, mi chiamo Francesco e sono Calabrese. Ho realizzato un progetto per un chiosco fotografico, funziona tutto tranne la stampa su una Kodak photo printer 605, se invese utilizzo una "normale"stampante ink jet tutto funzione. Il codice che utilizzo per la stampa è il seguente :

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim documento As New PrintDocument
Dim PrintDialog1 As New PrintDialog
PrintDialog1.Document = documento
'e se viene premuto il tasto "OK" la si stampa
Dim h_px As Integer = CM_15
Dim l_px As Integer = CM_20
Dim f15x20 As PaperSize = New PaperSize("15x20", l_px, h_px)
stampa10x13 = False
documento.DefaultPageSettings.PaperSize = f15x20
documento.DefaultPageSettings.Margins = New Margins(0, 0, 0, 0)
AddHandler documento.PrintPage, AddressOf PrintPage
documento.Print()
salvaResoconto(resoconto.foto10x15, lst_10x15.Items.Count)
If MsgBox("Svuotare il carrello di stampa ?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
lst_10x15.Items.Clear()
End If
'End If
End Sub

Private Sub PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
If stampa10x13 Then
stampa_lista(lst_10x13.Items(numero_foto).Text, e, numero_foto, lst_10x13.Items.Count, formato_anteprima._10x15)
Else
stampa_lista(lst_10x15.Items(numero_foto).Text, e, numero_foto, lst_10x15.Items.Count, formato_anteprima._15x20)
End If
End Sub

Private Sub stampa_lista(ByVal path As String, ByVal e As System.Drawing.Printing.PrintPageEventArgs, ByVal i As Integer, ByVal totale_stampa As Integer, ByRef tipo As formato_anteprima)

Dim immagine As Image = Image.FromFile(path)
'larghezza dell'immagine
Dim LImmagine As Integer = immagine.Width

'altezza dell'immagine
Dim HImmagine As Integer = immagine.Height
If LImmagine < HImmagine Then
immagine.RotateFlip(RotateFlipType.Rotate90FlipNone)
End If

Dim rapportoL As Double = (e.PageBounds.Width) / immagine.Width

'rapporto fra l'altezza dell'area stampabile e l'altezza dell'immagine
Dim rapportoH As Double = (e.PageBounds.Height) / immagine.Height


'posizione del vertice alto-sx dell'immagine
Dim x As Integer = 0
Dim y As Integer = 0

'Se l'immagine è più grande del foglio che deve contenerla, essa viene scalata.
'Per questo si valutano i due rapporti, rapportoL e rapportoH, e si utilizza quello di valore minore,
'poi attraverso una proporzione si scala l'immagine in modo che la relativa dimensione (larghezza per rapportoL,
'altezza per rapportH) sia uguale a quella dell'area stampabile
If (e.PageBounds.Width) < immagine.Width Or (e.PageBounds.Height) < immagine.Height Then

If rapportoL > rapportoH Then

HImmagine = CType(rapportoL * immagine.Height, Integer)
LImmagine = CType(e.PageBounds.Width, Integer)

Else

HImmagine = CType(e.PageBounds.Height, Integer)
LImmagine = CType(rapportoH * immagine.Width, Integer)

End If

End If

'centra l'immagine nel foglio
y = CType(((e.PageBounds.Height) - HImmagine) / 2, Integer)
x = CType(((e.PageBounds.Width) - LImmagine) / 2, Integer)

'si disegna l'immagine alle coordinate (x,y) e con le nuove dimensioni Limmagine e Himmagine
e.Graphics.DrawImage(immagine, x, y, LImmagine, HImmagine)

numero_foto += 1
If numero_foto < totale_stampa Then
e.HasMorePages = True
Else
e.HasMorePages = False
numero_foto = 0
End If
End Sub

Forse sbaglio qualcosa. Se possibile, aiutatemi. Grazie a tutti in anticipo.