I am writing program for Windows Phone 7.1 and using component Image, I stretch image in it - and its get blurry. I`ve studied such issues - it seems like UseLayoutRounding="True" should help, but it didnt help for me.
Here is the code:
<Grid x:Name="LayoutRoot" UseLayoutRounding="True" Background="Transparent">
<controls:Panorama x:Name="mainPanorama" Title="life rpg" SelectionChanged="Panorama_SelectionChanged_1">
<controls:Panorama.Background>
<ImageBrush ImageSource="Imgs/bg.jpg"/>
</controls:Panorama.Background>
<controls:PanoramaItem Header="main" Tag="main" >
<StackPanel Name="mainPanel">
<StackPanel Orientation="Horizontal">
<Image HorizontalAlignment="Left" Height="165" VerticalAlignment="Top" Width="165" Source="picture.png" Margin="0 0 20 0"/>
<Image Name="swordImg" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="50" Source="Imgs/swords/swordLVL1.png" Stretch="Fill" />
<Image Name="armorImg" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" Source="Imgs/armors/armorLVL1.png" Stretch="Uniform" />
<Image Name="shieldImg" HorizontalAlignment="Left" Height="150" VerticalAlignment="Top" Width="150" Source="Imgs/shields/shieldLVL1.png" Stretch="UniformToFill" />
</StackPanel>
<!--LayoutRoot is the root grid where all page content is placed-->
If the quality of an image is important when displayed at a large size then you have 2 options.
Start with a large image. Bitmap images will suffer distortion when made larger. This will be amplified depending on the compression/quality setting used within a JPEG file.
Use an image in a vector format.
Given the low resolution of your image (given that it is raster format and not vector), you cannot upscale it without losing quality. No rendering options will help you here.
A 25x25 image for a Panorama background is definitely not enough quality-wise.
Related
Hi I'm struggling with rotation in XAML. I found a solution that LayoutTransform should solve this issue, but on Windows Universal Plattform this option isn't available!
This is my Code:
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"
HorizontalAlignment="Center">
<Rectangle Fill="Red" Height="100" Width="100" />
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center"
Text="long long long long long long long long text"
RenderTransformOrigin="0.5,0.5" >
<TextBlock.RenderTransform>
<CompositeTransform Rotation="90"/>
</TextBlock.RenderTransform>
</TextBlock>
<Rectangle Fill="Green" Height="100" Width="100" />
</StackPanel>
But as you can see there are an huge margin between the colored boxes and the textblock as you can see here:
So my first guess was to add an Width="30" property to the textblock, but this isn't working as you can see here (not only the offset is the problem, but the cropping is the problem):
Any suggestions?
Try the LayoutTransform control of the WinRTXamlToolkit. Following links should help.
Github Source link and Demo link
I have a WPF Window with Viewbox. I want one of the child elements of this Viewbox to stay the same size at any screen resolution.
My XAML:
<Viewbox Name="MyMainViewbox" Stretch="Fill">
<Grid Name="MyMainGrid">
<Image Source="Images/bg.bmp" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stretch="Fill"/>
<Image Name="Thumb1" Source="Images/t1.png" MouseUp="Right_Click" Margin="0, 100, 50, 0" HorizontalAlignment="Right" VerticalAlignment="Stretch" Visibility="Visible"/>
<Image Name="Thumb2" Source="Images/t2.png" MouseUp="Left_Click" Margin="50, 100, 0, 0" HorizontalAlignment="Left" VerticalAlignment="Stretch" Visibility="Visible"/>
<Image Name="CurThumb" Width="640" Height="480" Stretch="UniformToFill" Margin="0, 50, 0, 0" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Hidden"/>
</Grid>
</Viewbox>
The first 2 images inside the Viewbox are predefined and scaled finely at the different screen resolutions.
My problem is with the 3rd image that gets its source during the runtime and should be of the same exact size at all resolutions. It will contain photos taken at 4x3 aspect ration, and I want them to stay so.
However at 16x9 screen resolutions they are stretched. I have tried to set a fixed size in XAML - it doesn't work. I have tried to set Stretch to None - doesn't work neither. I have tried to rest the sizes of this Image in the code behind - to no avail.
What else can I do to make this third picture unscalable?
It should stay inside the Viewbox for a couple of reasons.
Use two overlapping elements.
<Grid>
<Viewbox>
<Grid>
... scaled images
</Grid>
</Viewbox>
<Grid>
... non scaled images
<Grid>
<Grid>
I am developing an application where i want to browse images like native WindowsPhone form.
I have used Pivot control. Everything works, but there is one unwanted thing. The image does not fill all display area. There is a gap on the top of page. I have set margin and padding everywhere where it is possible. And the result is still the same. :(
Here is my XAML code:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid
x:Name="LayoutRoot"
Background="Transparent"
Margin="0">
<toolkit:PerformanceProgressBar
VerticalAlignment="Top"
HorizontalAlignment="Left"
IsIndeterminate="{Binding IsBusy}"
Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibilityConverter}}"
/>
<controls:Pivot
x:Name="PhotoPivot"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
IsHitTestVisible="True"
ItemsSource="{Binding Photos}"
Margin="0"
Padding="0"
>
<controls:Pivot.HeaderTemplate>
<DataTemplate/>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate >
<controls:PivotItem
x:Name="PhotoPivotItem"
Margin="0"
>
<Image
x:Name="PhotoPicture"
Source="{Binding}"
Stretch="Uniform"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="0"
/>
</controls:PivotItem>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
</Grid>
Are you talking about the system tray?
To remove the system tray use the following code:
shell:SystemTray.IsVisible="False"
Update:
I'm not real sure why that extra space is there.
I created a simplified version of your example and the only thing I could think of is to use negative margins. There is probably a better solution that I am just overlooking, but for now you can just use the following:
<controls:PivotItem x:Name="PhotoPivotItem" Margin="0,-10,0,0">
Although, from your posted image, it looks as if you have a bigger gap than I did, so you might need to decrease the margin.
I am using a textblock to display the product description under the product's image. The text must be fixed 100px wide but the height can grow up to 30px tall. If the text still can't fit, it must display ellipsis. Here is my xaml:
<StackPanel>
<!-- I use canvas here to reserve some space for animation (grow/shrink) -->
<Canvas Height="75" Width="75">
<Image x:Name="picture" Height="64" Width="64" .../>
<Canvas/>
<TextBlock Width="100" MaxHeight="30"
TextTrimming="CharacterEllipsis" TextWrapping="Wrap"
Text="{Binding Path=ProductDescription}"
HorizontalAlignment="Center" VerticalAlignment="Top" TextAlignment="Center">
</StackPanel>
The description can have multiple lines. For eg, "Wireless Mouse\nQuantity:20". It looks ok on XP but on Windows 7 only the first line shows up and there's no ellipsis. Can anyone spot the problem in my xaml?
There are several errors in your example: should , ".../>" isn't valid XAML and your TextBlock doesn't have a closing tag.
The follow XAML worked fine on for me on Windows 7:
<StackPanel>
<!-- I use canvas here to reserve some space for animation (grow/shrink) -->
<Canvas Height="75" Width="75">
<Image x:Name="picture" Height="64" Width="64" />
</Canvas>
<TextBlock Width="100" MaxHeight="30"
TextTrimming="CharacterEllipsis" TextWrapping="Wrap"
Text="I use canvas here to reserve some space for animation (grow/shrink)"
HorizontalAlignment="Center"
VerticalAlignment="Top"
TextAlignment="Center" />
</StackPanel>
Depending on the font size MaxHeight of 30 is almost just one line of text, so the textblock can't grow in height. Change it or remove it completely.
I have a StackPanel containing five images and I want to put a black border around each image.
The XAML I have at the moment is:
<Image Name="imgPic1"
Width="100"
Height="75"
Stretch="Fill"
VerticalAlignment="Top" />
I thought I would be just able to put a one-unit margin or padding on the image and set a background color to 000000 but Padding and Background are both invalid for images.
What is an easy way to do this in XAML? Do I really have to put each image inside another control to get a border around it or is there some other trickery I can use?
Simply wrap the Image in a Border control
<Border BorderThickness="1">
<Image Name="imgPic1"
Width="100"
Height="75"
Stretch="Fill"
VerticalAlignment="Top" />
</Border>
You could also provide a style you apply to images that does this if you don't want to do it around every image
Final solution from answer and comments added by Pax:
<Border BorderThickness="1"
BorderBrush="#FF000000"
VerticalAlignment="Top">
<Image Name="imgPic1"
Width="100"
Height="75"
Stretch="Fill"
VerticalAlignment="Top"/>
</Border>
The accepted answer will not work because of the problem described here
https://wpf.2000things.com/2011/04/17/279-adding-a-border-around-an-image-control/
I solved it this way.
<Viewbox>
<Border BorderThickness="3" BorderBrush="Red">
<Image Stretch="None" ></Image>
</Border>
</Viewbox>
I just stumbled upon this post and the other answer did not work right. Maybe because I now use framework 4 and this post is old?
In any case - if someone will see this by chance in the future - here is my answer:
<Border Name="brdSiteLogo"
BorderThickness="2"
BorderBrush="#FF000000"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Margin="12,112,0,0"
Height="128"
Width="128">
<Image Name="imgSiteLogo"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Stretch="Fill"/>
</Border>
The border thickness and brush are important (if you wont choose a color - you will not see the border!!!)
Also, the border should be aligned on your window. The image is "inside" the border, so you can use margins or just stretch it like I did.