Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created May 16, 2024 09:39
Show Gist options
  • Save aspose-com-gists/02151542baafe1993a477deee169f08c to your computer and use it in GitHub Desktop.
Save aspose-com-gists/02151542baafe1993a477deee169f08c to your computer and use it in GitHub Desktop.
Convert Chart to Image in Java
Convert Chart to Image in Javapackage com.example;
import com.aspose.slides.*;
// Convert Chart to Image in Java - Extract Charts From PPTX
public class GetChartImage
{
public static void main(String[] args)
{
// The path to the source PowerPoint file directory.
String dataDir = "/files/";
// Initialize an instance of the Presentation class with a source PPTX/PPT file.
Presentation pres = new Presentation(dataDir + "test.pptx");
try
{
// Invoke the addChart method to add a chart to the end of the collection.
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400);
// getImage method returns shape thumbnail.
IImage img = chart.getImage();
// Invoke the save method to save the chart as a PNG image.
img.save(dataDir + "image.png", ImageFormat.Png);
}
finally
{
if (pres != null) pres.dispose();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment