if (dataStream.Length == 0) { error = "Input data has a not supported size of 0 !"; return false; } uint maxByteStorage = ((uint)bmp.Height * (uint)bmp.Width * 3) / 8; error += "-> Up to " + (maxByteStorage-4) + " bytes could be stored in this bitmap...\n"; if (maxByteStorage < dataStream.Length + 4) { error = "Not enough pixel in target bitmap to hide the input data block !"; return false; }
Bitmap24Writer bmpWriter = new Bitmap24Writer(bmp); uint dataSize = (uint)dataStream.Length; try { for (uint u = 0; u < 4; u++) { bmpWriter.WriteByte( (byte)dataSize ); dataSize >>= 8; } for (uint u = 0; u < dataStream.Length; u++) bmpWriter.WriteByte( (byte)dataStream.ReadByte() ); } catch { error = "Error while modifing the bitmap's pixels !"; return false; }
if (bFile2Bmp) ret = BitmapWorks.Data2Bmp( File.OpenRead(inFile), File.OpenRead(inBmp), outFile, out err ); else ret = BitmapWorks.Bmp2Data( File.OpenRead(inBmp), outFile, out err); if (!ret) { Console.WriteLine("!! " + err); return; } else Console.Write( err ); } catch(FileNotFoundException) { Console.WriteLine("!! At least one file could not be found :("); return; } catch { Console.WriteLine("!! An exception occurred :("); return; }