从MemoryStream乘以图像源

时间:2017-11-29 15:38:16

标签: c# wpf image memorystream bitmapimage

我使用以下代码将图像文件转换为96 DPI并将其用作背景。

BitmapSource bitmapSource = ConvertBitmapTo96Dpi(CompleteBackgroundImage);
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
MemoryStream memoryStream = new MemoryStream();

encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
encoder.Save(memoryStream);

memoryStream.Position = 0;

CompleteBackgroundImage = new BitmapImage();
CompleteBackgroundImage.BeginInit();
CompleteBackgroundImage.StreamSource = memoryStream;
CompleteBackgroundImage.CacheOption = BitmapCacheOption.OnLoad;
CompleteBackgroundImage.DecodePixelHeight = (int)Math.Round(finalHeight, MidpointRounding.AwayFromZero);
CompleteBackgroundImage.DecodePixelWidth = (int)Math.Round(finalWidth, MidpointRounding.AwayFromZero);
CompleteBackgroundImage.EndInit();

memoryStream.Close();

现在我想,如果屏幕大于文件,则将图像乘以一个图像,这样我就可以将它用作背景。 因此,如果我的屏幕为1920 x 1080且图片仅为500 x 500,我希望该图片与2000 x 1500一样大,并且原始图片必须从左到右显示4次,从中显示3次直到下来。

但我应该怎么做?

0 个答案:

没有答案