private Bitmap ReadInput(BitmapPinRequest req) { Bitmap bmp; Stopwatch sw = new Stopwatch(); sw.Start(); bmp = inputPin.Read <Bitmap>(req); sw.Stop(); renderTime = sw.ElapsedTicks / (double)Stopwatch.Frequency * 1000; return(bmp); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName) && (cachedBmp == null || cachedBmpName != fileName)) { try { cachedBmp = new Bitmap(fileName); cachedBmpName = fileName; } catch { if (cachedSizedBmp != null) { cachedSizedBmp.Dispose(); } if (cachedBmp != null) { cachedBmp.Dispose(); } cachedSizedBmp = null; cachedBmp = null; cachedBmpName = null; } } if (cachedBmp != null) { BitmapPinRequest bp = request as BitmapPinRequest; if (bp != null) { if (cachedSizedBmp != null) { lock (cachedSizedBmp) { if (cachedSizedBmp.Size == bp.DesiredSize) { return(new Bitmap(cachedSizedBmp)); } else { cachedSizedBmp.Dispose(); cachedSizedBmp = null; } } } Debug.Print("Recaching bitmap {0}", bp.DesiredSize); cachedSizedBmp = new Bitmap(cachedBmp, bp.DesiredSize); return(new Bitmap(cachedSizedBmp)); } return(new Bitmap(cachedBmp)); } } return(null); }
void DoUpdate(Object obj) { if (busyUpdating) { return; } lock (inputPin) { busyUpdating = true; BitmapPinRequest req = new BitmapPinRequest(); req.Time = (DateTime.Now - startTime).TotalSeconds; req.DesiredSize = desiredSize; Bitmap bmp = ReadInput(req); bitmapWin.PBitmap = bmp; bitmapWin.Invalidate(); busyUpdating = false; } }