internal void Init () { if (NativeRef == null) { NativeRef = new NativeImageRef (Backend, ToolkitEngine); } else NativeRef.AddReference (); }
/// <summary> /// Creates a new image that is a copy of another image /// </summary> /// <param name="image">Image.</param> public Image(Image image) : base(image.Backend, image.ToolkitEngine) { NativeRef = image.NativeRef; requestedSize = image.requestedSize; requestedAlpha = image.requestedAlpha; styles = image.styles; Init(); }
/// <summary> /// Creates a new image that is a copy of another image /// </summary> /// <param name="image">Image.</param> public Image (Image image): base (image.Backend, image.ToolkitEngine) { NativeRef = image.NativeRef; requestedSize = image.requestedSize; requestedAlpha = image.requestedAlpha; styles = image.styles; Init (); }
internal void Init() { if (NativeRef == null) { NativeRef = new NativeImageRef(Backend, ToolkitEngine); } else { NativeRef.AddReference(); } }
void MakeWrittable () { // If the bitmap only has one reference, that reference is the one held by this instance, so // no other image is referencing this one. In that case, the bitmap can be safely modified. // On the other hand, if the bitmap is being referenced by another image, an local copy // has to be made if (NativeRef.ReferenceCount > 1) { Backend = ToolkitEngine.ImageBackendHandler.CopyBitmap (Backend); NativeRef.ReleaseReference (true); NativeRef = new NativeImageRef (Backend, ToolkitEngine); } }
void MakeWrittable() { // If the bitmap only has one reference, that reference is the one held by this instance, so // no other image is referencing this one. In that case, the bitmap can be safely modified. // On the other hand, if the bitmap is being referenced by another image, an local copy // has to be made if (NativeRef.ReferenceCount > 1) { Backend = ToolkitEngine.ImageBackendHandler.CopyBitmap(Backend); NativeRef.ReleaseReference(true); NativeRef = new NativeImageRef(Backend, ToolkitEngine); } }
public NativeImageRef LoadForToolkit(Toolkit targetToolkit) { if (Toolkit == targetToolkit) { return(this); } NativeImageRef newRef = null; var r = NextRef; while (r != this) { if (r.toolkit == targetToolkit) { newRef = r; break; } r = r.NextRef; } if (newRef != null) { return(newRef); } object newBackend = null; if (sources != null) { var frames = new List <object> (); foreach (var s in sources) { if (s.ImageLoader != null) { var streams = s.ImageLoader(); try { if (streams.Length == 1) { newBackend = targetToolkit.ImageBackendHandler.LoadFromStream(streams [0]); } else { var backends = new object [streams.Length]; for (int n = 0; n < backends.Length; n++) { backends [n] = targetToolkit.ImageBackendHandler.LoadFromStream(streams [n]); } newBackend = targetToolkit.ImageBackendHandler.CreateMultiResolutionImage(backends); } } finally { foreach (var st in streams) { st.Dispose(); } } } else if (s.CustomImageLoader != null) { targetToolkit.Invoke(() => newBackend = Image.FromCustomLoader(s.CustomImageLoader, s.Source, s.Tags).GetBackend()); } else if (s.ResourceAssembly != null) { targetToolkit.Invoke(() => newBackend = Image.FromResource(s.ResourceAssembly, s.Source).GetBackend()); } else if (s.Source != null) { targetToolkit.Invoke(() => newBackend = Image.FromFile(s.Source).GetBackend()); } else if (s.DrawCallback != null) { newBackend = targetToolkit.ImageBackendHandler.CreateCustomDrawn(s.DrawCallback); } else if (s.StockId != null) { newBackend = targetToolkit.GetStockIcon(s.StockId).GetBackend(); } else { throw new NotSupportedException(); } frames.Add(newBackend); } newBackend = targetToolkit.ImageBackendHandler.CreateMultiSizeIcon(frames); } else { using (var s = new MemoryStream()) { toolkit.ImageBackendHandler.SaveToStream(backend, s, ImageFileType.Png); s.Position = 0; newBackend = targetToolkit.ImageBackendHandler.LoadFromStream(s); } } newRef = new NativeImageRef(newBackend, targetToolkit); newRef.NextRef = NextRef; NextRef = newRef; return(newRef); }
/// <summary> /// Creates a new image that is a copy of another image /// </summary> /// <param name="image">Image.</param> public Image(Image image) : base(image.Backend, image.ToolkitEngine) { NativeRef = image.NativeRef; Init(); }
public NativeImageRef LoadForToolkit(Toolkit targetToolkit) { NativeImageRef newRef = null; var r = NextRef; while (r != this) { if (r.toolkit == targetToolkit) { newRef = r; break; } r = r.NextRef; } if (newRef != null) return newRef; object newBackend; if (sources != null) { var frames = new List<object> (); foreach (var s in sources) { if (s.ImageLoader != null) { var streams = s.ImageLoader (); try { if (streams.Length == 1) { newBackend = targetToolkit.ImageBackendHandler.LoadFromStream (streams [0]); } else { var backends = new object[streams.Length]; for (int n = 0; n < backends.Length; n++) { backends [n] = targetToolkit.ImageBackendHandler.LoadFromStream (streams [n]); } newBackend = targetToolkit.ImageBackendHandler.CreateMultiResolutionImage (backends); } } finally { foreach (var st in streams) st.Dispose (); } } else if (s.ResourceAssembly != null) newBackend = targetToolkit.ImageBackendHandler.LoadFromResource (s.ResourceAssembly, s.Source); else if (s.Source != null) newBackend = targetToolkit.ImageBackendHandler.LoadFromFile (s.Source); else if (s.DrawCallback != null) newBackend = targetToolkit.ImageBackendHandler.CreateCustomDrawn (s.DrawCallback); else if (s.StockId != null) newBackend = targetToolkit.GetStockIcon (s.StockId).GetBackend (); else throw new NotSupportedException (); frames.Add (newBackend); } newBackend = targetToolkit.ImageBackendHandler.CreateMultiSizeIcon (frames); } else { using (var s = new MemoryStream ()) { toolkit.ImageBackendHandler.SaveToStream (backend, s, ImageFileType.Png); s.Position = 0; newBackend = targetToolkit.ImageBackendHandler.LoadFromStream (s); } } newRef = new NativeImageRef (newBackend, targetToolkit); newRef.NextRef = NextRef; NextRef = newRef; return newRef; }
/// <summary> /// Creates a new image that is a copy of another image /// </summary> /// <param name="image">Image.</param> public Image(Image image) : base(image.Backend, image.ToolkitEngine) { NativeRef = image.NativeRef; Init (); }