private int Add(string id, BitmapProvider provider) { lock (this) { Task <ManagedBitmap> bitmap = new Task <ManagedBitmap>( delegate() { try { return(provider()); } catch (Exception exception) { if (EnableTrace) { Program.Log(LogCat.Cache, String.Format( "{0} ImageCache: provider threw exception: {2}{1}", DateTime.Now, Environment.NewLine, exception)); } } return(ManagedBitmap.CreateFromGDI(new Bitmap(Properties.Resources.InvalidPlaceHolder))); }); Entry entry = new Entry(id, bitmap); entry.BitmapCompleted += delegate(object sender, EventArgs args) { SwapOutOverLimit(); }; entries.Insert(0, entry); Trace("add", entry); PurgeDisposeList(); return(0); } }
public ManagedBitmap CreateTile(ManagedBitmap source, int offsetX, int offsetY, int drawWidth, int drawHeight, int targetWidth, int targetHeight, Profile profile) { EnsureStarted(profile); ManagedBitmap result; string mapId; int width, height; Profile serverProfile; bool succeeded = false; profile.Push("Remote call"); ClientServerCommunication.SendMessage( null /*log*/, channel, ClientServerCommunication.Commands.CreateTileGDI, new object[] { (int)Thread.CurrentThread.Priority, (string)source.BackingName, (int)source.Width, (int)source.Height, (int)offsetX, (int)offsetY, (int)drawWidth, (int)drawHeight, (int)targetWidth, (int)targetHeight }); try { ClientServerCommunication.WaitForPending(channel, out serverProfile, out mapId, out width, out height); profile.Add(serverProfile); result = new ManagedBitmap32(width, height, mapId); succeeded = true; } catch (ClientServerCommunication.RemoteException) { result = ManagedBitmap.CreateFromGDI(new Bitmap(Properties.Resources.InvalidPlaceHolder)); } profile.Pop(); if (succeeded) { profile.Push("Remote call"); ClientServerCommunication.SendMessage( null /*log*/, channel, ClientServerCommunication.Commands.Clear, null); ClientServerCommunication.WaitForDone(channel, out serverProfile); profile.Add(serverProfile); profile.Pop(); } return(result); }
public ManagedBitmap LoadAndOrientGDI(string path, int rightRotations, Profile profile, out RotateFlipType exifOrientation) { EnsureStarted(profile); exifOrientation = RotateFlipType.RotateNoneFlipNone; ManagedBitmap result; string mapId; int width, height; Profile serverProfile; bool succeeded = false; profile.Push("Remote call"); ClientServerCommunication.SendMessage( null /*log*/, channel, ClientServerCommunication.Commands.LoadAndOrientGDI, new object[] { (int)Thread.CurrentThread.Priority, (string)path, (int)rightRotations, }); try { object[] extra = ClientServerCommunication.WaitForPending(channel, out serverProfile, out mapId, out width, out height); exifOrientation = (RotateFlipType)(int)extra[0]; profile.Add(serverProfile); result = new ManagedBitmap32(width, height, mapId); succeeded = true; } catch (ClientServerCommunication.RemoteException) { result = ManagedBitmap.CreateFromGDI(new Bitmap(Properties.Resources.InvalidPlaceHolder)); } profile.Pop(); if (succeeded) { profile.Push("Remote call"); ClientServerCommunication.SendMessage( null /*log*/, channel, ClientServerCommunication.Commands.Clear, null); ClientServerCommunication.WaitForDone(channel, out serverProfile); profile.Add(serverProfile); profile.Pop(); } return(result); }
public ManagedBitmap AsManaged(Profile profile = null) { bool pop = false; try { if (managedBitmap != null) { return(managedBitmap); } if (profile != null) { profile.Push("SmartBitmap.AsManaged"); pop = true; } if (gdiBitmap != null) { managedBitmap = ManagedBitmap.CreateFromGDI(gdiBitmap); gdiBitmap.Dispose(); gdiBitmap = null; return(managedBitmap); } if (wpfBitmap != null) { managedBitmap = new ManagedBitmap32(wpfBitmap); wpfBitmap = null; return(managedBitmap); } } finally { if ((profile != null) && pop) { profile.Pop(); } } Debug.Assert(false); throw new InvalidOperationException(); }