public void InsertImageFromByteArrayCustomSize()
        {
            //ExStart
            //ExFor:DocumentBuilder.InsertImage(Byte[], Double, Double)
            //ExSummary:Shows how to import an image into a document from a byte array, with a custom size.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

#if NETSTANDARD2_0 || __MOBILE__
            using (SkiaSharp.SKBitmap bitmap = SkiaSharp.SKBitmap.Decode(ImageDir + "Aspose.Words.gif"))
            {
                using (SkiaSharp.SKFileWStream fs = new SkiaSharp.SKFileWStream(MyDir + "Artifacts/InsertImageFromByteArrayCustomSize.png"))
                {
                    bitmap.Encode(fs, SKEncodedImageFormat.Png, 100);
                }

                builder.InsertImage(bitmap, ConvertUtil.PixelToPoint(450), ConvertUtil.PixelToPoint(144));
                builder.Document.Save(MyDir + "Artifacts/Image.CreateFromByteArrayCustomSize.doc");
            }
#else
            // Prepare a byte array of an image.
            Image image = Image.FromFile(ImageDir + "Aspose.Words.gif");

            using (MemoryStream imageBytes = new MemoryStream())
            {
                image.Save(imageBytes, ImageFormat.Png);

                builder.InsertImage(imageBytes, ConvertUtil.PixelToPoint(450), ConvertUtil.PixelToPoint(144));
                builder.Document.Save(MyDir + @"\Artifacts\Image.CreateFromByteArrayCustomSize.doc");
            }
#endif
            //ExEnd
        }
        public void InsertImageFromByteArrayRelativePosition()
        {
            //ExStart
            //ExFor:DocumentBuilder.InsertImage(Byte[], RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType)
            //ExSummary:Shows how to import an image into a document from a byte array, also using relative positions.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

#if NETSTANDARD2_0 || __MOBILE__
            using (SkiaSharp.SKBitmap bitmap = SkiaSharp.SKBitmap.Decode(ImageDir + "Aspose.Words.gif"))
            {
                using (SkiaSharp.SKFileWStream fs = new SkiaSharp.SKFileWStream(MyDir + "Artifacts/InsertImageFromByteArrayCustomSize.png"))
                {
                    bitmap.Encode(fs, SKEncodedImageFormat.Png, 100);
                }

                builder.InsertImage(bitmap, RelativeHorizontalPosition.Margin, 100, RelativeVerticalPosition.Margin, 100, 200, 100, WrapType.Square);
                builder.Document.Save(MyDir + "Artifacts/Image.CreateFromByteArrayCustomSize.doc");
            }
#else
            // Prepare a byte array of an image.
            Image image = Image.FromFile(ImageDir + "Aspose.Words.gif");

            using (MemoryStream imageBytes = new MemoryStream())
            {
                image.Save(imageBytes, ImageFormat.Png);

                builder.InsertImage(imageBytes, RelativeHorizontalPosition.Margin, 100, RelativeVerticalPosition.Margin, 100, 200, 100, WrapType.Square);
                builder.Document.Save(MyDir + @"\Artifacts\Image.CreateFromByteArrayRelativePosition.doc");
            }
#endif
            //ExEnd
        }
Exemple #3
0
        public void InsertImageFromByteArray()
        {
            //ExStart
            //ExFor:DocumentBuilder.InsertImage(Byte[])
            //ExSummary:Shows how to import an image into a document from a byte array.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

#if NETSTANDARD2_0 || __MOBILE__
            using (SkiaSharp.SKBitmap bitmap = SkiaSharp.SKBitmap.Decode(ImageDir + "Aspose.Words.gif"))
            {
                using (SkiaSharp.SKFileWStream fs =
                           new SkiaSharp.SKFileWStream(MyDir + "Artifacts/InsertImageFromByteArray.png"))
                {
                    bitmap.Encode(fs, SKEncodedImageFormat.Png, 100);
                }

                builder.InsertImage(bitmap);
                builder.Document.Save(MyDir + "Artifacts/Image.CreateFromByteArrayDefault.docx");
            }
#else
            // Prepare a byte array of an image.
            using (Image image = Image.FromFile(ImageDir + "Aspose.Words.gif"))
            {
                using (MemoryStream imageBytes = new MemoryStream())
                {
                    image.Save(imageBytes, ImageFormat.Png);

                    builder.InsertImage(imageBytes.ToArray());
                    builder.Document.Save(MyDir + @"\Artifacts\Image.CreateFromByteArrayDefault.doc");
                }
            }
#endif
            //ExEnd
        }
Exemple #4
0
        /// <summary>
        /// Combines 2 images into one, given the shared ImageStats for both supplied images.
        /// </summary>
        /// <param name="info">the ImageStats object used to generate both bottom and top tiles.</param>
        /// <param name="bottomTile">the tile to use as the base of the image. Expected to be opaque.</param>
        /// <param name="topTile">The tile to layer on top. Expected to be at least partly transparent or translucent.</param>
        /// <returns></returns>
        public byte[] LayerTiles(ImageStats info, byte[] bottomTile, byte[] topTile)
        {
            SkiaSharp.SKBitmap bitmap = new SkiaSharp.SKBitmap(info.imageSizeX, info.imageSizeY, SkiaSharp.SKColorType.Rgba8888, SkiaSharp.SKAlphaType.Premul);
            SkiaSharp.SKCanvas canvas = new SkiaSharp.SKCanvas(bitmap);
            SkiaSharp.SKPaint  paint  = new SkiaSharp.SKPaint();
            canvas.Scale(1, 1, info.imageSizeX / 2, info.imageSizeY / 2);
            paint.IsAntialias = true;

            var baseBmp = SkiaSharp.SKBitmap.Decode(bottomTile);
            var topBmp  = SkiaSharp.SKBitmap.Decode(topTile);

            canvas.DrawBitmap(baseBmp, 0, 0);
            canvas.DrawBitmap(topBmp, 0, 0);
            var ms   = new MemoryStream();
            var skms = new SkiaSharp.SKManagedWStream(ms);

            bitmap.Encode(skms, SkiaSharp.SKEncodedImageFormat.Png, 100);
            var output = ms.ToArray();

            skms.Dispose(); ms.Close(); ms.Dispose();
            return(output);
        }