Skip to content

Instantly share code, notes, and snippets.

@blog-aspose-cloud
Last active November 2, 2022 22:22
Show Gist options
  • Save blog-aspose-cloud/c277e1abbd0a4bac4ed8883fe35ae702 to your computer and use it in GitHub Desktop.
Save blog-aspose-cloud/c277e1abbd0a4bac4ed8883fe35ae702 to your computer and use it in GitHub Desktop.
Grayscale Image using Java

Generate Grayscale Image in Java


We are going to discuss the deatils and steps on how to generate Grayscale Image using Aspose.Imaging Cloud SDK for Java. With simple steps, we are going to load the source/input raster image from local drive, convert to Grayscale picture using CreateGrayscaledImage API. After the conversion, the resultant image is stored in Cloud Storage. For complete details, please visit Convert Image into Black and White.

grayscale Image

Important Links

Home | Product Page | Docs | API Reference | Cloud Dashboard | Code Samples | Source Code | Blog | Free Support | Free Trial

// Get ClientID and ClientSecret from https://dashboard.aspose.cloud/
String clientId = "7ef10407-c1b7-43bd-9603-5ea9c6db83cd";
String clientSecret = "ba7cc4dc0c0478d7b508dd8ffa029845";
// create Imaging object
ImagingApi imageApi = new ImagingApi(clientSecret, clientId);
// load file from local drive
File f = new File("PinClipart.png");
// read the content of PNG image to byte array
byte[] bytes = Files.readAllBytes(f.toPath());
// create Grayscale conversion request where we specify the name of resultant file
CreateGrayscaledImageRequest request = new CreateGrayscaledImageRequest(bytes,"grayscale.jpg",null);
// Convert Image into Black and White
imageApi.createGrayscaledImage(request);
Grayscale Image using Java Cloud SDK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment