CreateGdPictureImageFromString Method (GdPictureImaging)
In This Topic
Creates a new GdPicture image from image data stored within string data (Encoding 1252).
Syntax
'Declaration
Public Function CreateGdPictureImageFromString( _
ByVal As String _
) As Integer
public int CreateGdPictureImageFromString(
string
)
public function CreateGdPictureImageFromString(
: String
): Integer;
public function CreateGdPictureImageFromString(
: String
) : int;
public: int CreateGdPictureImageFromString(
string*
)
public:
int CreateGdPictureImageFromString(
String^
)
Parameters
- ImageData
- String which contains the image file data.
Return Value
0: The image could not be created. Use the GetStat() method to determine the reason this method
failed.
Non-zero: GdPicture image identifier. The created image. The ReleaseGdPictureImage() method must be subsequently used to release the image from the memory.
Example
Creating a GdPicture image from an image file stored in a string and saving to a PNG file.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
using (Stream stream = File.Open("image.bmp", FileMode.Open))
{
// Load the file to a buffer for the sake of demonstration.
// In a production context, the image file should be obviously loaded with CreateGdPictureImageFromFile.
int size = (int)stream.Seek(0, SeekOrigin.End);
byte[] buffer = new byte[size];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(buffer, 0, size);
// Encode the buffer to a string
string encodedBuffer = Encoding.GetEncoding(1252).GetString(buffer, 0, size);
// Create the GdPicture image and save it as a PNG.
int imageID = gdpictureImaging.CreateGdPictureImageFromString(encodedBuffer);
gdpictureImaging.SaveAsPNG(imageID, "image.png");
gdpictureImaging.ReleaseGdPictureImage(imageID);
}
Example
Creating a GdPicture image from an image file stored in a string and saving to a PNG file.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
using (Stream stream = File.Open("image.bmp", FileMode.Open))
{
// Load the file to a buffer for the sake of demonstration.
// In a production context, the image file should be obviously loaded with CreateGdPictureImageFromFile.
int size = (int)stream.Seek(0, SeekOrigin.End);
byte[] buffer = new byte[size];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(buffer, 0, size);
// Encode the buffer to a string
string encodedBuffer = Encoding.GetEncoding(1252).GetString(buffer, 0, size);
// Create the GdPicture image and save it as a PNG.
int imageID = gdpictureImaging.CreateGdPictureImageFromString(encodedBuffer);
gdpictureImaging.SaveAsPNG(imageID, "image.png");
gdpictureImaging.ReleaseGdPictureImage(imageID);
}
See Also