圧縮フォルダを解凍する。画像が複数含まれるので分割する。フォルダごとにpdfに変換
@@ -3,6 +3,7 @@ | ||
3 | 3 | Imports iTextSharp.text |
4 | 4 | Imports WindowsApp1 |
5 | 5 | |
6 | + | |
6 | 7 | Public Class Form1 |
7 | 8 | |
8 | 9 | Private Class Form1Logger |
@@ -40,24 +41,46 @@ | ||
40 | 41 | End Using |
41 | 42 | End Using |
42 | 43 | End Sub |
44 | + Dim filename_count = 1 | |
45 | + Private Sub SaveTo(ByVal image As Bitmap, ByVal temppath As String) | |
46 | + Dim filepath = Path.Combine(temppath, String.Format("{0:D4}.jpg", filename_count)) | |
47 | + image.Save(filepath, Imaging.ImageFormat.Jpeg) | |
48 | + End Sub | |
43 | 49 | |
44 | 50 | |
45 | - | |
46 | 51 | Private Sub zipToPdf(zipFilePath As String, srcFiles As AppTempDir, tempFiles As AppTempDir) |
47 | 52 | |
48 | 53 | '解凍処理 |
49 | 54 | System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, srcFiles.Path) |
50 | 55 | |
51 | - Dim filename_count = 0 | |
56 | + filename_count = 1 | |
52 | 57 | 'tempフォルダのjpegファイルを列挙し以下を繰り返す |
53 | 58 | Dim files As String() = System.IO.Directory.GetFiles(srcFiles.Path, "*.jpg", System.IO.SearchOption.AllDirectories) |
54 | 59 | For Each filepath As String In files |
55 | 60 | Dim filename = System.IO.Path.GetFileName(filepath) |
56 | - '先頭ファイルはそのままとする。001.jpeg | |
61 | + '先頭ファイルはそのままとする。001.jpg | |
57 | 62 | If filename.Contains("001") Then |
58 | - Dim destfilepath = Path.Combine(tempFiles.Path, filename) | |
59 | - File.Copy(filepath, destfilepath) | |
63 | + Dim image As New Bitmap(filepath) | |
64 | + SaveTo(image, tempFiles.Path) | |
65 | + '左側画像を保存する。 | |
66 | + Else | |
67 | + Dim image As New Bitmap(filepath) | |
68 | + Dim width As Integer = image.Width / 2 | |
69 | + Dim height As Integer = image.Height | |
70 | + Dim desRect As New Drawing.Rectangle(0, 0, width, height) | |
71 | + Dim destImage As New Bitmap(width, height) | |
72 | + Dim g = Graphics.FromImage(destImage) | |
73 | + '右側画像を保存する。 | |
74 | + Dim srcRect As New Drawing.Rectangle(width, 0, width, height) | |
75 | + g.DrawImage(image, desRect, srcRect, GraphicsUnit.Pixel) | |
76 | + SaveTo(destImage, tempFiles.Path) | |
77 | + '左側画像を保存する。 | |
78 | + filename_count += 1 | |
79 | + Dim srcRect2 As New Drawing.Rectangle(0, 0, width, height) | |
80 | + g.DrawImage(image, desRect, srcRect2, GraphicsUnit.Pixel) | |
81 | + SaveTo(destImage, tempFiles.Path) | |
60 | 82 | End If |
83 | + filename_count += 1 | |
61 | 84 | Next |
62 | 85 | '2番目以降のファイルを読み込む。 |
63 | 86 | '2つに分割し右側をfilename_count.jpeg,左側をfilename_count+1.jpegとして保存する |