dev
Révision | f45799bb2490dc74a62102c4ade4dc737fbd5057 (tree) |
---|---|
l'heure | 2014-01-21 09:24:37 |
Auteur | Kimura Youichi <kim.upsilon@bucy...> |
Commiter | Kimura Youichi |
MemoryImageにCloneメソッドを実装
@@ -38,7 +38,7 @@ namespace OpenTween | ||
38 | 38 | /// Image.FromStream() を使用して Image を生成する場合、 |
39 | 39 | /// Image を破棄するまでの間は元となった Stream を破棄できないためその対策として使用する。 |
40 | 40 | /// </remarks> |
41 | - public class MemoryImage : IDisposable | |
41 | + public class MemoryImage : ICloneable, IDisposable | |
42 | 42 | { |
43 | 43 | public readonly Stream Stream; |
44 | 44 | public readonly Image Image; |
@@ -80,6 +80,16 @@ namespace OpenTween | ||
80 | 80 | this.Stream = stream; |
81 | 81 | } |
82 | 82 | |
83 | + public MemoryImage Clone() | |
84 | + { | |
85 | + return MemoryImage.CopyFromStream(this.Stream); | |
86 | + } | |
87 | + | |
88 | + public object ICloneable.Clone() | |
89 | + { | |
90 | + return this.Clone(); | |
91 | + } | |
92 | + | |
83 | 93 | protected virtual void Dispose(bool disposing) |
84 | 94 | { |
85 | 95 | if (this.disposed) return; |
@@ -120,12 +130,8 @@ namespace OpenTween | ||
120 | 130 | { |
121 | 131 | var memstream = new MemoryStream(); |
122 | 132 | |
123 | - var buffer = new byte[1024]; | |
124 | - int length; | |
125 | - while ((length = stream.Read(buffer, 0, buffer.Length)) > 0) | |
126 | - { | |
127 | - memstream.Write(buffer, 0, length); | |
128 | - } | |
133 | + stream.CopyTo(memstream); | |
134 | + memstream.Seek(0, SeekOrigin.Begin); | |
129 | 135 | |
130 | 136 | return new MemoryImage(memstream); |
131 | 137 | } |