This scales the image into the area defined by Pict->Col1, Pict->Row1, Pict->Col2 and Pict->Row2 and the clear PNG image becomes blurry because of this scaling. I do not want the image scaled at all, and I want it to be 100% its original size starting at row rw col 0. How do I do this?
P.S. In Excel itself, when I click on the blurry scaled image, a picture toolbar appears which has a "Reset Picture" button on it. When I click this, the image reverts to its original clear form and this is the result I want.
int ii,jj,lpx; TSheet *mjsh=XLSRW1->Sheets->Items[0];
TMSOPicture* msoPict=XLSRW1->MSOPictures->Add();
msoPict->LoadFromFile(imgnam);
TDrwPicture* drwPict=mjsh->DrawingObjects->Pictures->Add();
drwPict->PictureId=XLSRW1->MSOPictures->Count; drwPict->Col1=0; drwPict->Row1=rw;
drwPict->Col1Offset=0; drwPict->Row1Offset=0;
jj=0; ii=0;
while (jj<chhei)
{
mjsh->Rows->AddIfNone(0); lpx=mjsh->Rows->Items[0]->PixelHeight; if (jj+lpx>chhei) break;
jj+=lpx; ++ii;
}
rw+=ii; drwPict->Row2=rw; if (jj<chhei) drwPict->Row2Offset=(double)(chhei-jj)/lpx;
jj=0; ii=0;
while (jj<chwid)
{
mjsh->Columns->AddIfNone(ii,1); lpx=mjsh->Columns->Items[ii]->PixelWidth; if (jj+lpx>chwid) break;
jj+=lpx; ++ii;
}
drwPict->Col2=ii; if (jj<chwid) drwPict->Col2Offset=(double)(chwid-jj)/lpx;
I have fixed row heights and variable column widths. I step through height and width until I would overflow the image width and height and then set offsets to accomodate the remainder (overflow beyond a whole row or column height or width).
Here is Delphi Code. It is a passed in procedure ( We have a lot of excel exports, so it was refactored down to a single line call and have one routine do all of the coding) LOGO is a Global varible:
Procedure LoadPic(var aXLS: TXLSReadWriteII4; var cl, rw, ImgWid, ImgHgt, ts : Integer);
var ii, jj, lpx: Integer;
aSht : TSheet;
msoPict : TMSOPicture;
drwPict : TDrwPicture;
begin
aSht := aXLS.Sheets.Items[ts];
msoPict := aXLS.MSOPictures.Add;
msoPict.LoadFromFile(LOGO);
while jj < ImgHgt do
begin
aSht.Rows.AddIfNone(ts);
lpx := aSht.Rows.Items[ts].PixelHeight;
if (jj + lpx) > ImgHgt then break;
Inc(jj, lpx);
inc(ii);
end;
inc(rw, ii);
drwPict.Row2 := rw;
if jj < ImgHgt then
drwPict.Row2Offset := ( ImgHgt - jj ) / lpx;
jj := 0;
ii := 0;
while jj < ImgWid do
begin
aSht.Columns.AddIfNone(ii, 1);
lpx := aSht.Columns.Items[ii].PixelWidth;
if (jj + lpx) > ImgWid then break;
inc(jj, lpx);
inc(ii);
end;
drwPict.Col2 := ii;
if jj < ImgWid then
drwPict.Col2Offset := (ImgWid-jj) / lpx;
end;