首页 > 其他分享 >WPF open image and print as pdf file

WPF open image and print as pdf file

时间:2024-07-03 20:19:43浏览次数:1  
标签:dlg Windows image imgFile System file new print using

//xaml
<Window x:Class="WpfApp189.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:WpfApp189"
        mc:Ignorable="d" WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Orientation="Horizontal">
            <Button Content="Open Image" FontSize="20" Click="OnOpenImage"
         HorizontalAlignment="Center" Margin="4"/>
            <Button Content="Print Image" FontSize="20" Click="OnPrintImage"
         HorizontalAlignment="Center"/>
        </StackPanel>

        <Image x:Name="img" Grid.Row="1"/>
    </Grid>
</Window>






//cs
using System;
using System.Collections.Generic;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.IO;
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;
using System.Windows.Xps.Packaging;
using System.Xml.Linq;
using Microsoft.Win32;

namespace WpfApp189
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        string imgFile = "";
        private void OnOpenImage(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog()
            {
                Filter = "Image files|*.png;*.jpg;*.gif;*.bmp|All Files|*.*",
                Title = "Select image to open",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            };
            if(dlg.ShowDialog()==true)
            {
                img.Source = new BitmapImage(new Uri(dlg.FileName));
                imgFile=dlg.FileName;
            }
        }

        private void OnPrintImage(object sender, RoutedEventArgs e)
        {  
            if(File.Exists(imgFile)) 
            {
                Process p = new Process();
                p.StartInfo = new ProcessStartInfo()
                {
                    CreateNoWindow = true,
                    Verb = "print",
                    FileName = imgFile
                };
                p.Start();
            } 
        }
    }
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

标签:dlg,Windows,image,imgFile,System,file,new,print,using
From: https://www.cnblogs.com/Fred1987/p/18282489

相关文章

  • Derect local .aar file dependencies are not supported when building an AAR
    背景项目中需要将部分功能业务打包成aar包供其它项目调用,我引入了fataar(具体使用方式见github)。实际打包过程中抛出错误Derectlocal.aarfiledependenciesarenotsupportedwhenbuildinganAAR原因分析我们项目中lib文件夹下导入了很多jar包、aar包,在之前没有引入aar包......
  • dockerfile构建镜像
    dockerfile构建镜像镜像是多层存储,每一层在前一层的基础上进行修改;容器也是多层存储,以镜像为基础层,在其基础上加一层作为容器运行时的存储层。要求1.docker会逐行读取dockerfile中每一行的指令,按顺序解析,实现images的自动构建2.通过dockerbuild命令构建镜像3.dockerfile......
  • springboot的MultipartFile转File读取
    在SpringBoot中,处理文件上传时,MultipartFile接口被用来封装上传的文件信息。如果需要将MultipartFile转换为Java标准的File对象进行读取。以下是具体的操作流程:1.创建临时文件        首先,需要将接收到的MultipartFile对象转换为一个临时File对象。      ......
  • ArcGIS API for Javascript解决html2canvas、domtoimage截图地图出现空白问题
    原因使用html2canvas、domtoimage进行截图时,会出现地图面板是空白的情况,报错如下:#1133msUnabletocloneWebGLcontextasithaspreserveDrawingBuffer=false<canvasstyle=​"width:​100%;​height:​100%;​>在通过ArcGISAPIforJavaScript4.X版本实例化地图的......
  • [Hackerrank University Codesprint 5] Sword profit (李超线段树)
    [HackerrankUniversityCodesprint5]Swordprofit李超线段树考虑大力推式子。写出在第\(i\)所商店的第\(k\)把剑在第\(j\)所商店卖掉的价格。\[\text{profit}=\max(0,q_i-(j-i)\cdotd_i-r_j)-(a_i+k\cdotb_i)\]显然利益一定要是正的才有价值,所以\(\max\)可以改到......
  • The following untracked working tree files would be overwritten by merge/ git st
    背景给同学解决问题时,发现无法拉取远程的分支。解决他在C:\Users\用户名\路径下,建立了一个git仓库,然后在桌面上创建了一个文件夹,文件夹内部又新建了一个文件夹,导致gitstatus显示大量父级目录(多级父级)的文件。删除父级中的.git文件即可拉取前没有initgitpull用惯了......
  • WPF Image scalertransform translatetransform mvvm,custom delegate command Comman
    //xaml<Windowx:Class="WpfApp187.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • Dockerfile语法,自定义镜像
    我们一直在使用别人准备好的镜像,那如果我要部署一个Java项目,把它打包为一个镜像该怎么做呢?镜像结构要想自己构建镜像,必须先了解镜像的结构。镜像之所以能让我们快速跨操作系统部署应用而忽略其运行环境、配置,就是因为镜像中包含了程序运行需要的系统函数库、环境、配置、依......
  • [XDCTF 2015]filemanager
    [XDCTF2015]filemanager​/www.tar.gz​拿到源码我直接在github上看了https://github.com/CTFTraining/xdctf_2015_filemanagercommon.inc.php将传入的所有参数使用addslashes转义函数​​然后分析upload.php使用basename​函数确保文件名中没有目录路径,防止路径遍历攻击。......
  • Visual C++ generate uuid via UuidCreate and CoCreateGuid,get time now,write stri
    //ConsoleApplication3.cpp:Thisfilecontainsthe'main'function.Programexecutionbeginsandendsthere.//#pragmacomment(lib,"rpcrt4.lib")#include<windows.h>#include<chrono>#include<ctime>#include&l......