• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

dev


Commit MetaInfo

Révisionf45799bb2490dc74a62102c4ade4dc737fbd5057 (tree)
l'heure2014-01-21 09:24:37
AuteurKimura Youichi <kim.upsilon@bucy...>
CommiterKimura Youichi

Message de Log

MemoryImageにCloneメソッドを実装

Change Summary

Modification

--- a/OpenTween/MemoryImage.cs
+++ b/OpenTween/MemoryImage.cs
@@ -38,7 +38,7 @@ namespace OpenTween
3838 /// Image.FromStream() を使用して Image を生成する場合、
3939 /// Image を破棄するまでの間は元となった Stream を破棄できないためその対策として使用する。
4040 /// </remarks>
41- public class MemoryImage : IDisposable
41+ public class MemoryImage : ICloneable, IDisposable
4242 {
4343 public readonly Stream Stream;
4444 public readonly Image Image;
@@ -80,6 +80,16 @@ namespace OpenTween
8080 this.Stream = stream;
8181 }
8282
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+
8393 protected virtual void Dispose(bool disposing)
8494 {
8595 if (this.disposed) return;
@@ -120,12 +130,8 @@ namespace OpenTween
120130 {
121131 var memstream = new MemoryStream();
122132
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);
129135
130136 return new MemoryImage(memstream);
131137 }