BOOL WINAPI WriteImage(WCHAR *lcSource, WCHAR *lcInsert, int lnLeft, int lnTop) { GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; try { GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); } catch(...) { return 0; } CLSID loEncoderId; if (GetEncoderClsid(lcSource,&loEncoderId) == -1) { GdiplusShutdown(gdiplusToken); return 0; } Image *image = NULL; Image *insert = NULL; // Create an image and a thumbnail of the image. try { image = new Image(lcSource); //image = NULL; } catch(...) { return 0;} try { insert = new Image(lcInsert); } catch(...) { delete image; return 0;} if (image == NULL || insert == NULL) return 0; // *** Create a new bitmap to draw on Bitmap *tBitmap = new Bitmap(672,16); // *** Create device from it Graphics *graphics = new Graphics(tBitmap); // Draw the original source image into the dest Rect. Leave original dimensions to scale. int lnResult = graphics->DrawImage(image,0,0,image->GetWidth(),image->GetHeight()); lnResult = graphics->DrawImage(insert,lnLeft,lnTop,insert->GetWidth(),insert->GetHeight()); delete image; delete insert; try { DeleteFile(lcSource); // must delete file or size may not be updated tBitmap->Save(lcSource,&loEncoderId,NULL); } catch(...) { delete graphics; delete tBitmap; GdiplusShutdown(gdiplusToken); return 0;} delete graphics; delete tBitmap; GdiplusShutdown(gdiplusToken); return 1; } BOOL WINAPI ReadImage(WCHAR *lcSource, WCHAR *lcTarget, int lnLeft, int lnTop, int lnWidth, int lnHeight) { GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; try { GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); } catch(...) { return 0; } CLSID loEncoderId; if (GetEncoderClsid(lcTarget,&loEncoderId) == -1) { GdiplusShutdown(gdiplusToken); return 0; } // Create an image and a thumbnail of the image. Image *image = NULL; try { image = new Image(lcSource); } catch(...) { return 0; } Bitmap *tBitmap = new Bitmap(lnWidth,lnHeight); Graphics *graphics = new Graphics(tBitmap); Rect destinationRect(0,0,lnWidth,lnHeight); int lnResult = graphics->DrawImage(image,destinationRect,lnLeft,lnTop,lnWidth,lnHeight,UnitPixel); // Draw the original source image into the dest Rect. Leave original dimensions to scale. // lnResult = graphics->DrawImage(image,destinationRect,0, 0,lnImageWidth,lnImageHeight,UnitPixel); try { DeleteFile(lcTarget); // must delete file or size may not be updated tBitmap->Save(lcTarget,&loEncoderId,NULL); } catch(...) { delete graphics; delete tBitmap; GdiplusShutdown(gdiplusToken); return 0;} delete image; GdiplusShutdown(gdiplusToken); return 1; }Hope this helps someone out too...
>int main(int argc, char* argv[]) >{ >// HIMAGELIST hIL = ImageList_Create(32, 32, ILC_COLOR8, 0, 1); > HIMAGELIST hIL = ImageList_LoadImage(NULL, "strip.bmp", 32, 0, 0, IMAGE_BITMAP, LR_LOADFROMFILE); > > HICON hIcon = (HICON)LoadImage(NULL, "30.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE); > ImageList_AddIcon(hIL, hIcon); > DeleteObject(hIcon); > > hIcon = (HICON)LoadImage(NULL, "31.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE); > ImageList_AddIcon(hIL, hIcon); > DeleteObject(hIcon); > > IMAGEINFO ImageInfo; > ImageList_GetImageInfo(hIL, 0, &ImageInfo); > > PICTDESC PictDesc; > PictDesc.cbSizeofstruct = sizeof(PICTDESC); > PictDesc.picType = PICTYPE_BITMAP; > PictDesc.bmp.hbitmap = ImageInfo.hbmImage; > PictDesc.bmp.hpal = NULL; > IPicture* iPic; > OleCreatePictureIndirect(&PictDesc, IID_IDispatch, FALSE, (LPVOID*) &iPic); > > BSTR bstrFile = SysAllocString(L"result.bmp"); > OleSavePictureFile((IDispatch*)iPic, bstrFile); > SysFreeString(bstrFile); > iPic->Release(); > > return 0; >} >>