bitmap from memorystream has altered pixels

M

margec3

// at server, bitmapStream is a MemoryStream that i put together by
converting a gif file from indexed pixel format to raw (A)RBG format
Bitmap carrierBitmap = new Bitmap(bitmapStream);

// store encrypted data at the 'R' element of pixels at various
positions of carrierBitmap (i am doing image steganography)

// save the worked up bitmap back to memory stream
bitmapStream.Flush();
carrierBitmap.Save(bitmapStream,
System.Drawing.Imaging.ImageFormat.Png);

//******* examine pixels of the first 10 worked up positions of the
result bitmap (to be compared with the one recovered by the client
later)

// convert memory stream to byte array
byte[] embeddedBuf = bitmapStream.ToArray();

// send byte array to pocket PC client

// recover the memory stream at client

Bitmap carrierBitmap = new Bitmap(bitmapStream);

//******* examine pixels of the first 10 positions of the recovered
bitmap, and they're different, not just the R value that i need to
recover the original data with, but G and B too

can someone shed some light about why and how i can recover the exact
bitmap sent by the server?
 
M

margec3

this is exactly how i converted a gif file from indexed pixel format
to raw (A)RBG format:

public static MemoryStream convertBitmap(string fileName)
{
Bitmap myImage = new Bitmap(fileName);

int imageSize = myImage.Width * myImage.Height;
MemoryStream ms = new MemoryStream(imageSize);
myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

Bitmap resultImage = new Bitmap(myImage.Width,
myImage.Height);
Graphics resultG = Graphics.FromImage(resultImage);
resultG.DrawImage(myImage, 0, 0);

imageSize = myImage.Height * myImage.Width; // # of pixels
ms.Flush();
resultImage.Save(ms,
System.Drawing.Imaging.ImageFormat.Png);

return ms;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top