Documentation / Marblecore Imaging / Methods / SaveToBase64
SaveToBase64 method
Saves the current image (in the specified format) and returns the binary image data as a string encoded using the base64 encoding scheme. This method can be used to embed images directly in HTML web pages.
Syntax
String SaveToBase64(nFormat As Format, nBPP As Number, nLeft As Number, nTop As Number, nWidth As Number, nHeight As Number)
Return value
Returns a string with the base64 encoded stream or an empty string if the function failed.
Parameters
Parameter | Type | Required | Description |
nFormat | Format (Enumeration) | No | Optional parameter containing the format for the file. |
nBPP | Number | No | Optional parameter containing the number of bits per pixel for the file. |
nLeft | Number | No | Optional parameter which specifies the left coordinate of the rectangle to return. |
nTop | Number | No | Optional parameter which specifies the top coordinate of the rectangle to return. |
nWidth | Number | No | Optional parameter which specifies the width of the rectangle to return. |
nHeight | Number | No | Optional parameter which specifies the height of the rectangle to return. |
Example
The
SaveToBase64 method can be used to embed images directly in HTML pages. In the example below we create a new image and generate the HTML code to display it in a HTML page. The example is written in C#.
1
2 MarblecoreImaging Imaging = new MarblecoreImaging();
3
4
5 if (Imaging.Create(200, 200))
6 {
7 Imaging.DrawRectangleFilled(0, 0, 200, 200, Imaging.GetColorFromHTML("#ff0000"));
8
9
10 string sImg = "<img src=\"data:" + Imaging.MIME + ";base64," + Imaging.SaveToBase64() + "\" width=\"" + Imaging.Width + "\" height=\"" + Imaging.Height + "\" />";
11 }
Category
Basic operations
See also
Create |
Deserialize |
LoadFromBase64 |
LoadFromFile |
LoadFromSerializedStream |
LoadFromStream |
LoadFromURL |
Reset |
SaveToFile |
SaveToHBitmap |
SaveToHBitmapPreMultiplied |
SaveToStream |
Serialize