Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Clip Images
Message
General information
Forum:
Visual FoxPro
Category:
Pictures and Image processing
Title:
Miscellaneous
Thread ID:
00740884
Message ID:
00741225
Views:
22
Thanks Alexander,

That looks pretty good.

Turns out that I looked into the GDI+ stuff yesterday and that works relatively easily, so I got it working that way. For my specific application it was going to be easier to write everything out to file and import back in.

FWIW, here's the code for the two functions which basically allow you to read one image from the strip at a time into a file, then write them back one at a time. The main advantage here is that this is using GDI+ which means I can accept images in most common image formats as input, not just BMP files.
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...

+++ Rick ---



>Yes, you can make all what you want using Windows (not ActiveX) ImageList control. This piece of C++ code may be helpful:
>
>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;
>}
>
>
>>Hi all,
>>
>>I need to display and edit a strip of images contained in a single bmp image and before I run off and write some GDI+ code I thought I check to see if somebody has seen a control that possibly could help with this.
>>
>>What I need to do is basically be able to display all the images to the user, allow the user to load a new image into the strip and save it back out.
>>
>>The Picture Clip control can help me display the data - that part is easy, but I have not seen any tools that let you write the data back in in some way.
>>
>>For some reason I thought that the ImageList control uses a tabstrip like image internally that can somehow be coerced out of it - that would be ideal as you can simply load the thing up and then potentially save the raw image data.
>>
>>Any ideas? Basically what I need is like an editable PictureClip control.
>>
>>Yeah, you're probably asking what the hell do you need this for - well, braindead Win32 Image code in HTML Help requires icons to be loaded in an image strip and I want to be able to edit these and create new icons.
>>
>>+++ Rick ---
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform