首页 > 其他分享 >WPF relative uri

WPF relative uri

时间:2024-09-30 20:50:24浏览次数:13  
标签:Windows uri jpg System relative Source new using WPF

 <Image Grid.Column="0" 
        Source="pack://application:,,,/WpfApp431;component/Images/1.jpg"
        RenderOptions.BitmapScalingMode="Fant"/>
 <Image Grid.Column="1" 
        Source="pack://application:,,,/Images/1.jpg"
        RenderOptions.BitmapScalingMode="Fant"/>
 <Image Grid.Column="2" 
        Source="/Images/1.jpg" 
        RenderOptions.BitmapScalingMode="Fant"/>
 <Image Grid.Column="3" x:Name="img" 
        RenderOptions.BitmapScalingMode="Fant"/>


//cs
img.Source = new BitmapImage(new Uri("pack://application:,,,/Images/1.jpg"));

 

Source="pack://application:,,,/WpfApp431;component/Images/1.jpg"



Source="pack://application:,,,/Images/1.jpg"



Source="/Images/1.jpg"


img.Source = new BitmapImage(new Uri("pack://application:,,,/Images/1.jpg"));

 

 

 

 

//xaml
<Window x:Class="WpfApp431.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp431"
        mc:Ignorable="d"
        WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Image Grid.Column="0" 
               Source="pack://application:,,,/WpfApp431;component/Images/1.jpg"
               RenderOptions.BitmapScalingMode="Fant"/>
        <Image Grid.Column="1" 
               Source="pack://application:,,,/Images/1.jpg"
               RenderOptions.BitmapScalingMode="Fant"/>
        <Image Grid.Column="2" 
               Source="/Images/1.jpg" 
               RenderOptions.BitmapScalingMode="Fant"/>
        <Image Grid.Column="3" x:Name="img" 
               RenderOptions.BitmapScalingMode="Fant"/>
    </Grid>
</Window>


//cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp431
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            img.Source = new BitmapImage(new Uri("pack://application:,,,/Images/1.jpg"));
        }
    }
}

 

标签:Windows,uri,jpg,System,relative,Source,new,using,WPF
From: https://www.cnblogs.com/Fred1987/p/18442421

相关文章

  • spring security 超详细使用教程(接入springboot、前后端分离)
    SpringSecurity是一个强大且可扩展的框架,用于保护Java应用程序,尤其是基于Spring的应用。它提供了身份验证(验证用户身份)、授权(管理用户权限)和防护机制(如CSRF保护和防止会话劫持)等功能。SpringSecurity允许开发者通过灵活的配置实现安全控制,确保应用程序的数据和资......