In article <_8cM5.232$kn2.395...@newsr1.u-net.net>, "David Gollings"
Quote
<d...@bullart.com> writes:
>Ok, I think I get it... The only problem is the pictures are of paintings
>and to drop the colour resolution down to 16 would show a bad image. :(:(
>The other alternative that I have would be to trap the error and bypass the
>image but I don't know how to do this. I have tried a try...except
>statement, but to no joy If I can do this then I can see which images are
>causing the problem and then get a better idea of how to deal with it.
>A thought... would changing the video drivers colour in the settings down to
>a lower colour palette solve the problem, I will try.
>Regards
>Dave
Can I suggest trying something. I have a suspicion that on some machines
selecting a palette into a device that doesn't need one (>256 cols) causes
problems. TMetafile.Draw selects the palette into the dc without any checks to
see if it's appropriate.
I'd try it myself but I don't have access to a machine that raises any errors.
Create your own metafile TMyMetafile = class(TMetafile) and replace the Draw
method with the one below it may well tell you if this is the source of the
problem.
Alternatively, temporarily copy Graphics.Pas to your compile directory and
'Add' it to your project. Then modify the source as below.
PaletteDevice can also be supplimented with the following as a double check but
I'm not sure it's neccessary.
if GetDeviceCaps(aCanvas.Handle, RASTERCAPS) = RC_PALETTE then
//it's a palette device
I've not written and checked this in Delphi so there could be syntax errors
procedure TMetafile.Draw(ACanvas: TCanvas; const Rect: TRect);
var
MetaPal, OldPal: HPALETTE;
R: TRect;
PaletteDevice: boolean;
begin
if FImage = nil then Exit;
//the check for color depth
PaletteDevice:= (GetDeviceCaps(ACanvas.Handle, PLANES) *
GetDeviceCaps(ACanvas.Handle, BITSPIXEL)) <= 8;
MetaPal := Palette;
OldPal := 0;
//apply color depth check
if (MetaPal <> 0) and PaletteDevice) then
begin
OldPal := SelectPalette(ACanvas.Handle, MetaPal, True);
RealizePalette(ACanvas.Handle);
end;
R := Rect;
Dec(R.Right); // Metafile rect includes right and bottom coords
Dec(R.Bottom);
PlayEnhMetaFile(ACanvas.Handle, FImage.FHandle, R);
//check again
if (MetaPal <> 0) and PaletteDevice) then
SelectPalette(ACanvas.Handle, OldPal, True);
end;
Gordon
~~~~~~~~~~~~~~~~~~~~~~~~
Equation Illustrator V Graphics and Equation Editor http://www.mgcsoft.com/
MGCSoft
"Where graphics meets mathematics"
http://members.aol.com/delphistuf/delphstf.htm (Delphi bits and bobs)