Back to Devexpress

ASPxBinaryImage.ContentBytes Property

aspnet-devexpress-dot-web-dot-aspxbinaryimage.md

latest5.1 KB
Original Source

ASPxBinaryImage.ContentBytes Property

Gets or sets an array of the bytes representing the image.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue(null)]
public virtual byte[] ContentBytes { get; set; }
vb
<DefaultValue(Nothing)>
Public Overridable Property ContentBytes As Byte()

Property Value

TypeDefaultDescription
Byte[]null

A Byte array that contains the image’s contents.

|

Remarks

The example below demonstrates how to use the ASPxBinaryImage.ContentBytes property.

aspx
<dxwe:ASPxBinaryImage ID="biImage" runat="server">
</dxwe:ASPxBinaryImage>

<dxwuc:ASPxUploadControl runat="server" ID="ucImageUpload" 
    ClientInstanceName="ucImageUpload" 
    onfileuploadcomplete="ucImageUpload_FileUploadComplete">
    <ValidationSettings AllowedFileExtensions=".jpg,.jpe,.jpeg,.gif">
    </ValidationSettings>
</dxwuc:ASPxUploadControl>

<dxwe:aspxbutton id="btnUpload" runat="server" autopostback="False" text="Upload">
    <ClientSideEvents Click="function(s, e) { ucImageUpload.UploadFile(); }" />
</dxwe:aspxbutton>

<dxwe:aspxbutton id="btnApply" runat="server" text="Apply image from session" 
    onclick="btnApply_Click">
</dxwe:aspxbutton>
csharp
protected void ucImageUpload_FileUploadComplete
(object sender, DevExpress.Web.FileUploadCompleteEventArgs e) {
    UploadedFile uploadFile = ucImageUpload.UploadedFiles.Length == 0 ? 
        null : ucImageUpload.UploadedFiles[0];
    Session["UploadedImageBytes"] = uploadFile.FileBytes;
}
protected void btnApply_Click(object sender, EventArgs e) {
    biImage.ContentBytes = (byte[])Session["UploadedImageBytes"];
}
vb
Protected Sub ucImageUpload_FileUploadComplete(ByVal sender As Object, ByVal e As DevExpress.Web.FileUploadCompleteEventArgs)
    Dim uploadFile As UploadedFile = If(ucImageUpload.UploadedFiles.Length = 0, Nothing, ucImageUpload.UploadedFiles(0))
    Session("UploadedImageBytes") = uploadFile.FileBytes
End Sub

Protected Sub btnApply_Click(ByVal sender As Object, ByVal e As EventArgs)
    biImage.ContentBytes = CType(Session("UploadedImageBytes"), Byte())
End Sub

Online Example

View Example: How to display a bar code image in a column

The following code snippets (auto-collected from DevExpress Examples) contain references to the ContentBytes property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

asp-net-web-forms-grid-display-barcode-in-column/CS/ASPxGridViewBarCode/Default.aspx.cs#L20

csharp
if (value != null)
        image.ContentBytes = GetBarCodeImage(value.ToString());
}

asp-net-web-forms-implement-pdf-viewer/CS/PdfViewer.ascx.cs#L109

csharp
bitmap.Save(stream, ImageFormat.Png);
    image.ContentBytes = stream.ToArray();
}

asp-net-web-forms-grid-display-barcode-in-column/VB/ASPxGridViewBarCode/Default.aspx.vb#L25

vb
If value IsNot Nothing Then
    image.ContentBytes = GetBarCodeImage(value.ToString())
End If

asp-net-web-forms-implement-pdf-viewer/VB/PdfViewer.ascx.vb#L115

vb
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
    image.ContentBytes = stream.ToArray()
End Using

See Also

StoreContentBytesInViewState

Binary Image

ASPxBinaryImage Class

ASPxBinaryImage Members

DevExpress.Web Namespace