I created new bitmap file, bitmapdata, now a want the pixeldata that are in
the array bytes[] put into the bmpData, what should I change in the code
unsafe? there is something wrong with p[0] = (byte)(bytes[0]); is makes all
the pixel in some color..........
// this code will be replace by a COM who gets a byte array
Stream stream = File.Open(@"d:\ImageWeftIllum.bmp", FileMode.Open);
bytes=new byte[stream.Length];
stream.Read(bytes,0,(int)stream.Length);
mem= new MemoryStream(bytes);
//
Bitmap bmp = new Bitmap(640,480);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width,
bmp.Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmpData.Stride;
System.IntPtr Scan0 = bmpData.Scan0;
unsafe
{
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - bmp.Width*3;
int nWidth = bmp.Width * 3;
for(int y=0;y < bmp.Height;++y)
{
for(int x=0; x < nWidth; ++x )
{
p[0] = (byte)(bytes[0]);
++p;
}
p += nOffset;
}
}
bmp.UnlockBits(bmpData);
pictureBox1.Image=bmp; 2 2942
idd the p[0] = (byte)(bytes[0]); is very wrong, the 0 should be someting
else like int i..........
"Jeroen Ceuppens" <Je*************@barco.com> wrote in message
news:ev**************@tk2msftngp13.phx.gbl... I created new bitmap file, bitmapdata, now a want the pixeldata that are
in the array bytes[] put into the bmpData, what should I change in the code unsafe? there is something wrong with p[0] = (byte)(bytes[0]); is makes
all the pixel in some color.......... // this code will be replace by a COM who gets a byte array
Stream stream = File.Open(@"d:\ImageWeftIllum.bmp", FileMode.Open);
bytes=new byte[stream.Length];
stream.Read(bytes,0,(int)stream.Length);
mem= new MemoryStream(bytes);
//
Bitmap bmp = new Bitmap(640,480);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmpData.Stride;
System.IntPtr Scan0 = bmpData.Scan0;
unsafe
{
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - bmp.Width*3;
int nWidth = bmp.Width * 3;
for(int y=0;y < bmp.Height;++y)
{
for(int x=0; x < nWidth; ++x )
{
p[0] = (byte)(bytes[0]);
++p;
}
p += nOffset;
}
}
bmp.UnlockBits(bmpData);
pictureBox1.Image=bmp;
> I created new bitmap file, bitmapdata, now a want the pixeldata that are
in the array bytes[] put into the bmpData, what should I change in the code unsafe? there is something wrong with p[0] = (byte)(bytes[0]); is makes
all the pixel in some color..........
you can use Marshal.Copy instead of unsafe code. it should work (it works
for me in a similar scenario).
Marshal.Copy ( bytes, 0, bData.Scan0, size );
Regards,
Wiktor Zychla This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: becte |
last post by:
I need to use three bytes to store four 6-bit integers (4 * 6 = 3 * 8)
like this
11111122|22223333|33444444
Suppose the input is, int c1, c2, c3, c4, range 0 .. 2^6 -1
and the output is int...
|
by: philip |
last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as
code of form1 in a new project.
My problem is this one :
I try to write in a file a serie of bytes.
BUT some bytes...
|
by: Lee Crabtree |
last post by:
I need to shift all of the values in a byte array by more than 8 bits,
meaning that values should flow from one byte to another. Since I don't
know in advance how many bits will be shifting, I...
|
by: Geoffrey |
last post by:
Hello,
I have one array of Bytes , and I want to add some Bytes at the start of the
array.
Is it possible to move all the bytes of the array to right , so I can insert
my Bytes like Bytes, ......
|
by: Noel Milton |
last post by:
Hi:
Ok, I've just read in up to 65,535 bytes into a char array (using the
recvfrom socket API
call). So I have an array of 8 bit char's (char recvString;).
Now, four (4) consecutive bytes...
|
by: fineman |
last post by:
Hi all,
I want to get a 64bit(8 bytes) Encrypt result use DES class in the
VS2005.
Though I encrypt data is 64bit(8 bytes), but DES return encrypt result
that always is 128bit(16 bytes),
I don't...
|
by: Gerrit Holl |
last post by:
Hi,
In Python 3, reading from a file gives bytes rather than characters.
Some operations currently performed on strings also make sense when
performed on bytes, either if it's binary data or if...
|
by: Bint |
last post by:
I have an array whose elements I'm accessing, like array, array, etc.
However, the data is meant to be 16-bit words, not bytes. I'm getting byte
values right now. Is there
any way I can tell php...
|
by: sexauthor |
last post by:
I'm converting a VB6 application over that called a 3rd party DLL with
specific data structures. The VB6 code defined custom types for those
data structures (ie: one with the specific data types,...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| | |