svvada
asked on
Save form to metafile
I'm trying to save my form to a metafile.
I've tried just creating a Tmetafile and using GetFormImage to accuire the form which worked just fine. But the file size is the same as if I just save it as a bitmap. So my real question is how can I get the metafile smaller.
I've tried just creating a Tmetafile and using GetFormImage to accuire the form which worked just fine. But the file size is the same as if I just save it as a bitmap. So my real question is how can I get the metafile smaller.
Sorry, make sure you place in the Uses section - JPEG
procedure TForm1.Button1Click(Sender : TObject);
var
DestR : TRect;
Bmp: TBitmap;
Jpg: TJpegImage;
begin
Bmp:= TBitmap.Create;
Bmp.Width := Self.ClientRect.Right - Self.ClientRect.Left;
Bmp.Height := Self.ClientRect.Bottom - Self.ClientRect.Top;
DestR := Rect(0,0,Bmp.Width , Bmp.Height);
Bmp.Canvas.CopyRect(DestR, Canvas, Self.ClientRect);
Jpg := TJpegImage.Create;
JPg.CompressionQuality:= 70;
Jpg.Assign(Bmp);
Jpg.SaveToFile('C:\Test.jp g');
end;
When I tested this, the Bitmap was 2,041 KB and the JPEG was 13 KB
ShaneHolmes
procedure TForm1.Button1Click(Sender
var
DestR : TRect;
Bmp: TBitmap;
Jpg: TJpegImage;
begin
Bmp:= TBitmap.Create;
Bmp.Width := Self.ClientRect.Right - Self.ClientRect.Left;
Bmp.Height := Self.ClientRect.Bottom - Self.ClientRect.Top;
DestR := Rect(0,0,Bmp.Width , Bmp.Height);
Bmp.Canvas.CopyRect(DestR,
Jpg := TJpegImage.Create;
JPg.CompressionQuality:= 70;
Jpg.Assign(Bmp);
Jpg.SaveToFile('C:\Test.jp
end;
When I tested this, the Bitmap was 2,041 KB and the JPEG was 13 KB
ShaneHolmes
Also, as for the MetaFile you created - did you set its Enhanced property to false?
M:= TMetaFile.Create;
M.Enhanced:= False;
ShaneHolmes
M:= TMetaFile.Create;
M.Enhanced:= False;
ShaneHolmes
ASKER
ShaneHolmes,
Thanks for the input but I want to make a metafile, and I want to save it as both types (emf and wmf). The TChart component has the functionality I'm looking for, but I haven't got the source for that. The bitmap file generated by TChart is 391KB while emf is 4KB and wmf is 6KB.
Thanks for the input but I want to make a metafile, and I want to save it as both types (emf and wmf). The TChart component has the functionality I'm looking for, but I haven't got the source for that. The bitmap file generated by TChart is 391KB while emf is 4KB and wmf is 6KB.
Can you post your code, so we can see where you are going wrong....?
Also, did you see my last wquestion above - please reply so i know you .... thanks
Also, did you see my last wquestion above - please reply so i know you .... thanks
I can't seemt o get the Metafile the same size as the bmp.
Its always larger
Metafile = 3,585 KB
Bitmap = 2,041 KB
procedure TForm1.Button1Click(Sender : TObject);
var
DestR : TRect;
Bmp: TBitmap;
MetaFile : TMetaFile;
MetaFileCanvas : TMetaFileCanvas;
begin
Bmp:= TBitmap.Create;
Bmp.Width := Self.ClientRect.Right - Self.ClientRect.Left;
Bmp.Height := Self.ClientRect.Bottom - Self.ClientRect.Top;
DestR := Rect(0,0,Bmp.Width , Bmp.Height);
Bmp.Canvas.CopyRect(DestR, Canvas, Self.ClientRect);
Bmp.SaveToFile('C:\Test.bm p');
MetaFile := TMetaFile.Create;
MetaFile.Width:= BMp.Width;
MetaFile.Height:= Bmp.Height;
MetaFileCanvas := TMetaFileCanvas.Create(Met aFile, 0);
MetaFileCanvas.Draw(0,0, Bmp);
MetaFileCanvas.Free;
//MetaFile.Enhanced := False; {Optional}
MetaFile.SaveToFile('C:\te st.wmf'); {Optional}
MetaFile.Free;
end;
Id be interesed in seeing your code where your metafile is the same size as the bitmap
Shane
Its always larger
Metafile = 3,585 KB
Bitmap = 2,041 KB
procedure TForm1.Button1Click(Sender
var
DestR : TRect;
Bmp: TBitmap;
MetaFile : TMetaFile;
MetaFileCanvas : TMetaFileCanvas;
begin
Bmp:= TBitmap.Create;
Bmp.Width := Self.ClientRect.Right - Self.ClientRect.Left;
Bmp.Height := Self.ClientRect.Bottom - Self.ClientRect.Top;
DestR := Rect(0,0,Bmp.Width , Bmp.Height);
Bmp.Canvas.CopyRect(DestR,
Bmp.SaveToFile('C:\Test.bm
MetaFile := TMetaFile.Create;
MetaFile.Width:= BMp.Width;
MetaFile.Height:= Bmp.Height;
MetaFileCanvas := TMetaFileCanvas.Create(Met
MetaFileCanvas.Draw(0,0, Bmp);
MetaFileCanvas.Free;
//MetaFile.Enhanced := False; {Optional}
MetaFile.SaveToFile('C:\te
MetaFile.Free;
end;
Id be interesed in seeing your code where your metafile is the same size as the bitmap
Shane
ASKER
OK here's my code, it's the enhanced file (emf) that is the same size as the bitmap, the wmf is larger that's probably what you're doing right?
procedure TForm1.bitmap2emf;
var
Metafile: TMetafile;
MetaCanvas: TMetafileCanvas;
Bitmap : TBitmap;
begin
Metafile := TMetaFile.Create;
try
BitMap := GetFormImage;
try
Metafile.Height := BitMap.Height;
Metafile.Width := BitMap.Width;
MetaCanvas := TMetafileCanvas.Create(Met afile, 0);
try
MetaCanvas.Draw(0, 0, GetFormImage);
finally
MetaCanvas.Free;
end;
Metafile.SaveToFile('e:\te st.emf');
Metafile.Enhanced := False;
Metafile.SaveToFile('e:\te st.wmf');
BitMap.SaveToFile('e:\test .bmp');
finally
Bitmap.Free;
end;
finally
Metafile.Free;
end;
end;
procedure TForm1.bitmap2emf;
var
Metafile: TMetafile;
MetaCanvas: TMetafileCanvas;
Bitmap : TBitmap;
begin
Metafile := TMetaFile.Create;
try
BitMap := GetFormImage;
try
Metafile.Height := BitMap.Height;
Metafile.Width := BitMap.Width;
MetaCanvas := TMetafileCanvas.Create(Met
try
MetaCanvas.Draw(0, 0, GetFormImage);
finally
MetaCanvas.Free;
end;
Metafile.SaveToFile('e:\te
Metafile.Enhanced := False;
Metafile.SaveToFile('e:\te
BitMap.SaveToFile('e:\test
finally
Bitmap.Free;
end;
finally
Metafile.Free;
end;
end;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Perfectly Stated - Slick812 - I think you even helped me better understand something... thanks!
ShaneHolmes
ShaneHolmes
ASKER
Thanks Slick812 and Shane, this has helped my understanding of how this works.
var
DestR : TRect;
Bmp: TBitmap;
Jpg: TJpegImage;
begin
Bmp:= TBitmap.Create;
Bmp.Width := Self.ClientRect.Right - Self.ClientRect.Left;
Bmp.Height := Self.ClientRect.Bottom - Self.ClientRect.Top;
DestR := Rect(0,0,Bmp.Width , Bmp.Height);
Bmp.Canvas.CopyRect(DestR,
Jpg := TJpegImage.Create;
JPg.CompressionQuality:= ?
Jpg.Assign(ABitmap);
Jpg.SaveToFile('C:\Test.jp
end;
ShaneHolmes