|Manuals

ServerUtils.IconToBase64 Method

Converts a PNG image to base64 format for storage in IProfile.IconData.

Description

This method converts an Image object to a base64-encoded string, which can be stored in the IProfile.IconData property of a profile.

Syntax

public static string IconToBase64(Image png);

Parameters

Parameter Type Description
png Image The image to be encoded in base64

Return Value

Type: string

Returns a base64 representation of the provided PNG image.

Example

Server server = new Server();

// Load an image from file
Image icon = Image.FromFile("my_icon.png");

// Convert to base64
string iconData = ServerUtils.IconToBase64(icon);

// Assign to a profile
var profile = server.Profiles[0];
profile.IconData = iconData;

// Save changes
server.Save();

See Also