@@ -12,11 +12,9 @@ public class SerializableBitmapImage : ISerializable
12
12
public BitmapSource bitmapSource ;
13
13
private readonly string expression ;
14
14
15
- public BitmapImage Image { get ; private set ; }
16
-
17
15
public SerializableBitmapImage ( BitmapImage image )
18
16
{
19
- this . Image = image ;
17
+ bitmapSource = image ;
20
18
}
21
19
22
20
public SerializableBitmapImage ( BitmapSource source )
@@ -37,12 +35,14 @@ protected SerializableBitmapImage(SerializationInfo info, StreamingContext conte
37
35
var stream = new MemoryStream ( array ) ;
38
36
stream . Seek ( 0 , SeekOrigin . Begin ) ;
39
37
40
- Image = new BitmapImage ( ) ;
41
- Image . CacheOption = BitmapCacheOption . OnLoad ;
42
- Image . BeginInit ( ) ;
43
- Image . StreamSource = stream ;
44
- Image . EndInit ( ) ;
45
- Image . Freeze ( ) ;
38
+ var bitmapImage = new BitmapImage ( ) ;
39
+ bitmapImage . CacheOption = BitmapCacheOption . OnLoad ;
40
+ bitmapImage . BeginInit ( ) ;
41
+ bitmapImage . StreamSource = stream ;
42
+ bitmapImage . EndInit ( ) ;
43
+ bitmapImage . Freeze ( ) ;
44
+
45
+ bitmapSource = bitmapImage ;
46
46
}
47
47
}
48
48
catch ( ExternalException )
@@ -78,28 +78,26 @@ public static implicit operator SerializableBitmapImage(BitmapImage bitmapImage)
78
78
79
79
public static implicit operator BitmapImage ( SerializableBitmapImage serializableBitmapImage )
80
80
{
81
- return serializableBitmapImage . Image ;
81
+ return ( BitmapImage ) serializableBitmapImage . bitmapSource ;
82
82
}
83
83
84
84
//[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
85
85
void ISerializable . GetObjectData ( SerializationInfo info , StreamingContext context )
86
86
{
87
- var source = Image ?? bitmapSource ;
88
-
89
- if ( source != null )
87
+ if ( bitmapSource != null )
90
88
{
91
89
using ( var memoryStream = new MemoryStream ( ) )
92
90
{
93
91
var encoder = new PngBitmapEncoder ( ) ;
94
92
//TODO try/catch
95
- encoder . Frames . Add ( BitmapFrame . Create ( source ) ) ;
93
+ encoder . Frames . Add ( BitmapFrame . Create ( bitmapSource ) ) ;
96
94
encoder . Save ( memoryStream ) ;
97
95
memoryStream . Seek ( 0 , SeekOrigin . Begin ) ;
98
96
99
97
info . AddValue ( "Image" , memoryStream . ToArray ( ) , typeof ( byte [ ] ) ) ;
100
98
}
101
99
102
- info . AddValue ( "Name" , source . ToString ( ) ) ;
100
+ info . AddValue ( "Name" , bitmapSource . ToString ( ) ) ;
103
101
}
104
102
}
105
103
0 commit comments