【使い方】
/// <summary>
/// 指定したImageデータからバイナリ ラージ オブジェクト(BLOB)を生成します。
/// </summary>
private System.Byte[] ConvertImageToBLOB( System.Drawing.Image source )
{
System.Byte[] blob = null;
try
{
//ファイルストリームでイメージデータを読み込み
System.IO.MemoryStream tempStream = new System.IO.MemoryStream();
//メモリストリーム(Byte[])にImageデータを設定
source.Save(tempStream, System.Drawing.Imaging.ImageFormat.Jpeg );
//メモリストリームからByte[]データを取得
blob = tempStream.ToArray();
//メモリストリームを閉じる
tempStream.Close();
}
catch
{
throw new BadImageFormatException
("データを Image オブジェクト(BLOB)に変換できません。扱えないデータが指定された可能性があります。");
}
return blob;
}
|