Skip to main content

Tips to Convert Image to Array and Array to Image, C# .NET

I know my friend working on .NET development in a company. She wanted me to help her out in an occasion today. She actually wanted to convert a double array(double[]) into an image (Image) in C# .NET. I did googling on the this thing and I found something useful for my modifications.

You know I do also have little knowledge on .NET. I have Microsoft Visual Studio 2008 installed on my laptop which helped me to do this work. Unfortunately I could not finish this for converting exactly from double[] to Image. However it is useful for converting byte[] to Image.


Converting double[] to byte[], then using that will work for this C# code. I will try it out and let you know in the comments section. Here I share my search on this:








using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//Namespaces to be added
using System.IO;
using System.Drawing.Imaging;

namespace doubletoimg
{
    public partial class frmMain : Form
    {
        public byte[] bImg; //byte array
        //public double dImg;
        public frmMain()
        {
            InitializeComponent();
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            if (ofdImage.ShowDialog()==DialogResult.OK )
            {
                bImg = ImageToArray(Image.FromFile(ofdImage.FileName));
                //dImg = BitConverter.ToDouble(bImg,0);
                //bImg = BitConverter.GetBytes(dImg);
            }
            lblMsg.Text = "Converted to Array!";
        }
        public byte[] ImageToArray(Image imgIn)
        {
            //MemoryStream is a class in System.IO namespace
            MemoryStream ms = new MemoryStream();
            imgIn.Save(ms, ImageFormat.Jpeg);
            return ms.ToArray();
        }
        public Image ArrayToImage(byte[] bIn)
        {
            MemoryStream ms = new MemoryStream(bIn);
            return Image.FromStream(ms);
        }
       
        private void btnShow_Click(object sender, EventArgs e)
        {
            pbShow.Image = ArrayToImage(bImg);
        }
       
    }
}












Hope the Information is useful!

Popular posts from this blog

Convert Your Photos to Sketches - Free Sites

-Free Tools to convert photos to sketches- -Photo to sketch free converter- -Sketch creator software free- -Websites to make sketches from images- -Online photoshop- -Image processing- -Edit photos online- -Online tools for photo editing.
In this post, I would like to tell you about some free websites that let you to make graphical sketches from your photos or images. Why do we need this? If you are just a newbie to web, don't have much knowledge about creating graphical or pencil sketches for your photos using tools like Photoshop, you should go for these simple way to get your work done. Normally most of us are always interested in looking our photos with different effects and alterations made for better look and feel, and as we are all engaged our spare internet time with almost all the social networking sites, it's effective to have a sketched photo in our profile to represent which extent we are funny and enthusiastic about social networking. I just wanted this for my prof…

Cut or Split Your Music Files Free Online - Mp3Cut

-Cut or Split Music Files online- -Cut Mp3 files- -create Ringtones from songs- -Ringtone creator online- -Mp3 Cutter Online- -Mobile ringtones converter free- -Music editing tool- -Endhiran Ringtones free- -Web based mp3 cutter-

We have already seen many free web services at www.mysearchhistory.co.cc, a quick recap: ASCII Art Generator, Unzip zip and rar files online, Free OCR-Extract text from images, Download YouTube videos as Mp3 audio files, Convert your photos to sketches. As for now, if you are aware, you should download, install and then use complex software to edit, cut or split music files like MP3 files, the best free one, I have written about Audacity Audio Editor and Voice Recorder Free. The hassleful tasks have gone now. In this post, I would reach you with an amazing online service (web based) that helps you to split or cut your mp3 files for free. Yes! You can now make your ringtones from your mp3 music files free on the go in air. No more software needed.
Mp3Cut
Mp3Cut o…

First Indian Web Browser Released - Epic Browser - Powered by Mozilla

This post  is about Internet Browsers and useful for the following tags: -First Indian Web Browser- -Epic Browser- -Mozilla powered Epic Browser- -Mozilla powered Indian Browser- -Browser with Antivirus- -Epic Features and Options- -Epic Browser Review- -Download Epic Browser-

Hello All
Welcome back to www.mysearchhistory.co.cc!
As I was busy with some other activities I couldn't get you some updates last month. Here I would like to introduce first ever Indian Web Browser powered by Mozilla. 
Epic Browser
Epic browser is based on Mozilla Firefox and is customized in look-and-feel and everything useful for Indian internet users. Epic browser has been released last week with none of Indians' expectation and quoted with the following taglines: Meet Epic Your New Best Friend.
the first-ever web browser for India
the world's only sidebar apps browser
the world's only antivirus browser
So I just wanted to give it a try as I am always curious on testing features of different browser. …