Locking 24bpp bitmap portion
-
How to select correct width to lock from 24bpp bitmap of random width, that the locked bitmpa data has the stride equal to 3 * locked bitmap data width? bitmapData.stride == bitmapData.width * 3
Чесноков
-
How to select correct width to lock from 24bpp bitmap of random width, that the locked bitmpa data has the stride equal to 3 * locked bitmap data width? bitmapData.stride == bitmapData.width * 3
Чесноков
-
Depends how your bitmap is stored. If you have this structure:
BITMAPINFOHEADER bmHeader
it has a member
//LONG biWidth;
LONG width = bmHeader.biWidthI need to do it using GDI+ How do we need to decrease bitmap width, that after it was locked to read its RGB triplets, the stride in that array will be equal to (3 * width) e.g. 640x480 24bpp bitmap has stride 1920 = 3 * 640 but some 257x150 24bpp has stride not equal to 3 * 257 What is the formula to decrease 257 to fit into 3 * width = stride?
Чесноков
-
How to select correct width to lock from 24bpp bitmap of random width, that the locked bitmpa data has the stride equal to 3 * locked bitmap data width? bitmapData.stride == bitmapData.width * 3
Чесноков
-
I believe the memory holding the pixel data is DWORD aligned. So wouldnt you just do:
#define ALIGN(val)((val + 3) & ~3) DWORD iSize = (sizeof(RGBTRIPLE) * bitmapData.width); iSize = ALIGN(iSize);
Am I right? Best Wishes, -David Delaunesay we have width = 257; what is the width should be to (width * 3) % 4 = 0
Чесноков
-
say we have width = 257; what is the width should be to (width * 3) % 4 = 0
Чесноков
-
I do not need to estimate stride of bitmap given the width I need to estimate width of the bitmap for a stride. In the equation 257 is the x variable needed to be found: (((x * sizeof(RGBTRIPLE))) + 3) & ~3) = 772 we have width = 257 257 * 3 = 771, 771 / sizeof(DWORD) = 192.75 hence we need to decrease 257 the way the stride / 4 = integer 252 * 3 = 756, 756 / sizeof(DWORD) = 189 How can we found that width = 252 from original 257?
Чесноков
-
I do not need to estimate stride of bitmap given the width I need to estimate width of the bitmap for a stride. In the equation 257 is the x variable needed to be found: (((x * sizeof(RGBTRIPLE))) + 3) & ~3) = 772 we have width = 257 257 * 3 = 771, 771 / sizeof(DWORD) = 192.75 hence we need to decrease 257 the way the stride / 4 = integer 252 * 3 = 756, 756 / sizeof(DWORD) = 189 How can we found that width = 252 from original 257?
Чесноков
I am not understanding the numbers you are showing me. For example:
Chesnokov Yuriy wrote:
257 * 3 = 771, 771 / sizeof(DWORD) = 192.75
Why are you dividing 771 by sizeof(DWORD)? This does not make any sense to me. Each pixel is represented by 3 bytes or sizeof(RGBTRIPLE). The padding will be at the end of the memory allocated. Like this: xxxxxxxxxxxxxxxxPADDING You should be able to calculate the original bitmap width by checking that stride modulo RGBTRIPLE is equal to zero. For finding the best width where width is equal to stride you can multiply width by RGBTRIPLE and check that it is equal to the alignment. Something like this:
#define ALIGN(val)((val + 3) & ~3) #define ISSTRIDEALIGNED(val)((val * sizeof(RGBTRIPLE)) == ALIGN(val * sizeof(RGBTRIPLE))) DWORD OriginalWidth24(DWORD dwInStride) { if(0 != dwInStride % sizeof(RGBTRIPLE)) { --dwInStride; } return dwInStride / sizeof(RGBTRIPLE); } DWORD BestWidthEqualStride(DWORD dwWidth) { while(dwWidth && (sizeof(RGBTRIPLE) * dwWidth) != ALIGN(dwWidth * sizeof(RGBTRIPLE))) { --dwWidth; } return dwWidth; }
And you can check their values:DWORD dwBitmapWidth = 257; DWORD dwNonAlignedSize = (dwBitmapWidth * sizeof(RGBTRIPLE)); DWORD dwAlignedSize = ALIGN(dwBitmapWidth * sizeof(RGBTRIPLE)); DWORD dwOriginalWidth = OriginalWidth24(dwAlignedSize); DWORD dwWidthEqualsStride = BestWidthEqualStride(dwBitmapWidth);
Best Wishes, -David Delaune