public void Draw(Graphics g, Ink.Renderer renderer) { if (renderer == null) { throw new NullReferenceException("cannot draw with null renderer"); } for (int i = 0; i < NUM_DRAW_ATTEMPTS; i++) { try { renderer.Draw(g, myInk.Strokes); break; } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception occurred in InkScribble.Draw: " + e); // Ignore exception. System.Threading.Thread.Sleep(100); } } }
/// <summary> /// Draw ink strokes on top of the given image. Using DibGraphicsBuffer preserves /// ink transparency and anti-aliasing. /// </summary> /// <param name="img"></param> /// <param name="pageIdentifier"></param> private void AddInkOverlay(Image img, Guid pageIdentifier) { ScaledInk scaledInk = (ScaledInk)hashtablePageStrokes[pageIdentifier.ToString()]; if ((scaledInk != null) && (scaledInk.PageInk.Strokes.Count > 0)) { //Draw the slide data on a temporary graphics object in a temporary form System.Windows.Forms.Form tempForm = new System.Windows.Forms.Form(); Graphics screenGraphics = tempForm.CreateGraphics(); DibGraphicsBuffer dib = new DibGraphicsBuffer(); Graphics tempGraphics = dib.RequestBuffer(screenGraphics, img.Width, img.Height); //Draw the existing image tempGraphics.DrawImage(img, 0, 0); //Scale the ink relative to the image Microsoft.Ink.Renderer renderer = new Microsoft.Ink.Renderer(); Matrix transformation = new Matrix(); renderer.GetViewTransform(ref transformation); transformation.Scale(((float)img.Width / scaledInk.PageWidth), ((float)img.Height / scaledInk.PageHeight)); renderer.SetViewTransform(transformation); //Draw the ink renderer.Draw(tempGraphics, scaledInk.PageInk.Strokes); //Paint the results back to the original image Graphics toSave = Graphics.FromImage(img); dib.PaintBuffer(toSave, 0, 0); //Cleanup toSave.Dispose(); tempGraphics.Dispose(); dib.Dispose(); screenGraphics.Dispose(); tempForm.Dispose(); } }