Marblecore Imaging Library Documentation

Documentation Introduction
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.


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.


nFormatFormat (Enumeration)NoOptional parameter containing the format for the file.
nBPPNumberNoOptional parameter containing the number of bits per pixel for the file.
nLeftNumberNoOptional parameter which specifies the left coordinate of the rectangle to return.
nTopNumberNoOptional parameter which specifies the top coordinate of the rectangle to return.
nWidthNumberNoOptional parameter which specifies the width of the rectangle to return.
nHeightNumberNoOptional parameter which specifies the height of the rectangle to return.


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 // Create a new image class
2 MarblecoreImaging Imaging = new MarblecoreImaging();
4 // Create a new image and draw a red rectangle on it
5 if (Imaging.Create(200, 200))
6 {
7     Imaging.DrawRectangleFilled(0, 0, 200, 200, Imaging.GetColorFromHTML("#ff0000"));
9     // Create the image HTML code
10    string sImg = "<img src=\"data:" + Imaging.MIME + ";base64," + Imaging.SaveToBase64() + "\" width=\"" + Imaging.Width + "\" height=\"" + Imaging.Height + "\" />";
11 }


Basic operations

See also

Create | Deserialize | LoadFromBase64 | LoadFromFile | LoadFromSerializedStream | LoadFromStream | LoadFromURL | Reset | SaveToFile | SaveToHBitmap | SaveToHBitmapPreMultiplied | SaveToStream | Serialize