Click here to Skip to main content
15,894,405 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery9-Oct-07 6:00
Mark Salsbery9-Oct-07 6:00 
GeneralRe: Need a best possible alternative?? [modified] Pin
Kiran Satish9-Oct-07 6:10
Kiran Satish9-Oct-07 6:10 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery9-Oct-07 8:01
Mark Salsbery9-Oct-07 8:01 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish9-Oct-07 10:49
Kiran Satish9-Oct-07 10:49 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery10-Oct-07 5:24
Mark Salsbery10-Oct-07 5:24 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish10-Oct-07 6:56
Kiran Satish10-Oct-07 6:56 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish11-Oct-07 5:14
Kiran Satish11-Oct-07 5:14 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery11-Oct-07 5:30
Mark Salsbery11-Oct-07 5:30 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish11-Oct-07 12:53
Kiran Satish11-Oct-07 12:53 
GeneralRe: Need a best possible alternative?? Pin
Mark Salsbery11-Oct-07 13:06
Mark Salsbery11-Oct-07 13:06 
GeneralRe: Need a best possible alternative?? Pin
Kiran Satish11-Oct-07 13:31
Kiran Satish11-Oct-07 13:31 

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.