2 つの画像をマージしたいのですが、1 つの画像は 300x300 で、もう 1 つは 100x100 です。最初にキャンバスを作成し、次に 2 つの画像を作成して、両方の画像をキャンバスに追加し、キャンバスをコンテンツ パネルに追加します。次にwriteablebitmap
、キャンバスを作成してレンダリングしsavejpeg
、画像を保存するメソッドを作成しましたisolated stoarage
が、分離ストレージに画像全体が表示されず、黒い画面が保存されます。
最初に、高さの幅と背景色を設定するコードを使用してキャンバスを作成し、プログラムで2つの画像を作成してキャンバスに追加し、キャンバスをcontentpanel
私のコードは次のとおりです。
public void CreateImage()
{
Canvas canvas = new Canvas();
canvas.Height = 400;
canvas.Width = 400;
canvas.Background = new SolidColorBrush(Colors.Red);
Image img1 = new Image();
img1.Source = (ImageSource)new ImageSourceConverter().ConvertFromString("Image/Desert.jpg");
img1.Height = 300;
img1.Width = 300;
img1.Margin = new Thickness(0, 10, 0, 0);
Image img2 = new Image();
img2.Source = (ImageSource)new ImageSourceConverter().ConvertFromString("Image/Jellyfish.jpg");
img2.Height = 50;
img2.Width = 50;
img2.Margin=new Thickness(0,10,300,0);
canvas.Children.Add(img1);
canvas.Children.Add(img2);
ContentPanel.Children.Add(canvas);
WriteableBitmap wb = new WriteableBitmap(400, 400);
wb.Render(canvas, new MatrixTransform());
MemoryStream ms = new MemoryStream();
wb.SaveJpeg(ms,400,400,0,100);
using (var isoFileStream = new IsolatedStorageFileStream("myPicture.jpg", FileMode.OpenOrCreate, IsolatedStorageFile.GetUserStoreForApplication()))
{
wb.SaveJpeg(isoFileStream, 400, 400, 0, 100);
}
}
画像を保存すると、分離ストレージに黒い画面が表示されます。 両方の画像をキャンバスに保存するには?