GdPicture.NET.14
GdPicture14 Namespace / GdPictureImaging Class / CreateGdPictureImageFromString Method
String which contains the image file data.
Example





In This Topic
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 ImageData As String _
) As Integer
public int CreateGdPictureImageFromString( 
   string ImageData
)
public function CreateGdPictureImageFromString( 
    ImageData: String
): Integer; 
public function CreateGdPictureImageFromString( 
   ImageData : String
) : int;
public: int CreateGdPictureImageFromString( 
   string* ImageData
) 
public:
int CreateGdPictureImageFromString( 
   String^ ImageData
) 

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.
Remarks

Supported formats are listed here: http://www.gdpicture.com/solutions/supported-formats/.

Notes for multipage images (TIFF and GIF): By default, the class loads multipage images (GIF and TIFF) in read & write mode. To open multipage images in read-only mode call the TiffOpenMultiPageForWrite() method specifying False for tiff images or the GifOpenMultiFrameForWrite() method for gif images.

This method requires the Image Documents component to run.

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