반응형
<Window x:Class="WPFImagePrintTest.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:WPFImagePrintTest"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Image Name="image" Height="250" Width="425" Margin="82,10,10,59"></Image>
<Button x:Name="button1" Content="이미지!" HorizontalAlignment="Left" Margin="10,279,0,10" Width="75" Click="button1_Click"/>
<Button x:Name="button" Content="인쇄" HorizontalAlignment="Left" Margin="110,279,0,10" Width="75" Click="button_Click"/>
</Grid>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e) // 이미지를 인쇄하는 부분
{
var bi = imageLoad();
var vis = new DrawingVisual();
var dc = vis.RenderOpen();
dc.DrawImage(bi, new Rect { Width = bi.Width, Height = bi.Height });// 이것을 움직이면 크기를 바꿀 수 있습니다.
dc.Close();
var pdialog = new PrintDialog();
if (pdialog.ShowDialog() == true)
{
pdialog.PrintVisual(vis, "Smile Image");
}
}
private void button1_Click(object sender, RoutedEventArgs e) // 이미지 보여주는 함수
{
image.Source = imageLoad();
}
private ImageSource imageLoad() // 이미지를 불러오는 부분
{
var bi = new BitmapImage();
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.UriSource = new Uri(@"..\Assets\images.png", UriKind.Relative);
bi.EndInit();
return bi;
}
}
출처: https://finoriko8.tistory.com/34 [Visual Studio 연구소]
반응형
'[====== Development ======] > C#' 카테고리의 다른 글
REST API 사용 (1) | 2021.01.07 |
---|---|
Extension Method (0) | 2021.01.07 |
간단한 Logger 만들기 (0) | 2021.01.07 |
C# Expression (0) | 2021.01.04 |
GoF의 디자인 패턴 (C#) (0) | 2020.11.05 |