I have a specialized need, and though it seems as though it should not be difficult, it is something with which I have no experience.

I have a specialized need, and though it seems as though it should not be difficult, it is something with which I have no experience.

I must insert a graphic image into a spreadsheet, and the spreadsheet component we use insists on a rectangle of cells for placement, then resizes the image to fit the given rectangle. What I need as a workaround is to put the image at its normal size into a rectangular image that is the size of the target area of white.

My naive first thought is to create a TImage of the size needed for the target, and fill it with white. Then load the graphic into a second TImage, and copy that bitmap, then paste it to the upper left in the first TImage. Is that workable?

I am not looking for performance here, just a workaround for an otherwise unresolvable limitation in a third party component which we will not be updating.

If anyone can suggest a very simple solution, it need not be elegant, just workable. And hopefully without adding yet another large library to the mix.

Comments

  1. Asbjørn Heid So there I was, happy as a clam. Until it blew up. Some of the logos are in JPG, some are in BMP. The old code used to load from the file to a TMSOPicture, a proprietary class from the vendor of the spreadsheet comp. But to trick them into not distorting my image, I am loading to a TImage. 

    In my tests, I happened to be on a setup where the logo file was a JPG. Now I have switched to a different DB, and the logo is a BMP.

    The LoadFromStream() for the spreadsheet component must be given the filename, and then does its own testing to see whether it is a BMP. When it is, it then checks to see whether the stream size is > 32767, and rejects it if it is.

    My BMP file is 21K. After I call Image1.Picture.SaveToStream(), the stream size is 121K!! So now, I suppose, one choice might be to save to JPG, then reload...  Looking for ideas.  The third-party code is... interesting.

    ReplyDelete
  2. Never mind...  I got it. And it's making me rethink how I handle different image formats. I may just open in TImage, then assign to TJpegImage, just because the component seems to have better support for JPG.

    ReplyDelete

Post a Comment