I Post here the entire solution I have (with your help :) )
XAML :
<grid>>
<Button x:Name="btnOuvrirImage" Content="Image --> Base64" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="130"/>
<Button x:Name="btnChargerImage" Content="Base64 --> Image" HorizontalAlignment="Left" Margin="150,10,0,0" VerticalAlignment="Top" Width="130"/>
<Image x:Name="imgImage" Margin="290,10,10,10"/>
<TextBox x:Name="tbBytes" Margin="10,42,0,10" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Left" Width="270"/>
</Grid>
MainWindow.cs
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
btnChargerImage.Click += new RoutedEventHandler(btnChargerImage_Click);
btnOuvrirImage.Click += new RoutedEventHandler(btnOuvrirImage_Click);
}
void btnChargerImage_Click(object sender, RoutedEventArgs e)
{
if (tbBytes.Text != null && tbBytes.Text.Length > 0)
{
byte[] imgStr = Convert.FromBase64String(tbBytes.Text);
imgImage.Source = ByteImageConverter.ByteToImage(imgStr);
}
}
void btnOuvrirImage_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofg = new OpenFileDialog();
ofg.Title = "Select an image";
ofg.Filter = "Images (.jpg, .png, .gif, .bmp)|*.jpg;*.png;*.gif;*.bmp";
ofg.Multiselect = false;
if (ofg.ShowDialog() == true)
{
if (ofg.FileName != null && ofg.FileName.Length > 0)
{
ofg.OpenFile();
FileStream fs = new FileStream(ofg.FileName, FileMode.Open, FileAccess.Read);
tbBytes.Text = ByteImageConverter.ImageToByte(fs);
byte[] imgStr = Convert.FromBase64String(tbBytes.Text);
imgImage.Source = ByteImageConverter.ByteToImage(imgStr);
}
}
}
}
C# Convert Class :
public class ByteImageConverter
{
public static ImageSource ByteToImage(byte[] imageData)
{
BitmapImage biImg = new BitmapImage();
MemoryStream ms = new MemoryStream(imageData);
biImg.BeginInit();
biImg.StreamSource = ms;
biImg.EndInit();
ImageSource imgSrc = biImg as ImageSource;
return imgSrc;
}
public static string ImageToByte(FileStream fs)
{
byte[] imgBytes = new byte[fs.Length];
fs.Read(imgBytes, 0, Convert.ToInt32(fs.Length));
string encodeData = Convert.ToBase64String(imgBytes, Base64FormattingOptions.InsertLineBreaks);
return encodeData;
}
}
Hop will helpful for others like me :)