Click here to Skip to main content
15,901,505 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Smaller than a byte Pin
Sameerkumar Namdeo27-Sep-07 17:42
Sameerkumar Namdeo27-Sep-07 17:42 
QuestionRe: Smaller than a byte Pin
zakkas248327-Sep-07 23:49
zakkas248327-Sep-07 23:49 
AnswerRe: Smaller than a byte Pin
Iain Clarke, Warrior Programmer28-Sep-07 5:31
Iain Clarke, Warrior Programmer28-Sep-07 5:31 
QuestionNeed a best possible alternative?? Pin
Kiran Satish27-Sep-07 7:08
Kiran Satish27-Sep-07 7:08 
AnswerRe: Need a best possible alternative?? Pin
Mark Salsbery27-Sep-07 7:31
Mark Salsbery27-Sep-07 7:31 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish1-Oct-07 10:41
Kiran Satish1-Oct-07 10:41 
QuestionRe: Need a best possible alternative?? Pin
Mark Salsbery1-Oct-07 11:15
Mark Salsbery1-Oct-07 11:15 
AnswerRe: Need a best possible alternative?? Pin
Kiran Satish1-Oct-07 11:34
Kiran Satish1-Oct-07 11:34 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery1-Oct-07 11:53
Mark Salsbery1-Oct-07 11:53 
GeneralRe: Need a best possible alternative?? [modified] Pin
Kiran Satish2-Oct-07 5:40
Kiran Satish2-Oct-07 5:40 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery2-Oct-07 5:48
Mark Salsbery2-Oct-07 5:48 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery2-Oct-07 6:34
Mark Salsbery2-Oct-07 6:34 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery2-Oct-07 7:01
Mark Salsbery2-Oct-07 7:01 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish2-Oct-07 7:42
Kiran Satish2-Oct-07 7:42 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery2-Oct-07 8:13
Mark Salsbery2-Oct-07 8:13 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish2-Oct-07 8:21
Kiran Satish2-Oct-07 8:21 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery2-Oct-07 8:25
Mark Salsbery2-Oct-07 8:25 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish2-Oct-07 8:41
Kiran Satish2-Oct-07 8:41 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery2-Oct-07 9:11
Mark Salsbery2-Oct-07 9:11 
Kiran Satish wrote:
so have to do some research/reading on it and also the way to implement in my case.

Hopefully this will help a bit...
<code>// Example:  Create a DIBSection</code>

LONG DIBSecWidth = ...;
LONG DIBSecHeight = ...;
LONG BitsPerPixel = 24;

LONG Stride = ((DIBSecWidth * BitsPerPixel + 31L) & (~31L)) / 8L;

BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = DIBSecWidth;
bmi.bmiHeader.biHeight = DIBSecHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = (WORD)BitsPerPixel;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = Stride * abs(DIBSecHeight);

BYTE *pDIBSectionBits;

HBITMAP hbm = ::CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void**)&pDIBSectionBits, NULL, 0);



<code>// Example:  calculate a pixel location in the DIBSection</code>
int x = ...;
int y = ...;
RGBTRIPLE *pPixel = (RGBTRIPLE *)(pDIBSectionBits + ((y * Stride) + (x * sizeof(RGBTRIPLE))));

<code>// Example:  Use the pixel pointer calculated above to index an RGB value in the DIBSection</code>
pPixel[0].rgbtBlue = 0;
pPixel[0].rgbtGreen = 0;
pPixel[0].rgbtRed = 0;

<code>// Example:  Set rect (10, 10, 20, 20) in DIBSection to black</code>
RECT rect;
rect.left = 10;
rect.top = 10;
rect.right = 20;
rect.bottom = 20;
RGBTRIPLE *pCurRowPixel = (RGBTRIPLE *)(pDIBSectionBits + ((rect.top * Stride) + (rect.left * sizeof(RGBTRIPLE))));
for (int y = 0; y < rect.bottom - rect.top; ++y)
{
    for (int x = 0; x < rect.right - rect.left; ++x)
    {
        pCurRowPixel[x].rgbtBlue = 0;
        pCurRowPixel[x].rgbtGreen = 0;
        pCurRowPixel[x].rgbtRed = 0;
    }
    pCurRowPixel = (RGBTRIPLE *)((BYTE*)pCurRowPixel + Stride);
}

You can probably optimize that stuff even further for specific implementations
but that generic code should be much faster than a SetPixel loop Smile | :)

Mark



Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: Need a best possible alternative?? Pin
Kiran Satish2-Oct-07 9:45
Kiran Satish2-Oct-07 9:45 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish3-Oct-07 10:46
Kiran Satish3-Oct-07 10:46 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery3-Oct-07 11:18
Mark Salsbery3-Oct-07 11:18 
GeneralRe: Need a best possible alternative?? [modified] Pin
Kiran Satish3-Oct-07 12:13
Kiran Satish3-Oct-07 12:13 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery3-Oct-07 12:49
Mark Salsbery3-Oct-07 12:49 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish8-Oct-07 15:17
Kiran Satish8-Oct-07 15:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.