Пример #1
0
            public void InkExport(Microsoft.Ink.PersistenceFormat persistenceFormat, string filterString)
            {
                byte[] buffer = null;

                //variables used to create filename
                string file = null;
                string ext  = null;

                string defaultFileName = "SavedInk";

                int slideIndex = 0;
                //Create a new save file dialog
                SaveFileDialog saveFileDialog = new SaveFileDialog();

                saveFileDialog.Filter   = filterString;
                saveFileDialog.FileName = defaultFileName;
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //Iterate throught the slide deck to check for ink on each one
                    using (this.m_Model.Workspace.Lock()) {
                        using (Synchronizer.Lock(this.m_Model.Workspace.CurrentDeckTraversal.Value.SyncRoot)) {
                            DeckModel deck = this.m_Model.Workspace.CurrentDeckTraversal.Value.Deck;
                            using (Synchronizer.Lock(deck.SyncRoot)) {
                                foreach (SlideModel slide in deck.Slides)
                                {
                                    using (Synchronizer.Lock(slide.SyncRoot)) {
                                        foreach (SheetModel sheet in slide.AnnotationSheets)
                                        {
                                            if (sheet is InkSheetModel)
                                            {
                                                using (Synchronizer.Lock(sheet.SyncRoot)) {
                                                    Microsoft.Ink.Ink ink = ((InkSheetModel)sheet).Ink;
                                                    if (ink.Strokes.Count != 0)
                                                    {
                                                        //figure out the filename
                                                        string fileNameTemp = saveFileDialog.FileName;
                                                        ext  = Path.GetExtension(fileNameTemp);
                                                        file = Path.GetFileNameWithoutExtension(fileNameTemp);
                                                        string n        = slideIndex.ToString();
                                                        string fileName = file + "[" + n + "]" + ext;
                                                        buffer = ink.Save(persistenceFormat);

                                                        //open a stream and output the buffer
                                                        FileStream myStream = System.IO.File.Create(fileName);
                                                        myStream.Write(buffer, 0, buffer.Length);
                                                        myStream.Close();

                                                        slideIndex++;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
Пример #2
0
        /// <summary>
        /// Overlay one stroke on the image.
        /// </summary>
        /// <param name="img"></param>
        /// <param name="s"></param>
        /// <param name="size"></param>
        /// PRI2: I believe we can use the DibGraphicsBuffer (see opaque ink handling above) to improve the
        /// look of the transparency.  This currently has the following shortcoming:  The colors produced by the exported gif
        /// from CP's highlight pens have some whiteness which causes a little fog over the dark colors
        /// below, for example the yellow highlight over a black background results in a lighter dark color,
        /// no longer quite black.  In contrast the native ink mixing gives us nearly the original black.  It is as if
        /// the colors are on colored but clear mylar that overlay one another.  It's probably possible to get this effect
        /// with DrawImage somehow??
        private void addTransparentStroke(Image img, Microsoft.Ink.Strokes s, double size)
        {
            Microsoft.Ink.Ink tmpInk = new Microsoft.Ink.Ink();
            tmpInk.AddStrokesAtRectangle(s, s.GetBoundingBox());
            //Make a GIF Image from the Stroke.  Note that this image is assumed to be in a 500x500 pixel space.
            byte[] ba     = tmpInk.Save(Microsoft.Ink.PersistenceFormat.Gif);
            Image  inkImg = Image.FromStream(new MemoryStream(ba));

            Graphics g = Graphics.FromImage(img);

            //Get the origin from the ink Bounding Box (in ink space)
            Rectangle inkBB = tmpInk.GetBoundingBox();

            //Convert the origin of the ink rectangle to pixel space (500x500)
            Microsoft.Ink.Renderer r = new Microsoft.Ink.Renderer();
            Point inkOrigin          = inkBB.Location;

            r.InkSpaceToPixel(g, ref inkOrigin);

            //Convert the transparency coefficient from 0-255 with 0==opaque to the range of 0-1 with 1==opaque.
            int   t1 = Math.Abs(tmpInk.Strokes[0].DrawingAttributes.Transparency - 255);
            float t2 = (float)t1 / 255f;

            //Setting transparency with a ColorMatrix
            float[][] ptsArray =
            {
                new float[] { 1, 0, 0,  0, 0 }, //r
                new float[] { 0, 1, 0,  0, 0 }, //g
                new float[] { 0, 0, 1,  0, 0 }, //b
                new float[] { 0, 0, 0, t2, 0 }, //alpha
                new float[] { 0, 0, 0,  0, 1 }
            };
            ColorMatrix     clrMatrix     = new ColorMatrix(ptsArray);
            ImageAttributes imgAttributes = new ImageAttributes();

            imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            //Adjust Y origin to account for horizontal scroll.  (scrollPos becomes more positive as ink goes upward.)
            float scrolledYInkOrigin = (float)inkOrigin.Y - (500 * (float)scrollPos); //Still in 500x500 space

            //Scale and locate the destination rectangle of the ink within the slide image:
            RectangleF destRect = new RectangleF(
                (float)inkOrigin.X * ((float)img.Width / 500f) * (float)size,
                scrolledYInkOrigin * ((float)img.Height / 500f) * (float)size,
                (float)inkImg.Width * ((float)img.Width / 500f) * (float)size,
                (float)inkImg.Height * ((float)img.Height / 500f) * (float)size);

            Rectangle destRect2 = new Rectangle((int)destRect.X, (int)destRect.Y, (int)destRect.Width, (int)destRect.Height);

            //Draw the overlay:
            g.DrawImage(inkImg, destRect2, 0, 0, inkImg.Width, inkImg.Height, GraphicsUnit.Pixel, imgAttributes);
            g.Dispose();
        }
Пример #3
0
        private void AddOpaqueInkOverlayOld(double size, Image img)
        {
            //add the opaque ink overlay
            if ((opaqueInk != null) && (opaqueInk.Strokes.Count > 0))
            {
                //Make a GIF Image from the ink.  Note that this image is assumed to be in a 500x500 pixel space.
                byte[] ba     = opaqueInk.Save(Microsoft.Ink.PersistenceFormat.Gif);
                Image  inkImg = Image.FromStream(new MemoryStream(ba));

                Graphics     g  = Graphics.FromImage(img);
                GraphicsUnit gu = GraphicsUnit.Pixel;

                //Get the origin from the ink Bounding Box (in ink space)
                Rectangle inkBB = opaqueInk.GetBoundingBox();

                //Convert the origin of the ink rectangle to pixel space (500x500)
                Microsoft.Ink.Renderer r = new Microsoft.Ink.Renderer();
                Point inkOrigin          = inkBB.Location;
                r.InkSpaceToPixel(g, ref inkOrigin);

                //Adjust Y origin to account for horizontal scroll.
                float scrolledYInkOrigin = (float)inkOrigin.Y - (500 * (float)scrollPos);

                //Scale and locate the destination rectangle of the ink within the slide image:
                RectangleF destRect = new RectangleF(
                    (float)inkOrigin.X * ((float)img.Width / 500f) * (float)size,
                    scrolledYInkOrigin * ((float)img.Height / 500f) * (float)size,
                    (float)inkImg.Width * ((float)img.Width / 500f) * (float)size,
                    (float)inkImg.Height * ((float)img.Height / 500f) * (float)size);

                //Draw the overlay:
                g.DrawImage(inkImg, destRect, inkImg.GetBounds(ref gu), GraphicsUnit.Pixel);

                g.Dispose();
            }
        }