Click here to Skip to main content
12,945,927 members (54,335 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi Experts,

How to do this??

Thanks
Posted 23-May-12 22:33pm
Comments
Code-o-mat 24-May-12 4:41am
   
your question is a bit vague, give some more details about what you want to do, otherwise we can only try and guess...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

1. Load image using package of choice - GDI+, CxImage, etc
2. Create HBITMAP from image
3. Call GetDIBits on the HBITMAP

When inserting image data into PDFs, one must perform the same steps. Here's the code I use for this task: (Note: you also have to add code to initialize and shutdown GDI+)

// BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF
HBITMAP mLoadImg(WCHAR *szFilename)
{
    HBITMAP result=NULL;
 
    Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFilename,false);
    bitmap->GetHBITMAP(NULL, &result);
    delete bitmap;
    return result;
}
 
// Returns the DI (Device Independent) bits of the Bitmap
// Here I use 24 bit since it's suppported in pdf
// result is width*height*3 bytes (24 bit)
char unsigned *myGetDibBits24(HBITMAP hBmpSrc)
{
    BITMAPINFO bi;
    BITMAP bm;
    BOOL bRes;
    char unsigned *buf, *result;
    long outIndex, inIndex;
    long width, height, x, y;
 
    HDC memDC;
    HBITMAP oldBmp;
 
    memDC = CreateCompatibleDC(NULL);
    oldBmp = (HBITMAP)SelectObject(memDC, hBmpSrc);
 
    GetObject(hBmpSrc, sizeof(bm), &bm);
    width = bm.bmWidth;
    height = bm.bmHeight;
 
    bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
    bi.bmiHeader.biWidth = width;
    bi.bmiHeader.biHeight = -height;
    bi.bmiHeader.biPlanes = 1;
    bi.bmiHeader.biBitCount = 32;
    bi.bmiHeader.biCompression = BI_RGB;
    bi.bmiHeader.biSizeImage = 0;//bm.bmWidth * 4 * bm.bmHeight;
    bi.bmiHeader.biClrUsed = 0;
    bi.bmiHeader.biClrImportant = 0;
 
    buf = new unsigned char[width * 4 * height];
    bRes = GetDIBits(memDC, hBmpSrc, 0, bm.bmHeight, buf, &bi, DIB_RGB_COLORS);
 
    SelectObject(memDC, oldBmp);
    if (!bRes)
    {
        delete(buf);
        buf = NULL;
    }
    DeleteDC(memDC);
 
    result = new unsigned char[width*height*3];
 
    outIndex = 0;
    inIndex = 0;
    for (y=0; y<height;>    {
        inIndex = y * bm.bmWidthBytes;
 
        for (x=0; x<width;>        {
            result[outIndex++] = buf[inIndex+2];
            result[outIndex++] = buf[inIndex+1];
            result[outIndex++] = buf[inIndex];
            inIndex += 4;
        }
    }
    delete(buf);
 
    return result;
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Technically speaking a jpeg image is just an array of bytes (like any other file).
However, I suppose, you actually want to gain access to pixel values. I think the easy way is loading the image using the CImage class and then using the CImage::GetBits[^] method.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,205
Maciej Los 2,453
Jochen Arndt 1,935
ppolymorphe 1,795


Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 24 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100