Simply you can use the following code to convert Byte Array to Image:

Image.FromStream(new MemoryStream(byteArrayIn));

Which you can put it in a function like this:

public Image byteArrayToImage(byte[] byteArrayIn)
{
     Image returnImage = null;
     using (MemoryStream ms = new MemoryStream(byteArrayIn))
     {
         returnImage = Image.FromStream(ms);
     }
     return returnImage;
}

You can also convert your Byte Array to string and use it to bind a PictureBox like the following code. Actually, I've used it in WebApp projects and not sure if it works on yours:

string photo = "data:image/jpeg;base64," + Convert.ToBase64String(byteArray.Photo, 0, byteArray.Photo.Length);
Answer from Majid Shahabfar on Stack Overflow
๐ŸŒ
Javl
javl.github.io โ€บ image2cpp
image2cpp
You can import multiple images at once. All processing is done locally in your browser: your images are not uploaded or stored anywhere online. ... Set this to the size of your image. Common sizes: 16x16 32x32 64x48 128x32 128x64. ... Byte array is invalid (or empty).
๐ŸŒ
Freedevelopertools
freedevelopertools.com โ€บ array-to-image
Array to Image Converter Online Free - Byte Array Visualizer | FreeDeveloperTools.com
An array to image converter is a developer utility that takes a raw byte array - typically a C-style uint8_t[] or Rust &[u8] - and reconstructs it into a pixel image you can see in your browser.
Discussions

c# - How to I convert to image from Byte[] Array? - Stack Overflow
I am inserting image to database and dataGridView. When I insert a image, it writes "Byte[] Array" on dataGridView. How to I convert to image on dataGridView or how to I send to pictureBox ? More on stackoverflow.com
๐ŸŒ stackoverflow.com
Converting a byte array into an image
Hi! Iโ€™m receiving grayscale pixel data from a thermal sensor over the serial port. It is transferred into a byte array and I now want to transform it into an image via image.image() to combine it with the onboard camera module. The problem is that I always get the โ€œTypeError: โ€˜argโ€™ ... More on forums.openmv.io
๐ŸŒ forums.openmv.io
9
0
August 1, 2024
javascript - How to convert a byte array into an image?
Using Javascript, I'm making an AJAX call to a WCF service, and it is returning a byte array. How can I convert that to an image and display it on the web page? More on stackoverflow.com
๐ŸŒ stackoverflow.com
c# - How to convert a byte array to an image? - Stack Overflow
I tried to convert a byte array to an image but nothing and no error. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Code Beautify
codebeautify.org โ€บ base64-to-image-converter
Base64 to Image Decoder / Converter
Base64 to Image encoder Online helps to convert Base64 String to image.
๐ŸŒ
FileFlow Tool
base64-to-image.com โ€บ home โ€บ bytes to image
Bytes to Image Converter Online | Byte Array to Image
Convert byte arrays, Uint8Array, Buffer, decimal bytes, hexadecimal and Base64 data into previewable images locally in your browser.
๐ŸŒ
Onlinebinarytools
onlinebinarytools.com โ€บ convert-binary-to-image
Convert Binary to an Image โ€“ Online Binary Tools
Free online binary to image converter. Just load your binary number and it will automatically get converted to an image. There are no ads, popups or nonsense, just a binary to image converter. Load a binary value, get an image.
๐ŸŒ
Browserling
browserling.com โ€บ tools โ€บ image-to-base64
Image to Base64 Converter - Encode Images to Base64 - Online - Browserling Web Developer Tools
World's simplest online image base64 encoder for web developers and programmers. Just select your JPG, PNG, GIF, Webp, or BMP picture or drag & drop it in the form below, press the Convert to Base64 button, and you'll get a base-64 string of ...
Find elsewhere
๐ŸŒ
Google Groups
groups.google.com โ€บ g โ€บ google-web-toolkit โ€บ c โ€บ CWwkYQjQ0q4
byte array to Image
September 16, 2011 - So basically your app asks your server to fetch an image from the web service. The server will do so and returns something like "193823903" as unique id. Now your app creates an Image widget and as URL it uses http://yourapp.com/service/binary?id=93823903. Your "binary" servlet will take the unique id, look it up in the session, found the BinaryData object with the byte array and returns the array with the specified mime type (image/png).
๐ŸŒ
Dot2pic
dot2pic.com
dot2pic.com - Convert an image to data array
This site is a tool which is very helpfull when you want to create an image which will be displayed on your graphic display. You can use it to create fonts, menus, intros etc. It is also very versatile, it allows for creating many different kinds of data arrays like monochromatic or color, vertical or horizontal. It is also capable converting pictures with uncommon resolutions. dot2pic.com works online without downloading and installing any progarms.
๐ŸŒ
Online JPG Tools
onlinejpgtools.com โ€บ convert-base64-to-jpg
Convert Base64 to JPEG โ€“ Online JPG Tools
Incredibly simple, free, and fast browser-based utility for converting base64 data to viewable and downloadable JPEG images. Just paste your base64 in this utility and you will instantly get a JPG.
๐ŸŒ
Adafruit
forums.adafruit.com โ€บ forums index โ€บ supported products & projects โ€บ other products from adafruit
Simple online byte array generator for OLED - adafruit industries
January 22, 2016 - I didn't like having to boot a virtual machine to create images, and also I didn't like the program itself (got some errors and flakey results). So I made a simpel web-based converter. It allows you to open a file to convert and apply some simple changes (invert color, stretch to fit canvas, etc). It's also able to read back a previously generated byte array to display the image.
๐ŸŒ
OpenMV Forums
forums.openmv.io โ€บ openmv boards
Converting a byte array into an image - OpenMV Boards - OpenMV Forums
August 1, 2024 - Hi! Iโ€™m receiving grayscale pixel data from a thermal sensor over the serial port. It is transferred into a byte array and I now want to transform it into an image via image.image() to combine it with the onboard camera module. The problem is that I always get the โ€œTypeError: โ€˜argโ€™ argument requiredโ€. Do I miss something? img = image.Image(width=width, height=height, pixel_format=image.GRAYSCALE, buffer=byte_array) Thanks in advance ๐Ÿ™‚
๐ŸŒ
Vaadin
cookbook.vaadin.com โ€บ byte-array-to-image
How do I convert a byte array to an Image - Vaadin Cookbook
import com.vaadin.flow.component.orderedlayout.VerticalLayout; import java.io.ByteArrayInputStream; import java.io.IOException; import com.vaadin.flow.component.html.Image; import com.vaadin.flow.router.Route; import com.vaadin.flow.server.StreamResource; import org.apache.commons.io.IOUtils; @Route("byte-array-to-image") public class ByteArrayToImage extends VerticalLayout { public ByteArrayToImage() { StreamResource streamResource = new StreamResource("vaadin-logo.png", () -> new ByteArrayInputStream(getImageAsByteArray())); Image image = new Image(streamResource, "Vaadin logo"); add(image); } private byte[] getImageAsByteArray() { try { return IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("images/vaadin-logo.png")); } catch (IOException e) { e.printStackTrace(); return null; } } }
Top answer
1 of 8
19

I realize this is an old thread, but I managed to do this through an AJAX call on a web service and thought I'd share...

  • I have an image in my page already:

     <img id="ItemPreview" src="" />
    
  • AJAX:

    $.ajax({
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            timeout: 10000,
            url: 'Common.asmx/GetItemPreview',
            data: '{"id":"' + document.getElementById("AwardDropDown").value + '"}',
            success: function (data) {
                if (data.d != null) {
                    var results = jQuery.parseJSON(data.d);
                    for (var key in results) {
                        //the results is a base64 string.  convert it to an image and assign as 'src'
                        document.getElementById("ItemPreview").src = "data:image/png;base64," + results[key];
                    }
                }
            }
        });
    

My 'GetItemPreview' code queries a SQL server where I have an image stored as a base64 string and returns that field as the 'results':

     string itemPreview = DB.ExecuteScalar(String.Format("SELECT [avatarImage] FROM [avatar_item_template] WHERE [id] = {0}", DB.Sanitize(id)));
     results.Add("Success", itemPreview);
     return json.Serialize(results);

The magic is in the AJAX call at this line:

     document.getElementById("ItemPreview").src = "data:image/png;base64," + results[key];

Enjoy!

2 of 8
8

Converting a byte array to base64 when you have the binary byte array (not a JSON string array of the byte values) is ridiculously expensive, and more importantly; it is totally unnecessary work, as you do not have to do convert it at all in modern browsers! The static URL.createObjectURL method creates a DOMString, a short browser-specific url, from the byte array, and you can use the resulting short string in img.src or similar.

This is infinitely faster than solutions that require chaining TextEncoder and btoa when all you need is to display an image received in a byte array form.

var blob = new Blob( [ uint8ArrayBuffer ], { type: "image/jpeg" } );
var imageUrl = URL.createObjectURL( blob );

This is using HTML5 APIs, and so will not work on Node or other JS based servers, of course.

// Simulate a call to Dropbox or other service that can
// return an image as an ArrayBuffer.
var xhr = new XMLHttpRequest();

// Use PlaceKitten as a sample image to avoid complicating
// this example with cross-domain issues.
xhr.open( "GET", "https://placekitten.com/200/140", true );

// Ask for the result as an ArrayBuffer.
xhr.responseType = "arraybuffer";

xhr.onload = function( e ) {
    // Obtain a blob: URL for the image data.
    var arrayBufferView = new Uint8Array( this.response );
    var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
    var urlCreator = window.URL || window.webkitURL;
    var imageUrl = urlCreator.createObjectURL( blob );
    var img = document.querySelector( "#photo" );
    img.src = imageUrl;
};

xhr.send();
<h1>Demo of displaying an ArrayBuffer</h1>
<p><a href="http://jsfiddle.net/Jan_Miksovsky/yy7Zs/">Originally made by Jan Miksovsky</p>
<img id="photo"/>

๐ŸŒ
LVGL
lvgl.io โ€บ tools โ€บ imageconverter
Image Converter โ€” LVGL
Free online image converter for LVGL. Convert PNG, JPG, BMP, and other formats into C arrays optimized for embedded displays and color formats.