Changeset 1849


Ignore:
Timestamp:
Aug 20, 2010, 6:24:42 PM (11 years ago)
Author:
kopal
Message:
  • pictures on workspaces will be now converted into jpeg format
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/WorkspaceManager/Model/ImageModel.cs

    r1847 r1849  
    77using System.Windows.Media;
    88using System.Windows.Controls;
    9 
    109
    1110namespace WorkspaceManager.Model
     
    2322
    2423        /// <summary>
    25         /// Get the BitmapImage represented by this ImageModel
     24        /// Get the Image stored by this ImageModel
    2625        /// </summary>
    2726        /// <returns></returns>
     
    3433            }
    3534
    36             image.Source = BitmapImage.Create(width,
    37                           height,
    38                           96,
    39                           96,
    40                           System.Windows.Media.PixelFormats.Bgr32,
    41                           null,
    42                           data,
    43                           stride);
     35            MemoryStream stream = new MemoryStream(this.data);
     36            JpegBitmapDecoder decoder = new JpegBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
     37            BitmapFrame frame = decoder.Frames.First();
     38            image.Source = frame;           
    4439            return image;
    4540        }
     
    5449        /// <summary>
    5550        /// Instantiate a new ImageModel
     51        /// Loads the image from the imgUri and converts it into a jpeg
     52        /// Afterwards the data are stored in an internal byte array
    5653        /// </summary>
    5754        /// <param name="imageSource"></param>
     
    6461
    6562            BitmapImage bmpImage = new BitmapImage(imgUri) ;
    66             height = bmpImage.PixelHeight;
    67             width = bmpImage.PixelWidth;
    68             PixelFormat format = bmpImage.Format;
    69             stride = width * ((format.BitsPerPixel + 7) / 8);           
    70             byte[] byteImage = new byte[height * stride];
    71             bmpImage.CopyPixels(byteImage, stride, 0);
    72 
    73             this.data = byteImage;
     63            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
     64            encoder.Frames.Add(BitmapFrame.Create(bmpImage));
     65            MemoryStream stream = new MemoryStream();
     66            encoder.Save(stream);
     67            this.data = stream.ToArray();
     68            stream.Close();
    7469        }
    7570    }
Note: See TracChangeset for help on using the changeset viewer.