Пример #1
0
        public static BitmapSource ToImage(byte[] arg, TypeImagen tipo) {
            BitmapSource temporigen = null;
            if(arg != null){
                System.IO.MemoryStream ms = new System.IO.MemoryStream(arg);

                switch (tipo)
                {
                    case TypeImagen.BMP:

                        BmpBitmapDecoder bmpdeco = new BmpBitmapDecoder(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        temporigen = bmpdeco.Frames[0];
                        break;
                    case TypeImagen.JPG:
                        
                        JpegBitmapDecoder jpgdeco = new JpegBitmapDecoder(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        temporigen = jpgdeco.Frames[0];
                        break;
                }
            }
            return temporigen;
        }
Пример #2
0
 public static byte[] GetArray(BitmapSource source, TypeImagen tipo){
     if (source != null){
         System.IO.MemoryStream ms = new System.IO.MemoryStream();
         switch (tipo){
             case TypeImagen.BMP:
                 BmpBitmapEncoder bmpenco = new BmpBitmapEncoder();    
                 bmpenco.Frames.Add(BitmapFrame.Create(source));
                 bmpenco.Save(ms);
                 break;
             case TypeImagen.JPG:
                 JpegBitmapEncoder jpgenco = new JpegBitmapEncoder();
                 jpgenco.Frames.Add(BitmapFrame.Create(source));
                 jpgenco.Save(ms);
                 break;
         }
         ms.Flush();
         return ms.ToArray();
     }
     else{
         return new byte[0];
     }
 }