Learn how to implement Alpha Blending in Java
Created
June 6, 2024 01:56
Alpha Blending 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
// This code example demonstrates how to implement composite modes in alpha blending using Java. | |
// Create a bitmap | |
Bitmap bitmap = new Bitmap(1000, 800, com.aspose.drawing.imaging.PixelFormat.Format32bppPArgb); | |
// Initialize graphics | |
Graphics graphics = Graphics.fromImage(bitmap); | |
// Define color brush | |
SolidBrush solidBrush1 = new SolidBrush(Color.fromArgb(128, 255, 0, 0)); | |
SolidBrush solidBrush2 = new SolidBrush(Color.fromArgb(128, 0, 255, 0)); | |
SolidBrush solidBrush3 = new SolidBrush(Color.fromArgb(128, 0, 0, 255)); | |
// Set the Composite mode for overlapping ellipses, | |
// the colors of the ellipses are not blended. | |
graphics.setCompositingMode(CompositingMode.SourceCopy); | |
// Set the Composite quality of the Graphics object. | |
graphics.setCompositingQuality(CompositingQuality.GammaCorrected); | |
// Draw Ellipses | |
graphics.fillEllipse(solidBrush1, 300, 100, 400, 400); | |
graphics.fillEllipse(solidBrush2, 200, 300, 400, 400); | |
graphics.fillEllipse(solidBrush3, 400, 300, 400, 400); | |
// Save the bitmap | |
bitmap.save("AlphaBlending_SourceCopy.png"); |
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
// This code example demonstrates how to implement Alpha blending in Java. | |
Bitmap bitmap = new Bitmap(1000, 800); | |
Graphics graphics = Graphics.fromImage(bitmap); | |
graphics.fillEllipse(new SolidBrush(Color.fromArgb(128, 255, 0, 0)), 300, 100, 400, 400); | |
graphics.fillEllipse(new SolidBrush(Color.fromArgb(128, 0, 255, 0)), 200, 300, 400, 400); | |
graphics.fillEllipse(new SolidBrush(Color.fromArgb(128, 0, 0, 255)), 400, 300, 400, 400); | |
bitmap.save("AlphaBlending.png"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment