GdPicture.NET.14
GdPicture14 Namespace / GdViewer Class / DisplayFromByteArray Method
The document data stored in the array of bytes. This object must be properly initialized and it must be disposed of by the user as well.
Optional parameter. A member of the DocumentFormat enumeration specifying the format of the source document, that is stored in the provided byte array. If not provided the toolkit will try to automatically recognize the type of the document based byte array content.
Example





In This Topic
DisplayFromByteArray Method (GdViewer)
In This Topic
Loads a document from an array of bytes and subsequently displays it in the GdViewer control. The document previously displayed in the control will automatically close.

All document formats currently supported by the toolkit are listed here.

The BeforeDocumentChange and the AfterDocumentChange events are raised just before and right after the document is displayed in the GdViewer control. Both events are only raised if the document has been successfully loaded.

Syntax
'Declaration
 
Public Function DisplayFromByteArray( _
   ByVal Data() As Byte, _
   Optional ByVal DocumentFormat As DocumentFormat _
) As GdPictureStatus
public GdPictureStatus DisplayFromByteArray( 
   byte[] Data,
   DocumentFormat DocumentFormat
)
public function DisplayFromByteArray( 
    Data: Bytearray of;
    DocumentFormat: DocumentFormat
): GdPictureStatus; 
public function DisplayFromByteArray( 
   Data : byte[],
   DocumentFormat : DocumentFormat
) : GdPictureStatus;
public: GdPictureStatus DisplayFromByteArray( 
   byte[]* Data,
   DocumentFormat DocumentFormat
) 
public:
GdPictureStatus DisplayFromByteArray( 
   array<byte>^ Data,
   DocumentFormat DocumentFormat
) 

Parameters

Data
The document data stored in the array of bytes. This object must be properly initialized and it must be disposed of by the user as well.
DocumentFormat
Optional parameter. A member of the DocumentFormat enumeration specifying the format of the source document, that is stored in the provided byte array. If not provided the toolkit will try to automatically recognize the type of the document based byte array content.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK. We strongly recommend always checking this status first.
Remarks
Just to remind you that both the BeforeDocumentChange and the AfterDocumentChange events are raised using this method.
Example
How to display your image from an array of bytes.
'We assume that the GdViewer1 control has been properly integrated.
Dim oFile As System.IO.FileInfo
oFile = New System.IO.FileInfo("image.gif")
Dim oFileStream As System.IO.FileStream = oFile.OpenRead()
Dim lBytes As Integer = CInt(oFileStream.Length)
If (lBytes > 0) Then
    Dim fileData(lBytes - 1) As Byte
    oFileStream.Read(fileData, 0, lBytes)
    oFileStream.Close()
    If GdViewer1.DisplayFromByteArray(fileData) = GdPictureStatus.OK Then
        'Do your stuff here.
    Else
        MessageBox.Show("This file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.DisplayFromByteArray")
    End If
End If
//We assume that the GdViewer1 control has been properly integrated.
System.IO.FileInfo oFile;
oFile = new System.IO.FileInfo("image.gif");
System.IO.FileStream oFileStream = oFile.OpenRead();
int lBytes = System.(int)(oFileStream.Length);
if (lBytes > 0)
{
    byte[] fileData = new byte[lBytes];
    oFileStream.Read(fileData, 0, lBytes);
    oFileStream.Close();
    if (GdViewer1.DisplayFromByteArray(fileData) == GdPictureStatus.OK)
    {
        //Do your stuff here.
    }
    else
    {
        MessageBox.Show("This file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.DisplayFromByteArray");
    }
}
See Also