【问题标题】:Multiply Image Source From MemoryStream [closed]从 MemoryStream 乘以图像源 [关闭]
【发布时间】:2017-11-29 15:38:15
【问题描述】:

我使用以下代码将图像文件转换为 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次。

但是我应该怎么做呢?

【问题讨论】:

    标签: c# wpf image memorystream bitmapimage


    【解决方案1】:

    考虑使用 TileMode 设置为 Tile 的 ImageBrush:

    <Window.Background>
        <ImageBrush TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,512,384">
            <ImageBrush.ImageSource>
                <BitmapImage UriSource="C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"/>
            </ImageBrush.ImageSource>
        </ImageBrush>
    </Window.Background>
    

    或更短:

    <Window.Background>
        <ImageBrush TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,512,384"
                    ImageSource="C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"/>
    </Window.Background>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-13
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多