EDN Admin
Well-known member
hi all I trying to read pure BMP without header, the code work, but its take long time to load big Image, here my code:
<pre class="prettyprint FileStream fs = new FileStream(FileBox.Text, FileMode.Open);
BinaryReader rdr = new BinaryReader(fs);
int width = 800; // Width of Image
int height = 600; // Height of Image
int bytes = width * height * 2;
int t = 0; // Start Offset of Chunk Data
int b;
Bitmap tmp_bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
Rectangle rect = new Rectangle(0, 0, tmp_bitmap.Width, tmp_bitmap.Height);
System.Drawing.Imaging.BitmapData bmpData = tmp_bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, tmp_bitmap.PixelFormat);
unsafe
{
byte* ptr = (byte*)bmpData.Scan0;
// I wish, I can speed up this loop
for (int i = 0; i < bytes; i++)
{
fs.Position = t + i;
//
b = fs.ReadByte();
*ptr = Convert.ToByte(b);
ptr++; // Fix The Bug from OJS File:
if (width % 2 != 0)
if ((i + 1) % (width * 2) == 0 && (i + 1) * 2 % width < width - 1)
{
ptr += 2;
}
}
//ptr += 2;
tmp_bitmap.UnlockBits(bmpData);
PictureBox1.Image = tmp_bitmap;
fs.Close();
fs.Dispose();
rdr.Close(); [/code]
I tried using Marshal.Copy, but the file (OJS File) has a bug, and what I know to fix the bugs is by that code (see the // Fix The Bugs From OJS line at the loop). I hope someone can help me.
Sorry if my English so bad.
Thanks
<br/>
View the full article
<pre class="prettyprint FileStream fs = new FileStream(FileBox.Text, FileMode.Open);
BinaryReader rdr = new BinaryReader(fs);
int width = 800; // Width of Image
int height = 600; // Height of Image
int bytes = width * height * 2;
int t = 0; // Start Offset of Chunk Data
int b;
Bitmap tmp_bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
Rectangle rect = new Rectangle(0, 0, tmp_bitmap.Width, tmp_bitmap.Height);
System.Drawing.Imaging.BitmapData bmpData = tmp_bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, tmp_bitmap.PixelFormat);
unsafe
{
byte* ptr = (byte*)bmpData.Scan0;
// I wish, I can speed up this loop
for (int i = 0; i < bytes; i++)
{
fs.Position = t + i;
//
b = fs.ReadByte();
*ptr = Convert.ToByte(b);
ptr++; // Fix The Bug from OJS File:
if (width % 2 != 0)
if ((i + 1) % (width * 2) == 0 && (i + 1) * 2 % width < width - 1)
{
ptr += 2;
}
}
//ptr += 2;
tmp_bitmap.UnlockBits(bmpData);
PictureBox1.Image = tmp_bitmap;
fs.Close();
fs.Dispose();
rdr.Close(); [/code]
I tried using Marshal.Copy, but the file (OJS File) has a bug, and what I know to fix the bugs is by that code (see the // Fix The Bugs From OJS line at the loop). I hope someone can help me.
Sorry if my English so bad.
Thanks
<br/>
View the full article