469,950 Members | 2,341 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Image getting corrupt


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...
I am using 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 resultant image is displayed well.]

BITMAPINFO bmi;

bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biWidth
= swidth;//Image width
bmi.bmiHeader.biHeight = -sheight;//Image Height
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biCompression =
BI_RGB; //uncompressed bmi.bmiHeader.biSizeImage =
0; 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 //pointerto 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
toDevice

--
apoorv
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 17 '05 #1
1 1107
On Mon, 14 Feb 2005 09:47:52 -0600, apoorv
<ap***********@mail.codecomments.com> wrote:

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...
I am using 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 resultant image is displayed well.]


Scan lines must be multiples of 4 bytes.

So, for a 3-pixel wide 24-bit BGR image, each scanline will be 12
bytes, the last 3 unused.

Here's an easy way to calculate the required width of a row for a
specific width and bits-per-pixel:

scanwid = (((width * bpp + 7) / 8) + 3) & ~3;

Of course, to create the number of bytes required for the image data,
you need to multiply this scanwid by the image height.

--
Sev
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Bjarte Andreassen | last post: by
303 posts views Thread by mike420 | last post: by
4 posts views Thread by moondaddy | last post: by
35 posts views Thread by Stan Sainte-Rose | last post: by
6 posts views Thread by nichughes | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.