WPCubed Product Support

WPRichText to WPDFExport - BMP Comes out Black

Correct, it's not happening within the wPDF, it's going on when you move from Rich Text to wPDFExport. Rich Text (multiple types tested) is fine, can even save and reload to/from blob streams... moving into the wPDF export causes the problem.

Oh well, just have to cut the Delphi 4 code out of the support area and move forward only with Delphi 7

#12 ♥ 0
18.3k Views 2 users read 4 min
support

This problem has to do with memory management - it does not happen inside wPDF. In WPTools I took precautions using GlobalAlloc - that the only way to avoid it. I am not sure why Delphi 4 makes a difference since GloablAlloc is not a VCL, but a windows function.

Julian

#11 ♥ 0

fyi, this problem does not occur in Delphi 7, just Delphi 4.

#10 ♥ 0

WPEmOBJ.PAS is using GloabalAlloc... doesn't seem to get called though. it's in the TWPOImage.Paint method.

If I could understand greater how the images were transfered I might be able to figure it out. This is a very odd little problem that happens ONLY the first time you try it just after starting the application. Do it again and all is just fine.

I'm at a loss!

#9 ♥ 0
support

Did you check the unit WPEmOBJ.PAS? It must use the GloabalAlloc.

If you use your own code to draw images you need to use GlobalAlloc as well, that is not specify to wPDF - it can be problematic with any printing code, too.

Julian

#8 ♥ 0

Still looking into this issue and unable to find any place other than the PDFExport component in which there is a failure of some sort, any additional ideas?

#7 ♥ 0

I do not find either lines being used either in my application or within your source.

I do have:

Buf           := GlobalLock(hMem);

where buf is a var or pointer. This is done when my scanner is done reading memory and is working properly.

The entire piece of code where that is found is

procedure TTwain.csTwainScanMemoryReady(Sender: TObject; hMem: Cardinal);
var
  BmpFile : TFileStream;
  Bmf     : TBitmapFileHeader;
  Buf     : pointer;
  FilePath: string;
begin
  FilePath      := ExtractFilePath(Application.ExeName);

  BmpFile       := TFileStream.Create(FilePath + cScanFile+inttostr(ScanNo)+'.BMP', fmCreate);
  Inc(ScanNo);
  Bmf.bfType    := $4D42;
  Bmf.bfSize    := SizeOf(Bmf) + GlobalSize(hMem);
  Bmf.bfOffBits := SizeOf(TBitmapInfoHeader);
  Buf           := GlobalLock(hMem);
  try
    BmpFile.Write(Bmf, SizeOf(Bmf));
    BmpFile.Write(Buf^, GlobalSize(hMem));
  finally
    GlobalUnlock(hMem);
    BmpFile.Free;
  end;

end;

Where should I be using these two lines which you reference?

#6 ♥ 0
support

Please chedck in file if the lines

ImageHandle := GlobalAlloc(GMEM_MOVEABLE, ImageSize);
Image := GlobalLock(ImageHandle);

are used.

#5 ♥ 0

Also, just FYI, after I insert the bmp files into the RichText, I can see the images properly in the RichText object.

It's when the pdfexport.source = richtext where the error seems to come in.

#4 ♥ 0

WPDFView 1.1 and WPTools 4 is what is being used.

I imagine that it has to do with memory management, however it's eluding all 3 of us developers over here.

All is being created and free'd up equally which suggests it should give a black page each and everytime this function is done instead of just on the first time the application is run.

It's pretty odd. Still having the same issue and have had to put it on hold because we are stumbling along here.

#3 ♥ 0
support

Hi,

Which version of the components do you use. This problem has to do with the memory management - I check if V5 uses the 'save' method.

Julian

#2 ♥ 0

I am inserting BMP objects from a Scanner into a WPRichText as follows:

Bitmap := TBitmap.Create;    Try       Bitmap.LoadFromFile(FilePath);       Image1.Picture.Assign(Bitmap); //TImage       RichText.TextObjects.Insert(NewObject(Image1));   Finally      Bitmap.Free;   End;

The NewObject function is as follows:

Function  TTwain.NewObject(Img : TImage) : TWPOImage;begin    Result := TWPOImage.Create(Self);    Result.Picture.Assign(Img.Picture);    Result.WidthTW := Result.ContentsWidth;    Result.HeightTW := Result.ContentsHeight;end;

That is all working fine and dandy, however, I need to then save the contents to a PDF file. I'm doing this as:

PDFExport.Source := RichText; //PDFExport is TWPPDFExport object on form

          PDFExport.Filename := ('c:\test.pdf');
          PDFExport.BeginDoc;
          PDFExport.Print;
          PDFExport.EndDoc;

The odd problem that I am getting is as follows:

The very first time I run my application, if I insert 2 BMP's into the RichText then the first BMP is exported as a Black Square in the resulting PDF file. The second image inserted is just fine.

If I close the form (not the application) and go back to the form and perform the exact same thing (insert 2 BMP's into RichText and export it) then all is just fine.

If I only insert 1 BMP into the richtext and insert it works great everytime.

The only problem seems to be if there are multiple BMP's being exported, and ONLY the first time my application runs.

Any clues?

#1 ♥ 0