Skip to content

Instantly share code, notes, and snippets.

Aspose.Imaging .NET API allows to extract embedded raster images embedded in vectors on your images or photos in your Java application or Web service.

You can:

  • extract raster images from vectors;
  • save extracted images to another format;
  • save extracted images in original format.

Interested ?

You may go further at : https://products.aspose.com/imaging/java/

using Aspose.Imaging;
using System.Collections.Generic;
using System.IO;
string templatesFolder = @"c:\Users\USER\Downloads\templates";
string dataDir = templatesFolder;
string fileName = Path.Combine(dataDir, "template.svg");
var outputFolder = dataDir;
List<string> files = new List<string>();
using (Image image = Image.Load(fileName))
{
var images = ((VectorImage)image).GetEmbeddedImages();
int i = 0;
foreach (EmbeddedImage im in images)
{
string outFileName = string.Format("svg_image{0}{1}", i++, GetExtension(im.Image.FileFormat));
string outFilePath = Path.Combine(outputFolder, outFileName);
files.Add(outFilePath);
using (im)
{
im.Image.Save(outFilePath);
}
}
}
static string GetExtension(FileFormat format)
{
switch (format)
{
case FileFormat.Jpeg:
return ".jpg";
case FileFormat.Png:
return ".png";
case FileFormat.Bmp:
return ".bmp";
default:
return "." + format.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment