Я пытаюсь преобразовать байт [] в изображение в C #. Я знаю, что этот вопрос задавался на разных форумах. Но ни один из ответов на них не помог мне. Чтобы дать некоторый контекст =
Я открываю изображение, конвертирую его в байт []. Я шифрую байт []. В конце концов, у меня все еще есть байт [], но он был модифицирован ofc. Теперь я хочу показать это снова. Сам байт [] состоит из 6559 байтов. Я пытаюсь преобразовать его, выполнив:
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
и я получаю эту ошибку: параметр недействителен.
Массив байтов создается с использованием .toArray () в Списке
List<byte> encryptedText = new List<byte>();
pbEncrypted.Image = iConverter.byteArrayToImage(encryptedText.ToArray())
;
Кто-нибудь может мне помочь? Я забыл какой-то формат или что-то?
Байт, который необходимо преобразовать в изображение:
private void executeAlgoritm(byte[] plainText)
{
// Empty list of bytes
List<byte> encryptedText = new List<byte>();
// loop over all the bytes in the original byte array gotten from the image
foreach (byte value in plainText)
{
// convert it to a bitarray
BitArray myBits = new BitArray(8); //define the size
for (byte x = 0; x < myBits.Count; x++)
{
myBits[x] = (((value >> x) & 0x01) == 0x01) ? true : false;
}
// encrypt the bitarray and return a byte
byte bcipher = ConvertToByte( sdes.IPInvers(sdes.FK(sdes.Shift(sdes.FK(sdes.IP(myBits),keygen.P8(keygen.shift(keygen.P10(txtKey.Text))))),keygen.P8(keygen.shift(keygen.shift(keygen.shift(keygen.P10(txtKey.Text))))))));
// add the byte to the list
encryptedText.Add(bcipher);
}
// show the image by converting the list to an array and the array to an image
pbEncrypted.Image = iConverter.byteArrayToImage(encryptedText.ToArray());
}