source: trunk/CrypPlugins/WorkspaceManager/Model/ImageModel.cs @ 1842

Last change on this file since 1842 was 1842, checked in by kopal, 11 years ago
  • removed event bug of PluginModel which made saving unable to workspace
  • added new Models:
    • TextModel - represents a Text which can be put onto the workspace
    • ImageModel - represents an Image which can be put onto the workspace
File size: 1.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Media.Imaging;
6using System.IO;
7using System.Windows.Controls;
8
9namespace WorkspaceManager.Model
10{
11    /// <summary>
12    /// This class wraps a image which can be put onto the workspace
13    /// </summary>
14    public class ImageModel : VisualElementModel
15    {
16        private byte[] data = null;
17
18        /// <summary>
19        /// Get the BitmapImage represented by this ImageModel
20        /// </summary>
21        /// <param name="bytes"></param>
22        /// <returns></returns>
23        public BitmapImage getImage(Byte[] bytes)
24        {
25            MemoryStream stream = new MemoryStream(bytes);
26            BitmapImage image = new BitmapImage();
27            image.BeginInit();
28            image.StreamSource = stream;
29            image.EndInit();
30            return image;
31        }
32
33        /// <summary>
34        /// Instantiate a new ImageModel
35        /// </summary>
36        /// <param name="imageSource"></param>
37        public ImageModel(Uri imgUri)
38        {
39            BitmapImage img = new BitmapImage(imgUri);
40            Stream stream = img.StreamSource;
41            Byte[] buffer = null;
42            if (stream != null && stream.Length > 0)
43            {
44                using (BinaryReader br = new BinaryReader(stream))
45                {
46                    buffer = br.ReadBytes((Int32)stream.Length);
47                }
48            }
49
50            this.data = buffer;
51        }
52    }
53}
Note: See TracBrowser for help on using the repository browser.