コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: rbobot/rbscan
		void CreateJPGFile( IEnumerable<ScannedImageViewModel> items, string filename )
		{
			int index = 1;
			foreach ( ScannedImageViewModel image in items )
			{
				string destination;
				if ( ScannedImages.Count > 1 )
				{
					string temporary = string.Format( "{0}-{1}.{2}", Path.GetFileNameWithoutExtension( filename ), index, "jpg" );
					destination = Path.Combine( Path.GetDirectoryName( filename ), temporary );
					index++;
				}
				else
				{
					destination = filename;
				}
				try
				{
					image.Image.SaveImageJPG( destination, JpegQuality );
				}
				catch ( IOException )
				{
					// localization dictionary
					var dictionary = Application.Current.Resources.MergedDictionaries[ 0 ];
					Notify = new Notify( (string) dictionary[ "er_CantCreateFile" ], Notify.Type.Warning );
				}
				catch ( Exception ex )
				{
					Notify = new Notify( ex.Message, Notify.Type.Warning );
				}
			}
		}
コード例 #2
0
ファイル: MainViewModel.cs プロジェクト: rbobot/rbscan
		void CreatePDFFile( IEnumerable<ScannedImageViewModel> items, string filename )
		{
			try
			{
				// Save document
				var Document = new PdfDocument( PaperType.A4, false, UnitOfMeasure.cm, filename );

				// add to pdf file all images from collection
				foreach ( ScannedImageViewModel scan in items )
				{
					var page = new PdfPage( Document, PaperType.A4, scan.Image.Landscape );
					var contents = new PdfContents( page );
					var image = new PdfImage( Document, scan.Image.Source, 0, PdfQuality );
					contents.DrawFullPageImage( image, scan.Image.Landscape );
				}
				Document.CreateFile();
			}
			catch ( IOException )
			{
				// localization dictionary
				var dictionary = Application.Current.Resources.MergedDictionaries[ 0 ];
				Notify = new Notify( (string) dictionary[ "er_CantCreateFile" ], Notify.Type.Warning );
			}
			catch ( Exception ex )
			{
				Notify = new Notify( ex.Message, Notify.Type.Warning );
			}
		}