回答編集履歴
6
誤り訂正
answer
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
allBytes = allBytes.Concat(buf)
|
25
25
|
last12Bytes = allBytes.Skip(allBytes.Length - 12).Take(12)
|
26
26
|
End While
|
27
|
-
fs.Write(allBytes, 0,
|
27
|
+
fs.Write(allBytes, 0, allBytes.Length)
|
28
28
|
End Sub
|
29
29
|
|
30
30
|
'IENDチャンクが来たらファイル終わり
|
5
誤り訂正
answer
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
Dim buf(SerialPort1.BytesToRead) As Byte
|
23
23
|
SerialPort1.Read(buf, 0, SerialPort1.BytesToRead)
|
24
24
|
allBytes = allBytes.Concat(buf)
|
25
|
-
last12Bytes = allBytes.Skip(allBytes.Length -
|
25
|
+
last12Bytes = allBytes.Skip(allBytes.Length - 12).Take(12)
|
26
26
|
End While
|
27
27
|
fs.Write(allBytes, 0, SerialPort1.BytesToRead)
|
28
28
|
End Sub
|
4
誤り訂正
answer
CHANGED
@@ -14,11 +14,9 @@
|
|
14
14
|
上記を削除して、下記参考にデバッグしてみてください。
|
15
15
|
```vbnet
|
16
16
|
Dim fs As FileStream
|
17
|
-
Dim SerialPort1 As New SerialPort
|
18
17
|
Dim last12Bytes(12) As Byte
|
19
18
|
Dim allBytes As Byte() = {}
|
20
19
|
|
21
|
-
|
22
20
|
fs = File.Create("aaa.png")
|
23
21
|
While Not isIEND(last12Bytes)
|
24
22
|
Dim buf(SerialPort1.BytesToRead) As Byte
|
3
codeをvbnetフォーマットに変更
answer
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
おそらく、pngなのかjpegなのかは問題ではなく、読んだByte配列をファイルに書けば良いので、
|
2
|
-
```
|
2
|
+
```vbnet
|
3
3
|
'ここに下記コードでデータは取得できそうですが、そこからPNGファイルに変換したいです
|
4
4
|
'画像ファイルに変換できるのなら、別の方法でも可です
|
5
5
|
Dim buf(SerialPort1.BytesToRead) As Byte
|
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
pngデータの終わりはIENDチャンクというのを認識すれば良いみたいです。
|
14
14
|
上記を削除して、下記参考にデバッグしてみてください。
|
15
|
-
```
|
15
|
+
```vbnet
|
16
16
|
Dim fs As FileStream
|
17
17
|
Dim SerialPort1 As New SerialPort
|
18
18
|
Dim last12Bytes(12) As Byte
|
2
ファイル終わりの認識について追記
answer
CHANGED
@@ -7,6 +7,45 @@
|
|
7
7
|
File.WriteAllBytes("aaa.png", buf)
|
8
8
|
```
|
9
9
|
これで良い気がします。
|
10
|
+
|
11
|
+
(追記)
|
12
|
+
|
13
|
+
pngデータの終わりはIENDチャンクというのを認識すれば良いみたいです。
|
14
|
+
上記を削除して、下記参考にデバッグしてみてください。
|
15
|
+
```VB.Net
|
16
|
+
Dim fs As FileStream
|
17
|
+
Dim SerialPort1 As New SerialPort
|
18
|
+
Dim last12Bytes(12) As Byte
|
19
|
+
Dim allBytes As Byte() = {}
|
20
|
+
|
21
|
+
|
22
|
+
fs = File.Create("aaa.png")
|
23
|
+
While Not isIEND(last12Bytes)
|
24
|
+
Dim buf(SerialPort1.BytesToRead) As Byte
|
25
|
+
SerialPort1.Read(buf, 0, SerialPort1.BytesToRead)
|
26
|
+
allBytes = allBytes.Concat(buf)
|
27
|
+
last12Bytes = allBytes.Skip(allBytes.Length - 4).Take(4)
|
28
|
+
End While
|
29
|
+
fs.Write(allBytes, 0, SerialPort1.BytesToRead)
|
30
|
+
End Sub
|
31
|
+
|
32
|
+
'IENDチャンクが来たらファイル終わり
|
33
|
+
'00 00 00 00 "IEND" AE 42 60 82
|
34
|
+
Private Function isIEND(last12Bytes() As Byte) As Boolean
|
35
|
+
Dim iend() As Byte =
|
36
|
+
New Byte() {&H0, &H0, &H0, &H0} _
|
37
|
+
.Concat("IEND".Select(Of Byte)(
|
38
|
+
Function(c)
|
39
|
+
Return Byte.Parse(c)
|
40
|
+
End Function)) _
|
41
|
+
.Concat({&HAE, &H42, &H60, &H82})
|
42
|
+
|
43
|
+
Return last12Bytes.SequenceEqual(iend)
|
44
|
+
|
45
|
+
End Function
|
46
|
+
|
47
|
+
```
|
48
|
+
|
10
49
|
ソースの先頭にこれが要るかも。
|
11
50
|
```
|
12
51
|
Imports System.IO
|
1
不要な行を削除
answer
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
'ここに下記コードでデータは取得できそうですが、そこからPNGファイルに変換したいです
|
4
4
|
'画像ファイルに変換できるのなら、別の方法でも可です
|
5
5
|
Dim buf(SerialPort1.BytesToRead) As Byte
|
6
|
-
Dim file As File
|
7
6
|
SerialPort1.Read(buf, 0, SerialPort1.BytesToRead)
|
8
7
|
File.WriteAllBytes("aaa.png", buf)
|
9
8
|
```
|