Resources.resxファイルに埋め込んだ画像ファイルをImageオブジェクトに突っ込む
Streamを使用するならResources.resxファイルに画像ファイルを埋め込んでおく必要性があまり感じない・・・。
これもゴチャゴチャしているので何とかなら無いものか
System.Drawing.Bitmap gifBitmap = Properties.Resources.numericExpression01; // gif MemoryStream memoryStream = new MemoryStream(); gifBitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Gif); BitmapDecoder decoder = new GifBitmapDecoder(memoryStream, BitmapCreateOptions.None, BitmapCacheOption.Default); BitmapSource bitmapSource = decoder.Frames[0]; Image simpleImage = new Image(); simpleImage.Width = bitmapSource.Width; simpleImage.Height = bitmapSource.Height; Canvas.SetLeft(simpleImage, 10); Canvas.SetTop(simpleImage, 10); simpleImage.Source = bitmapSource;
上記はnumericExpression01がgifの場合であり、bmpなら下記のようにする
System.Drawing.Bitmap bmpBitmap = Properties.Resources.numericExpression01; // gif MemoryStream memoryStream = new MemoryStream(); gifBitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp); BitmapDecoder decoder = new BmpBitmapDecoder(memoryStream, BitmapCreateOptions.None, BitmapCacheOption.Default); BitmapSource bitmapSource = decoder.Frames[0];