EDN Admin
Well-known member
hi all I trying create Application for the BMP Constructor, I already write the code in C# but I cant translate it into VB.NET, because its require pointer, and as far as i know, there are no pointer function in vb.net @@ so how I can translate this:
<pre class="prettyprint FileStream fs = new FileStream(OJSPathBox.Text, FileMode.Open);
BinaryReader rdr = new BinaryReader(fs);
int width = 555; // its just for example
int height = 555; //its just for example
int bytes = width * height * 2;
int t = 0; // Offset Chunk data bmp, just for example
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;
for (int i = 0; i < bytes; i++)
{
fs.Position = t + i;
//
b = fs.ReadByte();
*ptr = Convert.ToByte(b);
ptr++;
if (width % 2 != 0)
if ((i + 1) % (width * 2) == 0 && (i + 1) * 2 % width < width - 1)
{
ptr += 2;
}
}
//ptr += 2;
tmp_bitmap.UnlockBits(bmpData);
OJSImageBox.Image = tmp_bitmap;
fs.Close();
fs.Dispose();
rdr.Close();[/code]
<br/>
ptr declaration is using Pointer and I throught, there are no unsafe in vb.net, how I can translate to vb.net language? is this still possible? thanks
<br/>
View the full article
<pre class="prettyprint FileStream fs = new FileStream(OJSPathBox.Text, FileMode.Open);
BinaryReader rdr = new BinaryReader(fs);
int width = 555; // its just for example
int height = 555; //its just for example
int bytes = width * height * 2;
int t = 0; // Offset Chunk data bmp, just for example
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;
for (int i = 0; i < bytes; i++)
{
fs.Position = t + i;
//
b = fs.ReadByte();
*ptr = Convert.ToByte(b);
ptr++;
if (width % 2 != 0)
if ((i + 1) % (width * 2) == 0 && (i + 1) * 2 % width < width - 1)
{
ptr += 2;
}
}
//ptr += 2;
tmp_bitmap.UnlockBits(bmpData);
OJSImageBox.Image = tmp_bitmap;
fs.Close();
fs.Dispose();
rdr.Close();[/code]
<br/>
ptr declaration is using Pointer and I throught, there are no unsafe in vb.net, how I can translate to vb.net language? is this still possible? thanks
<br/>
View the full article