Hello Everyone I want to use DocumentViewer control to display Multipage Tiffs.The code i have written is the following...
using System;
using System.Collections.Generic;
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;
namespace Tiff_Viewer
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private System.Windows.Controls.Image _Image;
private System.Windows.Documents.FixedDocument _FixedDocument;
private System.Windows.Documents.FixedPage _FixedPage;
private System.Windows.Documents.PageContent _PageContent;
public MainWindow()
{
InitializeComponent();
}
private void testbutton_Click(object sender, RoutedEventArgs e)
{
try
{
this._Image = new Image();
FileStream ImageStream = new FileStream("C:\\Users\\ttsa\\Desktop\\DocumentViewerTest\\002544-20180907.tif", FileMode.Open, FileAccess.Read, FileShare.Read);
TiffBitmapDecoder ImageDecoder = new TiffBitmapDecoder(ImageStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
//BitmapSource bitmapSource = ImageDecoder.Frames[0];
this._Image.Source = ImageDecoder.Frames[0];
//this._Image.Source = new BitmapImage(new Uri("C:\\Users\\ttsa\\Desktop\\DocumentViewerTest\\AAA0011A.tif", UriKind.Relative));
this._Image.Stretch = Stretch.None;
this._Image.Margin = new Thickness(20);
this._FixedPage = new System.Windows.Documents.FixedPage();
this._FixedPage.Width = 1000;
this._FixedPage.Height = 1000;
this._FixedPage.Children.Add(this._Image);
this._PageContent = new System.Windows.Documents.PageContent();
this._PageContent.Child = this._FixedPage;
this._FixedDocument = new FixedDocument();
this._FixedDocument.Pages.Add(this._PageContent);
DocumentViewer.Document = this._FixedDocument;
//DocumentViewer.LastPage();
}
catch (Exception fd)
{
System.Windows.MessageBox.Show(fd.Message);
}
}
}
}
-------------------------------WPF---------------------------------------------------------------------------
<Window x:Class="Tiff_Viewer.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:Tiff_Viewer"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
<DocumentViewer Grid.Row="1" x:Name="DocumentViewer" HorizontalAlignment="Left" Margin="0,41,0,0" VerticalAlignment="Top"/>
<Button HorizontalAlignment="left" Content="TEST" Name="testbutton" Grid.Row="0" Width="30" Click="testbutton_Click"/>
</Grid>
I have tried to take and display only one frame-page from the TIFF.However when i run the program it does show the page i want BUT when i move the cursor of the mouse inside the Document Viewer and specifically inside the image i keep getting the following error:
"System.IO.FileNotFoundException: 'Could not find file 'C:\Users\ttsa\Desktop\TIFF_Viewer\Tiff_Viewer\Tiff_Viewer\bin\Debug\image'.'".
I have tried almost everything and i cant find a way to fix this. Does anyone knows anything about this? Is there something i can do to fix it? Or else does anyone knows another way to display multipage tiff to DocumentViewer???
Thanks in advance!!!