I have an image on my drive, I encrypted the bytes by adding a numerical value, now how can I write that modified file and replace the old one?
Here's my encryption method [very newbish because I'm just getting a feel for things :P ]:
private void EncryptFile()
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";
dialog.InitialDirectory = @"C:\Users\Sergio\Desktop";
dialog.Title = "Please select an image file to encrypt.";
if (dialog.ShowDialog() == DialogResult.OK)
{
byte[] ImageBytes = File.ReadAllBytes(dialog.FileName);
for (int i = 0; i < ImageBytes.Length; i++)
{
ImageBytes[i] = (byte)(ImageBytes[i] + 5);
}
}
}
I'm stuck there. I don't really know how to procede. Technically, after that for loop, I have my modifed image inside of the byte[] ImageBytes. Now how can I write it in the exact same location as the image?
Woah! On a side note, am I reading the file correctly by using dialog.FileName. Does that return the file's path?