Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Image Handling for Library Agnosticism #5

Closed
sabir-aspose opened this issue Nov 6, 2023 · 2 comments · Fixed by #17
Closed

Enhance Image Handling for Library Agnosticism #5

sabir-aspose opened this issue Nov 6, 2023 · 2 comments · Fixed by #17
Assignees
Labels
enhancement New feature or request

Comments

@sabir-aspose
Copy link
Collaborator

OpenXML SDK stores images in drawing objects. We propose to make the custom Image object within FileFormat.Words.IElements library agnostic, enabling the storage of images as byte[] data, along with pixel dimensions using the default 96 DPI. This change empowers API users to utilize any image library of their preference for tailored image processing.

@sabir-aspose sabir-aspose self-assigned this Nov 13, 2023
@sabir-aspose sabir-aspose added the enhancement New feature or request label Nov 13, 2023
@sabir-aspose
Copy link
Collaborator Author

sabir-aspose commented Nov 13, 2023

Resolved in 23.10.0. Now, API stores Images as byte[] and user can use an image library to further work on it. Below is the example to parse all images from a Word Document using FileFormat.Words, decode those images using SkiSharp and then save to disk as image1.png, image2.png and so on:

using System;
using System.Threading.Tasks;
using FileFormat.Words;
using FileFormat.Words.IElements;
using System.Collections.Generic;
using SkiaSharp;
using System.IO;

namespace FileFormat.Words.Examples
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document("WordDocumentWithImages.docx");
            Body body = new Body(doc);
            int counter = 1;
            
            foreach (Image image in body.Images)
            {
                byte[] imageBytes = image.ImageData;

                using (SKBitmap skBitmap = SKBitmap.Decode(imageBytes))
                using (SKImage skImage = SKImage.FromBitmap(skBitmap))
                {
                    SKData encoded = skImage.Encode(SKEncodedImageFormat.Png, 100);
                    using (Stream stream = encoded.AsStream())
                    {
                        string imageName = $"Image{counter}.png";
                        using (FileStream fileStream = new FileStream(imageName, FileMode.Create))
                        {
                            stream.CopyTo(fileStream);
                            counter++;
                            Console.WriteLine("Image Copied");
                        }
                    }
                }
            }
        }
    }
}

The issue will be closed after adding related examples and articles.

@openize-words openize-words linked a pull request Jun 12, 2024 that will close this issue
@openize-words
Copy link

already resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant