Image getting skewed

Discussion in 'C++' started by apoorv, Feb 14, 2005.

  1. apoorv

    apoorv Guest

    Hi guys,
    I am writing a imaging aplication on VC++.I have to display images and
    apply effects onto it.Images could be of any type like jpg,gif,bmp,psd...M
    uding createDibSection API.it requires BITMAPINFO struc as one of its
    parameters.Its working well(Images are successfully displayed) but my
    problem is that in certain images(of any type)they are skewed and becomes
    B/W(means Data corruption).U can see my code of populating BITMAPINFO and
    CreateDibSection...Can any body help me in solving the annoying probs.
    [Note:If I am changing the dimension of image by few pixels using
    photoshop it displays well]

    BITMAPINFO bmi;

    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biWidth
    = swidth;//Image width
    bmi.bmiHeader.biHeight = -sheight;//Image Height //
    neg for top-to-bottom
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biCompression = BI_RGB; // uncompressed
    bmi.bmiHeader.biSizeImage = 0; // unused for BI_RGB
    bmi.bmiHeader.biXPelsPerMeter = 0;
    bmi.bmiHeader.biYPelsPerMeter = 0;
    bmi.bmiHeader.biClrUsed = 0;
    bmi.bmiHeader.biClrImportant = 0;
    bmi.bmiColors[0].rgbBlue = 0;
    bmi.bmiColors[0].rgbRed = 0;
    bmi.bmiColors[0].rgbGreen = 0;
    bmi.bmiColors[0].rgbReserved = 0;


    hBmp = CreateDIBSection( hdc_
    , &bmi
    , DIB_RGB_COLORS
    , &imageBuff //pointer to created buf
    , NULL
    , 0);

    dcMem = ::CreateCompatibleDC(hdc_);//creates a memory compatible
    device context (DC)passing exixting DC
    (HBITMAP) ::SelectObject(dcMem, hBmp); //selects handle of image to
    Device
    //context dcMem
    apoorv, Feb 14, 2005
    #1
    1. Advertising

  2. Re: Image getting skewed [OT]

    "apoorv" <> wrote in message
    news:...
    > I am writing a imaging aplication on VC++.I have to display images and
    > apply effects onto it.Images could be of any type like jpg,gif,bmp,psd...M
    > uding createDibSection API.it requires BITMAPINFO struc as one of its
    > parameters.Its working well(Images are successfully displayed) but my
    > problem is that in certain images(of any type)they are skewed and becomes
    > B/W(means Data corruption).U can see my code of populating BITMAPINFO and
    > CreateDibSection...Can any body help me in solving the annoying probs.

    Most likely this is related to a padding issue: on many systems, the
    data for each row of pixels needs to be aligned to an address that
    is a multiple of 2 (or 4). If data for a pixel row has an odd size,
    padding bytes need to be inserted.

    But, ahem, what was your C++ question ?

    --
    http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
    Ivan Vecerina, Feb 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    840
    Roedy Green
    Sep 19, 2005
  2. help
    Replies:
    2
    Views:
    389
  3. Laszlo Zsolt Nagy
    Replies:
    1
    Views:
    1,252
    Kartic
    Jan 26, 2005
  4. Replies:
    3
    Views:
    383
  5. Paul Hemans
    Replies:
    2
    Views:
    2,095
    Paul Hemans
    May 9, 2010
Loading...

Share This Page