fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.IO.Compression; // 圧縮(Deflate)の為
  11. using System.Runtime.InteropServices; // Marshalの為
  12.  
  13. namespace Deflate_Test
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. struct GetData
  23. { // データ取得用構造体
  24. public UInt32 intNum;
  25. public uint intFlag;
  26. public uint intWidth;
  27. public uint intHeight;
  28. public UInt32[] intData; // = new UInt32[1280 * 1024];
  29. public void Reset()
  30. { // 値を入れる時に必ず実行すること
  31. intData = new UInt32[1280 * 1024];
  32. }
  33. }
  34. private List<GetData> PGetSaveData = new List<GetData>(); // 保存用データ(ジェネリック)
  35.  
  36. private void button1_Click(object sender, EventArgs e)
  37. {
  38. for (uint i = 0; i < 1000; i++)
  39. {
  40. GetData gd = new GetData();
  41. gd.intNum = i;
  42. gd.intFlag = 0xff;
  43. gd.intWidth = 1280; // 幅と高さはROIで設定しているので、不要かも???
  44. gd.intHeight = 1024;
  45. gd.Reset(); // 構造体の配列の初期化
  46. for (uint j = 0; j < 1280 * 1024; j++)
  47. {
  48. gd.intData[j] = j;
  49. }
  50. PGetSaveData.Add(gd); // ジェネリックに追加
  51. }
  52. }
  53.  
  54. private void button2_Click(object sender, EventArgs e)
  55. {
  56. IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GetData)));
  57. byte[] packet = new byte[Marshal.SizeOf(typeof(GetData))];
  58.  
  59. // 入出力用のストリーム
  60. MemoryStream ms = new MemoryStream();
  61. DeflateStream CompStream = new DeflateStream(ms, CompressionMode.Compress, true);
  62.  
  63. try{
  64.  
  65. for (uint i = 0; i < 1000; i++)
  66. {
  67. // 構造体をバイト配列に変換
  68. Marshal.StructureToPtr(PGetSaveData[(int)i], ptr, false);
  69. Marshal.Copy(ptr, packet, 0, Marshal.SizeOf(typeof(GetData)));
  70.  
  71. // ストリームに圧縮するデータを書き込む
  72. CompStream.Write(packet, 0 , packet.Length); // 追記?
  73. }
  74. }finally{
  75. if(IntPtr.Zero != ptr){Marshal.FreeHGlobal(ptr);}
  76. }
  77. CompStream.Close();
  78.  
  79. // 圧縮されたデータをバイト配列で取得
  80. //byte[] dest = ms.ToArray();
  81.  
  82. // ストリームを開放
  83. ms.Close();
  84. ms.Dispose();
  85.  
  86. // サイズを比較
  87. label1.Text = (PGetSaveData.Count * Marshal.SizeOf(typeof(GetData))).ToString();
  88. //label2.Text = dest.Length.ToString();
  89. }
  90. }
  91. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(4,14): error CS0234: The type or namespace name `Data' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(5,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(8,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 3 error(s), 0 warnings
stdout
Standard output is empty