これは可能です。実際に変換する必要がある000001111100000111111100000011
か、バイト配列000111000111000111000111000111
として扱われます。これを行うには、string
byte[]
Convert.ToByte(object value, IFormatProvider provider)
string input = "BINARY GOES HERE";
int numOfBytes = input.Length / 8; //Get binary length and divide it by 8
byte[] bytes = new byte[numOfBytes]; //Limit the array
for (int i = 0; i < numOfBytes; ++i)
{
bytes[i] = Convert.ToByte(input.Substring(8 * i, 8), 2); //Get every EIGHT numbers and convert to a specific byte index. This is how binary is converted :)
}
これにより、新しい文字列が宣言input
され、バイト配列()にエンコードされますbyte[]
。として使用し、に挿入byte[]
できるようにするには、実際にこれが必要になります。これを行うには、Stream
PictureBox
MemoryStream
MemoryStream FromBytes = new MemoryStream(bytes); //Create a new stream with a buffer (bytes)
最後に、このストリームを使用してファイルを作成しImage
、ファイルをPictureBox
pictureBox1.Image = Image.FromStream(FromBytes); //Set the image of pictureBox1 from our stream
例
private Image Decode(string binary)
{
string input = binary;
int numOfBytes = input.Length / 8;
byte[] bytes = new byte[numOfBytes];
for (int i = 0; i < numOfBytes; ++i)
{
bytes[i] = Convert.ToByte(input.Substring(8 * i, 8), 2);
}
MemoryStream FromBinary = new MemoryStream(bytes);
return Image.FromStream(FromBinary);
}
これを使用することで、たとえばいつでも呼び出すことができDecode(000001111100000111111100000011)
、画像に変換されます。次に、このコードを使用してImage
、PictureBox
pictureBox1.Image = Decode("000001111100000111111100000011");
重要なお知らせ:ArgumentException was unhandled: Parameter is not valid.
これは、無効なバイナリコードが原因で発生する可能性があります。
ありがとう、
これがお役に立てば幸いです:)