Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC7.1
Hi Experts,
 
How to do this??
 
Thanks
Posted 23-May-12 23:33pm
Comments
Code-o-mat at 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
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 Sergey Alexandrovich Kryukov 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 24 May 2012
Copyright © CodeProject, 1999-2014
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