CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2010
    Posts
    37

    How to update the internal thmbnail of a jpg image ?

    I use the Bitmap class of GDI+ to access and modify a jpeg image.
    However after saving, the internal thumbnail is not updated.
    How can I update it ?
    I think I should use PropretyItem but don't know how exactly.
    Does anyone has a sample code to do this ?
    Last edited by neoneuf; February 6th, 2012 at 04:19 AM.

  2. #2
    Join Date
    Mar 2010
    Posts
    37

    Re: How to update the internal thmbnail of a jpg image ?

    nobody knows ?

  3. #3
    Join Date
    Mar 2010
    Posts
    37

    Re: How to update the internal thmbnail of a jpg image ?

    Finally I found how to do it.
    The idea is to create a new bitmap (jpeg here) using the Clone method.
    When the clone bitmap is created the metadata (and so the thumbnail) are not copied.
    So first I save the metadata of the original bitmap.
    Then I create the clone.
    Then I copy the metadata except the thumbnail to the clone bitmap.
    When I save the clone bitmap, it creates automatically a new thumbnail and add it to the metadata of the clone bitmap.
    Here is the code if someone needs to do the same thing.

    BTW, if someone knows how to configure the encoder (for example to choose the compression ratio of the jpeg) I'm interested...

    Code:
    // Save the metadata
    UINT totalBufferSize;
    UINT numProperties;
    orginalBMP.GetPropertySize(&totalBufferSize, &numProperties);
    PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
    orginalBMP.GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
    
    // Create the clone
    Bitmap * pCloneBMP=orginalBMP.Clone(0,0,pres.GetWidth(),pres.GetHeight(),pres.GetPixelFormat());
    
    //Copy all the metadata except the thumbnail
    for(UINT j = 0; j < numProperties; ++j)
    {
           if (pAllItems[j].id==0x501B) continue; //avoid copying the existing thumbnail
    
    	pCloneBMP->SetPropertyItem(&pAllItems[j]);
    }
    
    free(pAllItems);	
    
    // Save the clone : this will create a new thumbnail
    CLSID Clsid;
    GetEncoderClsid(L"image/jpeg", &Clsid);
    pCloneBMP->Save(FileName.AllocSysString(), &Clsid, NULL); //FileName is a CString
    Last edited by neoneuf; February 8th, 2012 at 05:59 PM.

  4. #4
    Join Date
    Mar 2012
    Location
    Australia
    Posts
    5

    Re: How to update the internal thmbnail of a jpg image ?

    The thumbnail is part of the EXIF profile. ImageMagick only updates the resolution of the EXIF profile. For the thumbnail you'll need another utility..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured