/* Jpegファイルとメモリストリームの操作 2004/ 5/15 宍戸 輝光 */ using System; using System.Drawing; using System.Windows.Forms; using System.IO; public class test:Form { private Bitmap m_bmp; test() { // コンストラクタ /* ファイルストリーム生成 */ FileStream fs = new FileStream("test.jpg", FileMode.Open); /* データ格納用バッファ生成 */ byte[] abyData = new byte[fs.Length]; /* バッファにデータを読み込む */ fs.Read(abyData, 0, (int)fs.Length); fs.Close(); /* データを格納したバッファからMemoryStream生成 */ MemoryStream ms = new MemoryStream(abyData); /* ストリームからBitmap生成 */ m_bmp = new Bitmap(ms); ms.Close(); /* フォームのクライアント領域サイズをBitmapにあわせる */ ClientSize = m_bmp.Size; } protected override void OnPaint(PaintEventArgs e) { /* Bitmapをフォームに描画 */ e.Graphics.DrawImage(m_bmp, 0, 0); } public static void Main() { // フォーム生成 test app = new test(); // イベントループに入る Application.Run(app); } }