last day (14 days later) » 

10:12 AM
0
Q: Slanted bitmap, stride calculation for RGB565 C#

majidarifSome of my resulting images are slanted, some are not. Expected Result: (529x22) Actual Result: (529x22) Don't mind the different image sizes, these are screenshots. They are both 529x22. The code I am using, I just got this from an answer on a question here at SO. // some other meth...

 
Sorry, I didn't know what it was called. New to bitmaps. I'll try to fix the question.
 
TaW
It is four bytes.
 
@TaW 4 bytes? the padding?
 
TaW
Yes or rather: a scanline is padded to the next multiple of four byte, ie the stride is 0-3 bytes longer than the net pixel line.
You don't have to calculate Stride nor to remove padding, the system calculates Stride and inserts the padding. Most likely the way you move unpadded data in one go is the error.. A loop going over the lines seems more likely to work.
 
@TaW what am i missing? im new to c#. And in python i never had problems like this.
 
TaW
10:12 AM
Hi
Can you tell me a little about the data? where do they come from? they semms to have different lengths, right?
 
Hello. Thanks for the time.
The data comes from a binary file
The first part is width and height then the size then the pixel data
It is actually a file that contains possibly many images
All in <w> <h> <size> <pixel data...> then repeat if there is more
It is a game packed file
I already have a working python code for a long time. But i decided to make a tool using c# to make use of the winforms. Becuas with python i was just using wx.
I also already have the c# code working. Correctly getting the offsets and data from the files.
But the problem is some are slanted.
So that is what im trying to figure out
 
10:49 AM
Is this what you mean?
private Bitmap ByteToImage(int w, int h, byte[] pixels)
{
var bmp = new Bitmap(w, h, PixelFormat.Format16bppRgb565);

var BoundsRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
BitmapData bmpData = bmp.LockBits(BoundsRect,
ImageLockMode.WriteOnly,
bmp.PixelFormat);

for (int row = 0; row < bitmapData.Height; row++)
{
var dataBeginPointer = IntPtr.Add(bitmapData.Scan0, row * bitmapData.Stride);
Marshal.Copy(dataBeginPointer, pixels, row * bitmapData.Width * bytesPerPixel, bitmapData.Width * bytesPerPixel);
I cant test for now cuz im out
Just wrote that on my notes
 
TaW
11:20 AM
Sorry, I forgot about the chat, busy writing out a working solutuion.. Yes, that is what I meant. At first glance it looks ok
You can compare my solution and yours and test later.. bye
 

last day (14 days later) »