✅ An issue with converting byte array to a Bitmap with 32bppArgb image format

Hi everyone. I need help (desperately). I'm creating a simple raycaster game, which means I need to clear screen and fill it again every frame. I draw by puting color data into array and converting this array into a bitmap. The following code sets bitmap pixel data to data taken from array.
Rectangle copyRect = new Rectangle(0, 0, Width, Height);
BitmapData data = imageBuffer.LockBits(copyRect, ImageLockMode.ReadWrite, imageBuffer.PixelFormat);
IntPtr bPointer = data.Scan0;
Marshal.Copy(buffer, 0, bPointer, buffer.Length);
imageBuffer.UnlockBits(data);
Rectangle copyRect = new Rectangle(0, 0, Width, Height);
BitmapData data = imageBuffer.LockBits(copyRect, ImageLockMode.ReadWrite, imageBuffer.PixelFormat);
IntPtr bPointer = data.Scan0;
Marshal.Copy(buffer, 0, bPointer, buffer.Length);
imageBuffer.UnlockBits(data);
Width and Height are variables specifying size of the bitmap I want to edit. imageBuffer is a Bitmap I want to edit. buffer is my pixel color data (byte[]), stored in this order: BGRA. This array is reset every frame by setting all elements to zero. Next, I draw imageBuffer to the screen. It works fine as long as imageBuffer.PixelFormat is Format32bppRgb. And here comes my issue: when I change imageBuffer.PixelFormat to Format32bppArgb, weird thing happens (as shown on the second picture). Image is glitched in a odd way, and the same happens to strings in the left up corner, which aren't being drawn on the buffer, but on the graphics, after the imageBuffer is modified. Some interesting notes (all experiments done with Format32bppArgb pixel format): - when I change order in the buffer to ABGR I get less blurry effect and blurrines disappears when camera is not moving. - when I change order in the buffer to ARGB, blur gets stronger, but also disappears after few seconds of standing still In both cases colors are off, because I changed order of channels in the buffer. On the first picture you can see how it looks with Format32bppRgb. On the second picture you see a glitched image buffer, using Format32bppRgb.
No description
No description
7 Replies
Kouhai /人◕ ‿‿ ◕人\
Can you try with a simpler framebuffer? For example just the color red or blue
SamwiseTheBrave
SamwiseTheBrave4mo ago
with alpha channel, or without it?
SamwiseTheBrave
SamwiseTheBrave4mo ago
Here is a result with alpha channel equal to 255 and R and G channels equal to 0.
No description
SamwiseTheBrave
SamwiseTheBrave4mo ago
Hands are still normal, because they aren't being drawn to the buffer. oh my I'm afraid I'm just dumb as hell let me check Yes, that's the case. You know what? I was clearing buffer every frame, but I wasn't clearing graphics. so half transparent buffer was drawing on top of the old
Kouhai /人◕ ‿‿ ◕人\
Oh :Sweats: I guess it's fixed now?
SamwiseTheBrave
SamwiseTheBrave4mo ago
well, it doesn't do this blurring glitch effect, so I guess it works. thank you for pointing me in the right direction
Kouhai /人◕ ‿‿ ◕人\
:HYPERS: you might wanna /close just so it's marked as solved
Want results from more Discord servers?
Add your server
More Posts