我想合并两个图像,一个图像是 300x300,另一个是 100x100,首先我创建了一个画布,然后我创建了两个图像,我将它们添加到画布的图像中,并将画布添加到内容面板中,然后我创建了一个writeablebitmap
并渲染画布并创建了一个savejpeg
将图像保存到的方法isolated stoarage
,但是隔离存储没有显示整个图像,它保存了一个黑屏。
首先,我通过代码创建了一个画布,设置了它的高度宽度和背景颜色,然后我以编程方式创建了两个图像,我已将它们添加到画布中,然后将画布添加到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);
}
}
当我保存图像时,我在隔离存储中出现黑屏。 如何将两个图像保存在画布上?