简体   繁体   English

JPG ImageBrush ImageSource值不在预期范围内

[英]JPG ImageBrush ImageSource Value does not fall within the expected range

I have been srtuggling on this one for quite some time, looking everywhere I could on SO and Google without success. 我已经为此苦苦挣扎了很长时间,在SO和Google上我能找到的一切都没有成功。
I want to display a background image in some simple window (How Ambitious!) 我想在一些简单的窗口中显示背景图像(多么雄心勃勃!)

<Window x:Class="HelloWorld_Lite.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowStyle="None" ResizeMode="NoResize"
        Title="Hello World" Height="350" Width="525">
    <Window.Background >
        <ImageBrush ImageSource="HelloWorld-Lite;component/Background.jpg" />
    </Window.Background>
    <Grid>
    <Label Content="Hello World!" Height="28" HorizontalAlignment="Left" Margin="225,30,0,0" Name="label2" VerticalAlignment="Top" />
    </Grid>
</Window>

The image has been added to the project (Add > Existing Item) and is built as "Resource" 该图像已添加到项目(“添加”>“现有项目”)中,并作为“资源”构建
I did a clean up and rebuild, but this thing is still trying my nerves. 我进行了清理和重建,但是这件事仍然让我感到不安。

Please Tell Me I missed something obvious 请告诉我我错过了明显的事情

Edit : Saving the file to PNG format fixed the problem(?). 编辑 :将文件保存为PNG格式可解决问题(?)。 PNG size = 2Mb, JPG size=360k. PNG大小= 2Mb,JPG大小= 360k。
If this is a limitation, this is just ridiculous. 如果这是一个限制,那就太荒谬了。

Edit 2 : Resizing the original JPG from 1280x853 to 480x320 also fixed the problem. 编辑2 :将原始JPG从1280x853调整为480x320的大小也解决了该问题。
Hence, It looks like a size limitation specific to JPG format. 因此,它看起来像是JPG格式的大小限制。

As per the iterative process above, two fixes are possible 按照上面的迭代过程,可以进行两个修复

1) Preserve file size by converting the image to PNG format 1)通过将图像转换为PNG格式来保留文件大小
2) Preserve JPG format by reducing image size 2)通过减小图像尺寸来保留JPG格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM