Public Class Form1 Dim arData() As Byte Structure RGB Dim r As Long Dim g As Long Dim b As Long Dim r_6bit As Long Dim g_6bit As Long Dim b_6bit As Long End Structure Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click OpnFileDlg.InitialDirectory = "C:\" If OpnFileDlg.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim fs As New FileStream(OpnFileDlg.FileName, FileMode.Open) Dim binRD As BinaryReader TextBox1.Text = OpnFileDlg.FileName ' 入力用のストリームを準備 ' 読み込み用の配列を準備 ' 大きさを決定 ReDim arData(fs.Length - 1) binRD = New BinaryReader(fs) ' データの読込み binRD.Read(arData, 0, arData.Length) binRD.Close() fs.Close() End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i, j, k As Integer Dim Byte_table() As Integer = {1, 2, 4} Dim Bit_shift() As Long = {1, 256, 65536, 16777216} Dim BiWidth As Long Dim BiHeight As Long Dim offset As Integer = 18 Dim File_max_byte As Long Dim BiBitCount As Integer Dim Byte_cnt As Integer Dim One_col As Long Dim count, cnt, temp As Long Dim rgb_data() As RGB Dim x_sled As Integer = 1 Dim y_sled As Integer = 1 With SaveFileDialog1 .Filter = "Cファイル|*.c" .FileName = "" .InitialDirectory = "C:\" End With If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) Else MsgBox("ファイル名を指定してください") Exit Sub End If 'ヘッダ情報の取得 File_max_byte = arData.Length For j = 0 To 3 BiWidth += arData(offset + j) * Bit_shift(j) Next offset = offset + j For j = 0 To 3 BiHeight += arData(offset + j) * Bit_shift(j) Next offset = offset + j + 2 For j = 0 To 1 BiBitCount += arData(offset + j) * Bit_shift(j) Next If BiBitCount >= 8 Then Byte_cnt = BiBitCount / 8 'ビットをバイトに変換:8bitmap以上に対応させる End If One_col = Byte_cnt * BiWidth One_col += One_col Mod 4 '1行あたりのバイト数算出 4の倍数でない場合補正する count = File_max_byte y_sled = BiHeight / 96 '縦・横を300円液晶のフレーム数圧縮させる x_sled = BiWidth / 400 cnt = 0 temp = 0 For j = 1 To BiHeight Step 1 * y_sled '現状は24bitmapのみ対応 For i = count - One_col To count - 3 Step 3 * x_sled ReDim Preserve rgb_data(cnt) rgb_data(cnt).r = arData(i + 0) rgb_data(cnt).r_6bit = 63 * rgb_data(cnt).r / 256 '1ピクセル24bitデータを6bitデータへ変換 rgb_data(cnt).g = arData(i + 1) rgb_data(cnt).g_6bit = 63 * rgb_data(cnt).g / 256 rgb_data(cnt).b = arData(i + 2) rgb_data(cnt).b_6bit = 63 * rgb_data(cnt).b / 256 cnt += 1 Next count = count - One_col If count = 54 Then Exit For End If temp += 1 Next '以下ファイル処理 Cソースファイルへ作成する '二次元配列に画像データを代入する PrintLine(1, "struct rgb vrom[96][400] = {") For i = 0 To cnt - 1 If i Mod 400 = 0 Then If i <> 0 Then PrintLine(1, "}") PrintLine(1, ",") PrintLine(1, "{") Else PrintLine(1, "{") End If End If PrintLine(1, "{" & rgb_data(i).r_6bit & "," & rgb_data(i).g_6bit & "," & rgb_data(i).b_6bit & "},") Next PrintLine(1, "}") PrintLine(1, "};") FileClose(1) End Sub End Class