예제 #1
0
파일: Image.cs 프로젝트: m13253/xwt
		internal void Init ()
		{
			if (NativeRef == null) {
				NativeRef = new NativeImageRef (Backend, ToolkitEngine);
			} else
				NativeRef.AddReference ();
		}
예제 #2
0
파일: Image.cs 프로젝트: git-thinh/limada
 /// <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();
 }
예제 #3
0
파일: Image.cs 프로젝트: TheBrainTech/xwt
		/// <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 ();
		}
예제 #4
0
파일: Image.cs 프로젝트: git-thinh/limada
 internal void Init()
 {
     if (NativeRef == null)
     {
         NativeRef = new NativeImageRef(Backend, ToolkitEngine);
     }
     else
     {
         NativeRef.AddReference();
     }
 }
예제 #5
0
파일: BitmapImage.cs 프로젝트: m13253/xwt
		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);
			}
		}
예제 #6
0
        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);
            }
        }
예제 #7
0
파일: Image.cs 프로젝트: git-thinh/limada
        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);
        }
예제 #8
0
 /// <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();
 }
예제 #9
0
        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;
        }
예제 #10
0
 /// <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 ();
 }