デュアルディスプレイのセカンドモニターにPDF、動画、画像を表示。
@@ -29,32 +29,41 @@ | ||
29 | 29 | End Sub |
30 | 30 | |
31 | 31 | Private Sub DisplayPage() |
32 | - | |
33 | 32 | If (page >= pdfDoc.PageCount) Then |
34 | 33 | Return |
35 | 34 | End If |
36 | - Dim size = pdfDoc.PageSizes(page) | |
37 | - Dim h1 = size.Width / size.Height ' // pdfの縦横比 | |
38 | - Dim h2 = PictureBox1.Width / PictureBox1.Height ' // コントロールの縦横比 | |
39 | - If (h2 > 10) Then ' 落ちないように Then | |
35 | + Dim renderSize As Size? = GetRenderSize() | |
36 | + If renderSize Is Nothing Then | |
40 | 37 | Return |
41 | 38 | End If |
42 | - Dim Width = 0, Height = 0 | |
43 | - If (h1 < h2) Then | |
39 | + Render(renderSize) | |
40 | + End Sub | |
41 | + | |
42 | + Private Function GetRenderSize() As Size? | |
43 | + Dim renderSize = New Size(PictureBox1.Size) | |
44 | + Dim pdfSize = pdfDoc.PageSizes(page) | |
45 | + Dim pdfWdivH = pdfSize.Width / pdfSize.Height ' // pdfの縦横比 | |
46 | + Dim boxWdivH = PictureBox1.Width / PictureBox1.Height ' // コントロールの縦横比 | |
47 | + If (boxWdivH > 10) Then ' 落ちないよう | |
48 | + Return Nothing | |
49 | + End If | |
50 | + If (pdfWdivH < boxWdivH) Then | |
44 | 51 | ' フォーム内にImageを当てはめる判定 { |
45 | - Width = PictureBox1.Height * h1 | |
46 | - Height = PictureBox1.Height | |
52 | + renderSize.Width = PictureBox1.Height * pdfWdivH | |
47 | 53 | Else |
54 | + renderSize.Height = PictureBox1.Width / pdfWdivH | |
55 | + End If | |
56 | + Return renderSize | |
57 | + End Function | |
48 | 58 | |
49 | - Width = PictureBox1.Width | |
50 | - Height = PictureBox1.Width / h1 | |
51 | - End If | |
52 | - Dim img = pdfDoc.Render(page, Width, Height, 96, 96, False) ' // 解像度は意味ない? | |
59 | + Private Sub Render(renderSize As Size) | |
60 | + Dim img = pdfDoc.Render(page, renderSize.Width, renderSize.Height, 96, 96, False) ' // 解像度は意味ない? | |
53 | 61 | Dim oldImage = PictureBox1.Image |
54 | 62 | PictureBox1.Image = img |
55 | 63 | If oldImage IsNot Nothing Then |
56 | 64 | oldImage.Dispose() '; // メモリー節約 |
57 | 65 | End If |
66 | + | |
58 | 67 | End Sub |
59 | 68 | |
60 | 69 | End Class |
\ No newline at end of file |