Beispiel #1
1
        /// <summary>
        /// Creates a WPF bitmap source from an GDI image.
        /// </summary>
        public static BitmapSource CreateBitmapSource(Image image)
        {
            MemoryStream stream = new MemoryStream();
            //int width = image.Width;
            //int height = image.Height;
            //double dpiX = image.HorizontalResolution;
            //double dpiY = image.VerticalResolution;
            //System.Windows.Media.PixelFormat pixelformat = PixelFormats.Default;
            BitmapSource bitmapSource = null;

            try
            {
                string guid = image.RawFormat.Guid.ToString("B").ToUpper();
                switch (guid)
                {
                    case "{B96B3CAA-0728-11D3-9D7B-0000F81EF32E}":  // memoryBMP
                    case "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}":  // bmp
                        image.Save(stream, ImageFormat.Bmp);
                        stream.Position = 0;
                        BmpBitmapDecoder bmpDecoder = new BmpBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        bitmapSource = bmpDecoder.Frames[0];
                        break;

                    case "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}":  // png
                        image.Save(stream, ImageFormat.Png);
                        stream.Position = 0;
                        PngBitmapDecoder pngDecoder = new PngBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        bitmapSource = pngDecoder.Frames[0];
                        break;

                    case "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}":  // jpeg
                        image.Save(stream, ImageFormat.Jpeg);
                        JpegBitmapDecoder jpegDecoder = new JpegBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        stream.Position = 0;
                        bitmapSource = jpegDecoder.Frames[0];
                        break;

                    case "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}":  // gif
                        image.Save(stream, ImageFormat.Gif);
                        GifBitmapDecoder gifDecoder = new GifBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        stream.Position = 0;
                        bitmapSource = gifDecoder.Frames[0];
                        break;

                    case "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}":  // tiff
                        image.Save(stream, ImageFormat.Tiff);
                        TiffBitmapDecoder tiffDecoder = new TiffBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        stream.Position = 0;
                        bitmapSource = tiffDecoder.Frames[0];
                        break;

                    case "{B96B3CB5-0728-11D3-9D7B-0000F81EF32E}":  // icon
                        image.Save(stream, ImageFormat.Icon);
                        IconBitmapDecoder iconDecoder = new IconBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        stream.Position = 0;
                        bitmapSource = iconDecoder.Frames[0];
                        break;

                    case "{B96B3CAC-0728-11D3-9D7B-0000F81EF32E}":  // emf
                    case "{B96B3CAD-0728-11D3-9D7B-0000F81EF32E}":  // wmf
                    case "{B96B3CB2-0728-11D3-9D7B-0000F81EF32E}":  // exif
                    case "{B96B3CB3-0728-11D3-9D7B-0000F81EF32E}":  // photoCD
                    case "{B96B3CB4-0728-11D3-9D7B-0000F81EF32E}":  // flashPIX

                    default:
                        throw new InvalidOperationException("Unsupported image format.");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ImageHelper.CreateBitmapSource failed:" + ex.Message);
            }
            finally
            {
                //if (stream != null)
                //  stream.Close();
            }
            return bitmapSource;
        }
Beispiel #2
0
        public override void Show(System.Windows.Controls.ContentControl contentControl, object writer)
        {
            ScrollViewer scrollViewer = new ScrollViewer();
            StackPanel stackPanel = new StackPanel();
            stackPanel.Orientation = Orientation.Vertical;
            scrollViewer.Content = stackPanel;

            this.m_ImageStreamSource = new FileStream(this.FullFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            TiffBitmapDecoder tiffDecoder = new TiffBitmapDecoder(this.m_ImageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
            try
            {
                for (int i = 0; i < tiffDecoder.Frames.Count; i++)
                {
                    BitmapSource bitMapSource = tiffDecoder.Frames[i];
                    Image image = new Image();
                    image.Source = bitMapSource;
                    stackPanel.Children.Add(image);
                }
                contentControl.Content = scrollViewer;
            }
            catch
            {

            }
        }
        public static void LoadImage(Uri fileUri, Image frente)
        {
            TiffBitmapDecoder tiffBitmapDecoder = new TiffBitmapDecoder(fileUri,
                               BitmapCreateOptions.None,
                               BitmapCacheOption.Default);

            frente.Source = tiffBitmapDecoder.Frames[0];
        }
Beispiel #4
0
        public static BitmapSource[] BitmapFrames(string tifPath)
        {
            Stream imageStreamSource = new FileStream(tifPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

            BitmapSource[] bitmapFrames = new BitmapSource[decoder.Frames.Count];

            for (int i = 0; i < decoder.Frames.Count; i++)
            {
                bitmapFrames[i] = decoder.Frames[i];
            }

            return bitmapFrames;
        }
        public void Load(System.IO.MemoryStream memoryStream)
        {
            TiffBitmapDecoder decoder = new TiffBitmapDecoder(memoryStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
            foreach (BitmapFrame bitmapFrame in decoder.Frames)
            {
                BitmapSource bitmapSource = bitmapFrame;
                this.m_BitmapSourceList.Add(bitmapSource);

                Image image = new Image();
                image.Source = bitmapSource;
                image.Margin = new Thickness(2);
                this.StackPanelImages.Children.Add(image);
            }
        }
Beispiel #6
0
        public static Document[] ReceiveDocument(Stream contentStream, string filename, int length, IKcsarContext ctx, Guid reference, string type)
        {
            List<Document> docs = new List<Document>();
            if (filename.ToLowerInvariant().EndsWith(".tif", StringComparison.OrdinalIgnoreCase))
            {
                TiffBitmapDecoder decode = new TiffBitmapDecoder(contentStream, BitmapCreateOptions.None, BitmapCacheOption.None);

                int frameCount = decode.Frames.Count;
                for (int i = 0; i < frameCount; i++)
                {
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();

                    JpegBitmapEncoder encode = new JpegBitmapEncoder();
                    encode.Frames.Add(BitmapFrame.Create(decode.Frames[i]));
                    encode.Save(ms);
                    ms.Seek(0, System.IO.SeekOrigin.Begin);
                    docs.Add(Kcsara.Database.Web.Documents.ProcessImage(ms, ctx, filename.Replace(".tif", string.Format("-{0}.jpg", i)), reference));
                    ms.Dispose();
                }
            }
            else if (filename.ToLowerInvariant().EndsWith(".jpg"))
            {
                docs.Add(Kcsara.Database.Web.Documents.ProcessImage(contentStream, ctx, filename, reference));
            }
            else
            {
                byte[] contents = new byte[length];
                contentStream.Read(contents, 0, length);

                Document doc = new Document
                {
                    Size = length,
                    FileName = System.IO.Path.GetFileName(filename),
                    Contents = contents,
                    ReferenceId = reference,
                    MimeType = GuessMime(filename),
                    Type = type
                };
                ctx.Documents.Add(doc);
                docs.Add(doc);
            }
            return docs.ToArray();
        }
        public void Load(string fileName)
        {
            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
            System.IO.FileStream fileStream = System.IO.File.OpenRead(fileName);
            CopyStream(fileStream, memoryStream);
            fileStream.Close();

            TiffBitmapDecoder decoder = new TiffBitmapDecoder(memoryStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
            foreach (BitmapFrame bitmapFrame in decoder.Frames)
            {
                BitmapSource bitmapSource = bitmapFrame;
                this.m_BitmapSourceList.Add(bitmapSource);

                Image image = new Image();
                image.Source = bitmapSource;
                image.Margin = new Thickness(2);
                this.StackPanelImages.Children.Add(image);
            }
        }
Beispiel #8
0
        /// <summary>
        /// 从资源中恢复图像(png、ico、jpeg、bmp)
        /// </summary>
        /// <param name="nomImage"></param>
        /// <returns></returns>
        public static ImageSource ImageSource(string nomImage)
        {
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(nomImage);

            if (Path.GetExtension(nomImage).ToLower().EndsWith(".png")) // Cas png
            {
                PngBitmapDecoder img = new System.Windows.Media.Imaging.PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(img.Frames[0]);
            }

            if (Path.GetExtension(nomImage).ToLower().EndsWith(".bmp")) // Cas bmp
            {
                BmpBitmapDecoder img = new System.Windows.Media.Imaging.BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(img.Frames[0]);
            }

            if (Path.GetExtension(nomImage).ToLower().EndsWith(".jpg")) // Cas jpg
            {
                JpegBitmapDecoder img = new System.Windows.Media.Imaging.JpegBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(img.Frames[0]);
            }

            if (Path.GetExtension(nomImage).ToLower().EndsWith(".tiff")) // Cas tiff
            {
                TiffBitmapDecoder img = new System.Windows.Media.Imaging.TiffBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(img.Frames[0]);
            }

            if (Path.GetExtension(nomImage).ToLower().Contains(".ico")) // Cas  ico
            {
                IconBitmapDecoder img = new System.Windows.Media.Imaging.IconBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(img.Frames[0]);
            }

            return(null);
        }
Beispiel #9
0
        //static readonly byte[] pngHeader = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
        //static readonly byte[] jpgHeader = { 0xFF, 0xD8, 0xFF };
        //static readonly byte[] gifHeader = { 0x47, 0x49, 0x46 };
        //static readonly byte[] bmpHeader = { 0x42, 0x4D };
        public override PureImage FromStream(System.IO.Stream stream)
        {
            GMapImage ret = null;
             if(stream != null)
             {
            var type = stream.ReadByte();
            stream.Position = 0;

            ImageSource m = null;

            switch(type)
            {
               // PNG: 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A
               case 0x89:
               {
                  var bitmapDecoder = new PngBitmapDecoder(stream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);
                  m = bitmapDecoder.Frames[0];
                  bitmapDecoder = null;
               }
               break;

               // JPG: 0xFF, 0xD8, 0xFF
               case 0xFF:
               {
                  var bitmapDecoder = new JpegBitmapDecoder(stream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);
                  m = bitmapDecoder.Frames[0];
                  bitmapDecoder = null;
               }
               break;

               // GIF: 0x47, 0x49, 0x46
               case 0x47:
               {
                  var bitmapDecoder = new GifBitmapDecoder(stream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);
                  m = bitmapDecoder.Frames[0];
                  bitmapDecoder = null;
               }
               break;

               // BMP: 0x42, 0x4D
               case 0x42:
               {
                  var bitmapDecoder = new BmpBitmapDecoder(stream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);
                  m = bitmapDecoder.Frames[0];
                  bitmapDecoder = null;
               }
               break;

               // TIFF: 0x49, 0x49 || 0x4D, 0x4D
               case 0x49:
               case 0x4D:
               {
                  var bitmapDecoder = new TiffBitmapDecoder(stream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);
                  m = bitmapDecoder.Frames[0];
                  bitmapDecoder = null;
               }
               break;

               default:
               {
                  Debug.WriteLine("WindowsPresentationImageProxy: unknown image format: " + type);
               }
               break;
            }

            if(m != null)
            {
               ret = new GMapImage();
               ret.Img = m;
               if(ret.Img.CanFreeze)
               {
                  ret.Img.Freeze();
               }
            }
             }
             return ret;
        }
        private static BitmapFrame GetBitmapFrame(string sourceFile, Stream s)
        {
            BitmapDecoder d;

            string extension = Path.GetExtension(sourceFile);
            switch (extension.ToLower())
            {
                case ".jpg":
                case ".jpeg":
                    d = new JpegBitmapDecoder(s, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
                    break;
                case ".gif":
                    d = new GifBitmapDecoder(s, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
                    break;
                case ".png":
                    d = new PngBitmapDecoder(s, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
                    break;
                case ".bmp":
                    d = new BmpBitmapDecoder(s, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
                    break;
                case ".tif":
                case ".tiff":
                    d = new TiffBitmapDecoder(s, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
                    break;
                default:
                    throw new InvalidDataException("Unsupported file extension " + extension);
            }

            BitmapFrame frame = d.Frames[0];

            return frame;
        }
Beispiel #11
0
 public override ImageData Read(Stream file, ImageMetaData info)
 {
     var decoder = new TiffBitmapDecoder (file,
         BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
     var frame = decoder.Frames[0];
     frame.Freeze();
     return new ImageData (frame, info);
 }
 public ReadExifInfo(string fileName, FileInfo file)
 {
     try
     {
         using (foto = File.Open(fileName, FileMode.Open, FileAccess.Read))
         {
             JpegBitmapDecoder jpegdecoder;
             PngBitmapDecoder pngdecoder;
             BmpBitmapDecoder bmpdecoder;
             GifBitmapDecoder gifdecoder;
             IconBitmapDecoder icondecoder;
             TiffBitmapDecoder tiffdecoder;
             WmpBitmapDecoder wmpdecoder;
                 
             switch(file.Extension.ToLower())
             {
                 case ".jpg":
                     jpegdecoder = new JpegBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)jpegdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".jpeg":
                     jpegdecoder = new JpegBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)jpegdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".png":
                     pngdecoder = new PngBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)pngdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".bmp":
                     bmpdecoder = new BmpBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)bmpdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".gif":
                     gifdecoder = new GifBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)gifdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".ico":
                     icondecoder = new IconBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)icondecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".tiff":
                     tiffdecoder = new TiffBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)tiffdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".wmp":
                     wmpdecoder = new WmpBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)wmpdecoder.Frames[0].Metadata.Clone();
                     break;
             }
             creationTime = Convert.ToDateTime(bm.DateTaken);
         }
     }
     catch (Exception ex) { WPF.MessageBox.Show(fileName + "\n" + ex.Message, "Decoder Exception"); }
 }
Beispiel #13
0
 private void GetBitmapSourceFromTiff(string fileRoute)
 {
     Stream imageStream = new FileStream(fileRoute, FileMode.Open, FileAccess.Read, FileShare.Read);
     var decoder = new TiffBitmapDecoder(imageStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
     BmSource = decoder.Frames[0];
     BitsPerPix = BmSource.Format.BitsPerPixel;
 }
Beispiel #14
0
        private BitmapSource LoadReference(string fileName)
        {
            var imageStreamSource = Assembly
                                  .GetExecutingAssembly()
                                  .GetManifestResourceStream(
                                      "NSane.Tests.images." + fileName + ".tiff");

            var decoder = new TiffBitmapDecoder(imageStreamSource,
                BitmapCreateOptions.PreservePixelFormat,
                BitmapCacheOption.Default);
            BitmapSource ret = decoder.Frames[0];
            return ret;
        }
        internal static BitmapDecoder CreateFromUriOrStream(
            Uri baseUri,
            Uri uri,
            Stream stream,
            BitmapCreateOptions createOptions,
            BitmapCacheOption cacheOption,
            RequestCachePolicy uriCachePolicy,
            bool insertInDecoderCache
            )
        {
            Guid clsId = Guid.Empty;
            bool isOriginalWritable = false;
            SafeMILHandle decoderHandle = null;
            BitmapDecoder cachedDecoder = null;
            Uri finalUri = null;
            Stream uriStream = null;
            UnmanagedMemoryStream unmanagedMemoryStream = null;
            SafeFileHandle safeFilehandle = null;

            // check to ensure that images are allowed in partial trust
            DemandIfImageBlocked();

            if (uri != null)
            {
                finalUri = (baseUri != null) ?
                               System.Windows.Navigation.BaseUriHelper.GetResolvedUri(baseUri, uri) :
                               uri;

                if (insertInDecoderCache)
                {
                    if ((createOptions & BitmapCreateOptions.IgnoreImageCache) != 0)
                    {
                        ImagingCache.RemoveFromDecoderCache(finalUri);
                    }

                    cachedDecoder = CheckCache(
                        finalUri,
                        out clsId
                        );
                }
            }

            // try to retrieve the cached decoder
            if (cachedDecoder != null)
            {
                decoderHandle = cachedDecoder.InternalDecoder;
            }
            else if ((finalUri != null) && (finalUri.IsAbsoluteUri) && (stream == null) &&
                     ((finalUri.Scheme == Uri.UriSchemeHttp) ||
                      (finalUri.Scheme == Uri.UriSchemeHttps)))
            {
                return new LateBoundBitmapDecoder(baseUri, uri, stream, createOptions, cacheOption, uriCachePolicy);
            }
            else if ((stream != null) && (!stream.CanSeek))
            {
                return new LateBoundBitmapDecoder(baseUri, uri, stream, createOptions, cacheOption, uriCachePolicy);
            }
            else
            {
                // Create an unmanaged decoder
                decoderHandle = BitmapDecoder.SetupDecoderFromUriOrStream(
                    finalUri,
                    stream,
                    cacheOption,
                    out clsId,
                    out isOriginalWritable,
                    out uriStream,
                    out unmanagedMemoryStream,
                    out safeFilehandle
                    );
            }

            BitmapDecoder decoder = null;

            // Find out the decoder type and wrap it appropriately and return that
            if (MILGuidData.GUID_ContainerFormatBmp == clsId)
            {
                decoder = new BmpBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatGif == clsId)
            {
                decoder = new GifBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatIco == clsId)
            {
                decoder = new IconBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatJpeg == clsId)
            {
                decoder = new JpegBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatPng == clsId)
            {
                decoder = new PngBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatTiff == clsId)
            {
                decoder = new TiffBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatWmp == clsId)
            {
                decoder = new WmpBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else
            {
                decoder = new UnknownBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }

            return decoder;
        }
Beispiel #16
0
 private void SetPages()
 {
     System.IO.FileStream fileStream = new FileStream(this.m_FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
     TiffBitmapDecoder tiffBitmapDecoder = new TiffBitmapDecoder(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
     for (int i = 0; i < tiffBitmapDecoder.Frames.Count; i++)
     {
         BitmapSource bitmapSource = tiffBitmapDecoder.Frames[i];
         YellowstonePathology.Business.TifDocumentPage tifDocumentPage = new TifDocumentPage();
         tifDocumentPage.BitmapImage = this.BitmapImageFromBitmapSource(bitmapSource);
         this.Pages.Add(tifDocumentPage);
     }
     fileStream.Close();
 }
Beispiel #17
0
        /// <summary>
        /// Encode image fingerprint to wsq file
        /// </summary>
        /// <param name="FileSource">File source (bmp,tiff)</param>
        /// <param name="FileDest">File wsq</param>
        /// <param name="comments">Comments in image</param>
        /// <param name="BitRate">Bit rate</param>
        public void EnconderFile(String FileSource, 
                                String FileDest, 
                                String[] comments, 
                                double BitRate)
        {
            try
            {
                switch (Path.GetExtension(FileSource).ToUpper())
                {
                    case ".BMP":
                    case ".TIF":
                        break;
                    default:
                        throw new ApplicationException("Error: FileSource extension no supported");

                }

                if (Path.GetExtension(FileDest).ToUpper().Replace(".", "") != "WSQ")
                {
                    throw new ApplicationException("Error: FileDest extension no supported");
                }

                Bitmap bm = null;
                System.Drawing.Image img = null;
                byte[] fileData;

                Wsqm.cBitmap bitmap;
                Wsqm.DataOutput data;
                BitmapSource bitmapSource;

                switch (Path.GetExtension(FileSource).ToUpper())
                {
                    case ".BMP":
                        img = System.Drawing.Image.FromFile(FileSource);
                        bm = new Bitmap(img);

                        Uri myUri = new Uri(FileSource, UriKind.RelativeOrAbsolute);
                        BmpBitmapDecoder decoder2 = new BmpBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        bitmapSource = decoder2.Frames[0];

                        fileData = GetBytesFromBitmapSource(bitmapSource);

                        bitmap = new Wsqm.cBitmap(fileData,
                                bm.Width,
                                bm.Height, 500, 8, 1);

                        data = new Wsqm.DataOutput();
                        data.RutaDestino = FileDest;

                        _EncoderWSQ.encode(data, bitmap, BitRate, comments);

                        img.Dispose();

                        break;
                    case ".TIF":
                        img = System.Drawing.Image.FromFile(FileSource);
                        bm = new Bitmap(img);

                        Stream imageStreamSource = new FileStream(FileSource, FileMode.Open, FileAccess.Read, FileShare.Read);
                        TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        bitmapSource = decoder.Frames[0];

                        fileData = GetBytesFromBitmapSource(bitmapSource);

                        bitmap = new Wsqm.cBitmap(fileData,
                                bm.Width,
                                bm.Height, 500, 8, 1);

                        data = new Wsqm.DataOutput();
                        data.RutaDestino = FileDest;
                        _EncoderWSQ.encode(data, bitmap, BitRate, comments);

                        img.Dispose();
                        imageStreamSource.Dispose();
                        break;

                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
Beispiel #18
0
        public static BitmapSource[] LoadSplitTiff(string fileName)
        {
            if (String.IsNullOrEmpty(fileName)) new ArgumentNullException("fileName");
            if (!System.IO.File.Exists(fileName)) throw new ArgumentException(String.Format("Soubor '{0}' neexistuje, nelze načíst TIFF soubor.", fileName));

            BitmapSource[] sources = null;

            using (var ms = new MemoryStream(File.ReadAllBytes(fileName)))
            {
                TiffBitmapDecoder decoder = new TiffBitmapDecoder(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                sources = decoder.Frames.ToArray<BitmapSource>();
                ms.Close();
            }

            return sources;
        }
Beispiel #19
0
        public void Load(string filename, FileTypes type)
        {
            Tags.Clear();
            Title = "";
            Description = "";
            City = "";
            Sublocation = "";
            Country = "";
            DateTaken = new DateTime(2000, 1, 1);
            FileName = filename;
            GeoLat = GeoLong = null;
            StarRating = 0;

            if (type == FileTypes.FileTypeUnknown)
            {
                if (filename.EndsWith(".jpg", System.StringComparison.CurrentCultureIgnoreCase))
                    type = FileTypes.FileTypeJpeg;
                else if (filename.EndsWith(".jpeg", System.StringComparison.CurrentCultureIgnoreCase))
                    type = FileTypes.FileTypeJpeg;
                else if (filename.EndsWith(".gif", System.StringComparison.CurrentCultureIgnoreCase))
                    type = FileTypes.FileTypeGIF;
                else if (filename.EndsWith(".png", System.StringComparison.CurrentCultureIgnoreCase))
                    type = FileTypes.FileTypePNG;
                else if (filename.EndsWith(".tif", System.StringComparison.CurrentCultureIgnoreCase))
                    type = FileTypes.FileTypeTiff;
                else if (filename.EndsWith(".tiff", System.StringComparison.CurrentCultureIgnoreCase))
                    type = FileTypes.FileTypeTiff;
                else if (filename.EndsWith(".bmp", System.StringComparison.CurrentCultureIgnoreCase))
                    type = FileTypes.FileTypeBmp;
            }

            try
            {
                Stream pictureStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
                BitmapMetadata bitmapMetadata;

                switch (type)
                {
                    case FileTypes.FileTypeJpeg:
                        JpegBitmapDecoder JpegDecoder = new JpegBitmapDecoder(pictureStream, BitmapCreateOptions.None, BitmapCacheOption.None);
                        bitmapMetadata = (BitmapMetadata)JpegDecoder.Frames[0].Metadata;

                        if (bitmapMetadata.Keywords != null)
                        {
                            foreach (string tag in bitmapMetadata.Keywords)
                                Tags.Add(tag);
                        }

                        Title = bitmapMetadata.Title;
                        Description = bitmapMetadata.Comment;
                        if (bitmapMetadata.DateTaken != null)
                            DateTaken = DateTime.Parse(bitmapMetadata.DateTaken);

                        //City = (string)bitmapMetadata.GetQuery(@"/xmp/<xmpbag>photoshop:City");
                        City = (string)bitmapMetadata.GetQuery(@"/app13/irb/8bimiptc/iptc/city");
                        if (City == null)
                            City = "";

                        Sublocation = (string)bitmapMetadata.GetQuery(@"/app13/irb/8bimiptc/iptc/sub-location");
                        if (Sublocation == null)
                            Sublocation = "";

                        //Country = (string)bitmapMetadata.GetQuery(@"/xmp/<xmpbag>photoshop:Country");
                        Country = (string)bitmapMetadata.GetQuery(@"/app13/irb/8bimiptc/iptc/country\/primary location name");
                        if (Country == null)
                            Country = "";

                        byte[] Version = (byte[])bitmapMetadata.GetQuery(@"/app1/ifd/gps/");
                        if (Version != null)
                        {
                            ulong[] GeoLatInfo = (ulong[])bitmapMetadata.GetQuery(@"/app1/ifd/gps/subifd:{ulong=2}");
                            string GeoLatDirection = (string)bitmapMetadata.GetQuery(@"/app1/ifd/gps/subifd:{char=1}");
                            ulong[] GeoLongInfo = (ulong[])bitmapMetadata.GetQuery(@"/app1/ifd/gps/subifd:{ulong=4}");
                            string GeoLongDirection = (string)bitmapMetadata.GetQuery(@"/app1/ifd/gps/subifd:{char=3}");

                            if (GeoLatInfo != null && GeoLatDirection != null)
                            {
                                GeoLat = ConvertCoordinate(GeoLatInfo);
                                if (GeoLatDirection == "S")
                                    GeoLat = -GeoLat;
                            }

                            if (GeoLongInfo != null && GeoLongDirection != null)
                            {
                                GeoLong = ConvertCoordinate(GeoLongInfo);
                                if (GeoLongDirection == "W")
                                    GeoLong = -GeoLong;
                            }
                        }

                        StarRating = bitmapMetadata.Rating;

                        break;

                    case FileTypes.FileTypeTiff:
                        TiffBitmapDecoder TiffDecoder = new TiffBitmapDecoder(pictureStream, BitmapCreateOptions.None, BitmapCacheOption.None);
                        bitmapMetadata = (BitmapMetadata)TiffDecoder.Frames[0].Metadata;

                        if (bitmapMetadata.Keywords != null)
                        {
                            foreach (string tag in bitmapMetadata.Keywords)
                                Tags.Add(tag);
                        }

                        Title = bitmapMetadata.Title;
                        Description = bitmapMetadata.Comment;
                        if (bitmapMetadata.DateTaken != null)
                            DateTaken = DateTime.Parse(bitmapMetadata.DateTaken);

                        StarRating = bitmapMetadata.Rating;

                        break;

                    case FileTypes.FileTypeGIF:
                        GifBitmapDecoder GifDecoder = new GifBitmapDecoder(pictureStream, BitmapCreateOptions.None, BitmapCacheOption.None);
                        bitmapMetadata = (BitmapMetadata)GifDecoder.Frames[0].Metadata;

                        if (bitmapMetadata.Keywords != null)
                        {
                            foreach (string tag in bitmapMetadata.Keywords)
                                Tags.Add(tag);
                        }

                        Title = bitmapMetadata.Title;
                        Description = bitmapMetadata.Comment;
                        if (bitmapMetadata.DateTaken != null)
                            DateTaken = DateTime.Parse(bitmapMetadata.DateTaken);

                        StarRating = bitmapMetadata.Rating;

                        break;

                    case FileTypes.FileTypePNG:
                        PngBitmapDecoder PngDecoder = new PngBitmapDecoder(pictureStream, BitmapCreateOptions.None, BitmapCacheOption.None);
                        bitmapMetadata = (BitmapMetadata)PngDecoder.Frames[0].Metadata;

                        if (bitmapMetadata.Keywords != null)
                        {
                            foreach (string tag in bitmapMetadata.Keywords)
                                Tags.Add(tag);
                        }

                        Title = bitmapMetadata.Title;
                        Description = bitmapMetadata.Comment;
                        if (bitmapMetadata.DateTaken != null)
                            DateTaken = DateTime.Parse(bitmapMetadata.DateTaken);

                        StarRating = bitmapMetadata.Rating;

                        break;

                    case FileTypes.FileTypeBmp:
                        BmpBitmapDecoder BmpDecoder = new BmpBitmapDecoder(pictureStream, BitmapCreateOptions.None, BitmapCacheOption.None);
                        bitmapMetadata = (BitmapMetadata)BmpDecoder.Frames[0].Metadata;

                        if (bitmapMetadata.Keywords != null)
                        {
                            foreach (string tag in bitmapMetadata.Keywords)
                                Tags.Add(tag);
                        }

                        Title = bitmapMetadata.Title;
                        Description = bitmapMetadata.Comment;
                        if (bitmapMetadata.DateTaken != null)
                            DateTaken = DateTime.Parse(bitmapMetadata.DateTaken);

                        StarRating = bitmapMetadata.Rating;

                        break;
                }

                pictureStream.Close();
            }
            catch (Exception)
            {
            }

            if (Title == null) Title = "";
            if (Description == null) Description = "";
        }
Beispiel #20
0
        public void initFileListFromStack(string path)
        {
            if (Directory.Exists(path))
            {
                filePathListTIFF = new List<string>();
                filePathsTIFF = System.IO.Directory.GetFiles(path, "*.tif", SearchOption.TopDirectoryOnly);

                for (int i = 0; i < filePathsTIFF.Length; i++)
                {
                    filePathListTIFF.Add(filePathsTIFF[i].ToString());
                }

                filePathListBMP = new List<string>();
                filePathsBMP = System.IO.Directory.GetFiles(path, "*.bmp", SearchOption.TopDirectoryOnly);

                for (int i = 0; i < filePathsBMP.Length; i++)
                {
                    filePathListBMP.Add(filePathsBMP[i].ToString());
                }

                if (filePathListBMP.Count == 0)
                {
                    throw new ProjectException("Die gewählte Projektdatei enthält keine Bitmaps");
                }

                if (filePathListBMP.Count != filePathListTIFF.Count)
                {
                    throw new ProjectException("Differenz von TIF und BMP-Dateien in Projektdatei");
                }

                if (filePathListTIFF.Count() != 0)
                {
                    totalLayers = filePathListTIFF.Count();

                    try
                    {
                        FileStream imgStream = new FileStream(this.getPictureFromList(0), FileMode.Open, FileAccess.Read, FileShare.Read);
                        TiffBitmapDecoder decoder = new TiffBitmapDecoder(imgStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        BitmapSource bmpSrc = decoder.Frames[0];

                        ImgHeight = bmpSrc.PixelHeight;
                        ImgWidth = bmpSrc.PixelWidth;
                    }
                    catch (Exception e)
                    {
                        throw new ProjectException("Fehler bei der Bildstapelverarbeitung\n" + e.Message);
                    }
                }
                else
                {
                    throw new ProjectException("Der gewählte Ordner enthält keine *.tif Dateien");
                }
            }
            else
            {
                throw new ProjectException("Der ausgewählte Ordner konnte nicht gefunden werden");
            }
        }
		private void ReadFile()
		{
			// Open a Stream and decode a TIFF image
			_imageStreamSource = new FileStream(_filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
			_tiffDecoder = new TiffBitmapDecoder(_imageStreamSource,
				BitmapCreateOptions.PreservePixelFormat,
				BitmapCacheOption.Default);

			_page = 0;
			Image = _tiffDecoder.Frames[0];
			_maxPages = _tiffDecoder.Frames.Count - 1;
			PageFlipedOrImageChanged();
		}
        private static BitmapSource Load(object obj, BitmapEncoding enc, 
            BitmapCreateOptions create, BitmapCacheOption cache, out BitmapMetadata data)
        {
            BitmapDecoder dec = null;

            if (obj is Stream)
            {
                Stream stream = obj as Stream;

                switch (enc)
                {
                    case BitmapEncoding.Bmp:
                        dec = new BmpBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Png:
                        dec = new PngBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Jpg:
                        dec = new JpegBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Tiff:
                        dec = new TiffBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Gif:
                        dec = new GifBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Wmp:
                        dec = new WmpBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Icon:
                        dec = new IconBitmapDecoder(stream, create, cache);
                        break;
                    default:
                        throw new NotImplementedException();
                }
            }
            else if (obj is Uri)
            {
                Uri stream = obj as Uri;

                switch (enc)
                {
                    case BitmapEncoding.Bmp:
                        dec = new BmpBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Png:
                        dec = new PngBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Jpg:
                        dec = new JpegBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Tiff:
                        dec = new TiffBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Gif:
                        dec = new GifBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Wmp:
                        dec = new WmpBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Icon:
                        dec = new IconBitmapDecoder(stream, create, cache);
                        break;
                    default:
                        throw new NotImplementedException();
                }
            }
            else
                throw new ArgumentException();

            data = dec.Metadata;
            return dec.Frames[0];
        }
Beispiel #23
0
 public static BitmapSource getImgFromPath(string path)
 {
     Stream imgStreamSource = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
     TiffBitmapDecoder decoder = new TiffBitmapDecoder(imgStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
     return decoder.Frames[0];
 }
Beispiel #24
0
        private void CreateAndShowMainWindow()
        {
            // Create the application's main window
            _mainWindow = new Window {Title = "TIFF Imaging Sample"};
            var mySv = new ScrollViewer();

            var width = 128;
            var height = width;
            var stride = width/8;
            var pixels = new byte[height*stride];

            // Define the image palette
            var myPalette = BitmapPalettes.WebPalette;

            // Creates a new empty image with the pre-defined palette

            var image = BitmapSource.Create(
                width,
                height,
                96,
                96,
                PixelFormats.Indexed1,
                myPalette,
                pixels,
                stride);

            var stream = new FileStream("new.tif", FileMode.Create);
            var encoder = new TiffBitmapEncoder();
            var myTextBlock = new TextBlock {Text = "Codec Author is: " + encoder.CodecInfo.Author};
            encoder.Compression = TiffCompressOption.Zip;
            encoder.Frames.Add(BitmapFrame.Create(image));
            encoder.Save(stream);

            // Open a Stream and decode a TIFF image
            Stream imageStreamSource = new FileStream("tulipfarm.tif", FileMode.Open, FileAccess.Read, FileShare.Read);
            var decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat,
                BitmapCacheOption.Default);
            BitmapSource bitmapSource = decoder.Frames[0];

            // Draw the Image
            var myImage = new Image
            {
                Source = bitmapSource,
                Stretch = Stretch.None,
                Margin = new Thickness(20)
            };

            // Open a Uri and decode a TIFF image
            var myUri = new Uri("tulipfarm.tif", UriKind.RelativeOrAbsolute);
            var decoder2 = new TiffBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat,
                BitmapCacheOption.Default);
            BitmapSource bitmapSource2 = decoder2.Frames[0];

            // Draw the Image
            var myImage2 = new Image
            {
                Source = bitmapSource2,
                Stretch = Stretch.None,
                Margin = new Thickness(20)
            };

            // Define a StackPanel to host the decoded TIFF images
            var myStackPanel = new StackPanel
            {
                Orientation = Orientation.Vertical,
                VerticalAlignment = VerticalAlignment.Stretch,
                HorizontalAlignment = HorizontalAlignment.Stretch
            };

            // Add the Image and TextBlock to the parent Grid
            myStackPanel.Children.Add(myImage);
            myStackPanel.Children.Add(myImage2);
            myStackPanel.Children.Add(myTextBlock);

            // Add the StackPanel as the Content of the Parent Window Object
            mySv.Content = myStackPanel;
            _mainWindow.Content = mySv;
            _mainWindow.Show();
        }
Beispiel #25
0
 public object ReadTif(Stream stream)
 {
     var decoder = new TiffBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
     return decoder.Frames[0].Clone();
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            Assembly caller = Assembly.GetEntryAssembly();
            var obj = caller.GetType(ClassName).GetProperty(ResourceName, BindingFlags.Static | BindingFlags.NonPublic);
            if (obj != null)
            {
                var val = obj.GetValue(obj, null);
                if (val != null)
                {
                    MemoryStream mstr = new MemoryStream();
                    BitmapDecoder decoder = null;

                    if (val is Icon)
                    {
                        ((Icon)val).Save(mstr);
                        decoder = new IconBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);

                    }
                    else if (val is Bitmap)
                    {
                        Bitmap bmp = val as Bitmap;
                        if (ImageFormat == ImageFormat.Png)
                        {
                            bmp.Save(mstr, ImageFormat.Png);
                            decoder = new PngBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);
                        }
                        else if (ImageFormat == ImageFormat.Tiff)
                        {
                            bmp.Save(mstr, ImageFormat.Tiff);
                            decoder = new TiffBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);
                        }
                        else if (ImageFormat == ImageFormat.Gif)
                        {
                            bmp.Save(mstr, ImageFormat.Gif);
                            decoder = new GifBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);
                        }
                        else if (ImageFormat == ImageFormat.Jpeg)
                        {
                            bmp.Save(mstr, ImageFormat.Jpeg);
                            decoder = new JpegBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);
                        }
                        else if (ImageFormat == ImageFormat.Bmp)
                        {
                            bmp.Save(mstr, ImageFormat.Bmp);
                            decoder = new BmpBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);
                        }
                    }

                    if (decoder != null)
                    {
                        return decoder.Frames[0];
                    }
                }

                return null;
            }
            else
            {
                return null;
            }
        }
Beispiel #27
-1
        private void Load_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialogue = new OpenFileDialog()
            {
                Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif|JPEG Image (.jpeg)|*.jpeg|Png Image (.png)|*.png|Tiff Image (.tiff)|*.tiff|Wmf Image (.wmf)|*.wmf"
            };

            if (openFileDialogue.ShowDialog() == true)
            {
                Stream imageStreamSource = new FileStream(openFileDialogue.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                BitmapDecoder decoder;
                #region Decoding
                string extension = System.IO.Path.GetExtension(openFileDialogue.FileName);
                switch (extension.ToLower())
                {
                    case ".jpeg":
                        decoder = new JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;
                    case ".png":
                        decoder = new PngBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;
                    case ".gif":
                        decoder = new GifBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;
                    case ".tiff":
                        decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;
                    case ".wmf":
                        decoder = new WmpBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;
                    case ".bmp":
                        decoder = new BmpBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;
                    default:
                        return;
                }
                #endregion
                BitmapSource LoadedBitmap = decoder.Frames[0];
                MyCanvas.Children.Clear();
                MyCanvas.Width = LoadedBitmap.Width;
                MyCanvas.Height = LoadedBitmap.Height;
                MyCanvas.Children.Add(
                            new Image() { Source = LoadedBitmap }
                        );

            }
        }