Bitmap Image Multiplication I Found this Memory stream option to merge the files with given no of repeats. All the things are working file but in the End, the generated BMP file is not as per enter repetition. Need help. Commented lines in code is another way which I tried. enter code here public partial class Form1 : Form { FileStream bitmapfileload; Bitmap bmp; int NoOfRepeats; public Form1() { InitializeComponent(); }
private void btnOpenFile_Click(object sender, EventArgs e)
{
DoubleBuffered = true;
OpenFileDialog openFileDialog1 = new OpenFileDialog
{
InitialDirectory = @"D:\",
Title = "Browse Design Files",
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = "tif",
Filter = "Images (*.BMP;*.TIF)|*.BMP;*.TIF|" + "All files (*.*)|*.*",
FilterIndex = 1,
RestoreDirectory = true,
Multiselect = false,
ReadOnlyChecked = false,
ShowReadOnly = true
};
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
byte[] ba = null;
foreach (String file in openFileDialog1.FileNames)
{
Image temp = new Bitmap(file);
LblSourceWidth.Text = Convert.ToString(temp.Width);
LblSourHeight.Text = Convert.ToString(temp.Height);
temp.Dispose();
bitmapfileload = new FileStream(file,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
ba = streamToByteArray(bitmapfileload);
}
NoOfRepeats = int.Parse(ltbRepeat.Text); // Text box will give no of repeat for writing proceedure
// List <byte[]> ListBa = new List<byte[]>();
MemoryStream MergeFile = new MemoryStream();
using (MemoryStream allFrameStream = new MemoryStream())
{
for (int i = 0; i < NoOfRepeats; i++)
{
allFrameStream.Write(ba, 0, ba.Length);
allFrameStream.Position = ba.Length * i;
//ListBa.Add(allFrameStream.ToArray());
//ListBa.Add(ba);
}
MergeFile = allFrameStream;
bmp = new Bitmap(MergeFile);
}
//byte[] finaleba = Combine(ListBa.ToArray());
//byte[] finaleba = ListBa.Cast<byte[]>().SelectMany(a => a).ToArray();
//LblListCount.Text = Convert.ToString(finaleba.Length); // List Count = no of repeats for FOR-LOOP
//Stream Finalfile = new MemoryStream(MergeFile);
//richTextBox1.Text = Convert.ToString(Finalfile);
LblDestiWidth.Text = Convert.ToString(bmp.Width); // no change here
LblDestiHeight.Text = Convert.ToString(bmp.Height); // no change here
pictureBox1.Image = bmp;
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
}
private static byte[] Combine(byte[][] arrays)
{
byte[] bytes = new byte[arrays.Sum(a => a.Length)];
int offset = 0;
foreach (byte[] array in arrays)
{
Buffer.BlockCopy(array, 0, bytes, offset, array.Length);
offset += array.Length;
}
return bytes;
}
public static byte[] streamToByteArray(Stream input)
{
MemoryStream ms = new MemoryStream();
input.CopyTo(ms);
return ms.ToArray();
}