C# tutorials for beginner : how to create Base64 Images Converter windows applications? Convert from base64 and from base64 to an images using C# programming language.
C# for beginners - How to convert an image to Base64 code and/or from Base64 code into an image using C# programming language? The simple application 'Images Converter' will allow you to convert all images type to Base64 codes, we can select / browse an image where we want to convert it, just click "Convert button" and you get your Base64 code.
Please read :
After image already converted, you can fill it into a PictureBox, then we can create copy or paste button to copy or paste all base64 code from teh RichTexBox.
Just focuss to our project dude xD
Source Code Base64 Images Convert (Form1.Cs)
If you're still confused, please watch video tutorials below,
Download full source code https://www.dropbox.com/s/ruhzif4eiyu9tsc/hc-kr-com-Base64ImagesConverter.zip?dl=0
Please read :
After image already converted, you can fill it into a PictureBox, then we can create copy or paste button to copy or paste all base64 code from teh RichTexBox.
Create Base64 Images Converter
Just create new project in your visual studio and rename with "Base64ImagesConverter", at the form1.vb please add 6 Buttons, one TextBox, One RichTextBox and OpenFileDialog Component, and design it look like this images :Just focuss to our project dude xD
Source Code Base64 Images Convert (Form1.Cs)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Base64ImagesConverter {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
DialogResult dr = openFileDialog1.ShowDialog();
try {
textBox1.Text = openFileDialog1.FileName;
} catch (Exception x) {
MessageBox.Show(x.Message);
}
}
private void button2_Click(object sender, EventArgs e) {
if (textBox1.Text == "") {
MessageBox.Show("No path spesified");
textBox1.Focus();
}
else {
byte[] imagearray = System.IO.File.ReadAllBytes(textBox1.Text);
string createBase64 = Convert.ToBase64String(imagearray);
richTextBox1.Text = createBase64;
}
}
private void button3_Click(object sender, EventArgs e) {
if (richTextBox1.Text !="") {
// we can create base64 functions
pictureBox1.Image = Base64toImage(richTextBox1.Text);
} else {
MessageBox.Show("Paste Base 64 string First");
richTextBox1.Focus();
}
}
public Image Base64toImage(string base64string) {
// Convert Base64 String to byte[]
byte[] imagesByte = Convert.FromBase64String(base64string);
System.IO.MemoryStream ms = new System.IO.MemoryStream(imagesByte, 0 , imagesByte.Length);
// Convert byte[] to Image , based on @Crulex comment, the below line has no need since MemoryStream already initialized
ms.Write(imagesByte, 0 , imagesByte.Length);
Image image = Image.FromStream(ms, true);
return image;
}
private void button4_Click(object sender, EventArgs e) {
Clipboard.Clear();
Clipboard.SetText(richTextBox1.Text.ToString());
MessageBox.Show("Copied to clipboard!");
richTextBox1.Clear();
}
private void button5_Click(object sender, EventArgs e) {
richTextBox1.Text = Clipboard.GetText();
}
private void button6_Click(object sender, EventArgs e) {
this.Close();
}
}
}
If you're still confused, please watch video tutorials below,
Video tutorials How to Convert Image from / to Base64 code
Download full source code https://www.dropbox.com/s/ruhzif4eiyu9tsc/hc-kr-com-Base64ImagesConverter.zip?dl=0
COMMENTS