Created
May 16, 2024 09:39
-
-
Save aspose-com-gists/02151542baafe1993a477deee169f08c to your computer and use it in GitHub Desktop.
Convert Chart to Image in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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