You are not logged in.
Pages: 1
I need some advice.
I have develop a small component that use a TPaintBox, I use the TPainBox to draw on canvas some objects (line, point, circle, ...).
Now I need save my canvas as a TIFF with specific size and resolution (200 dpi) if possible with antialiased.
I'd like know if and how can I do it with your framework. Is it possible? It there a piace of code about it? Which is the more easy way to not rewrite all my code?
Thanks
Offline
Just search for "TIFF" in the forum and you'll find out your way.
Basically:
- Create a TMetaFile with the expected size;
- Draw directly on it using an associated TMetaFileCanvas instance (do not draw from a TPaintBox bitmap, but you should better share the code for the drawing - e.g. making a sub-method taking a TCanvas as a parameter, which may be either a TPaintBox canvas, either a TMetaFileCanvas);
- Play the metafile using SynGdiPlus to render it into a bitmap;
- Save the bitmap into TIFF using SynGdiPlus.
As an alternative, you may use SynGDIPlus to make all the drawing instead of writing directly to the TPaintBox canvas: all your drawings would be anti-aliased and would have much better rendering result. Just draw the rendered bitmap in TPaintBox.Draw (letting the bitmap be cached for better speed).
Offline
OK.
For example I want create a 10x11 inch image with 100 dpi.
I can use:
var Bmp: TBitmap;
MF: TMetaFile;
MetafileCanvas: TMetafileCanvas;
begin
Gdip := TGDIPlusFull.Create('gdiplus.dll');
MF := TMetaFile.Create;
MF.Width := 1000;
MF.Height := 1100;
MetafileCanvas := TMetafileCanvas.Create(MF, 0);
MetafileCanvas.Brush.Color := clRed;
MetafileCanvas.Brush.Style := bsDiagCross;
MetafileCanvas.Ellipse(50, 50, 300 - 50, 200 - 50);
MetafileCanvas.Free;
Bmp := Gdip.DrawAntiAliased(MF);
Image1.Picture.Assign(Bmp);
SynGDIPlus.SaveAs(Bmp, 'c:\test.tif', gptTIF);
Bmp.Free;
MF.Free;
FreeAndNil(GdiP);
end;
In this way the TIFF have always 96 DPI (screen resolution). How can I change it?
Thanks
Last edited by array81 (2012-07-30 17:24:32)
Offline
I have check the code. I think in this moment is not possible set DPI.
Is it possible add this feature?
Offline
See http://synopse.info/fossil/info/5850eaeb4b
Should be able to set the DPI, as such:
Bmp := Gdip.DrawAntiAliased(MF);
Image1.Picture.Assign(Bmp);
SynGDIPlus.SaveAs(Bmp, 'c:\test.tif', gptTIF, 80, 0, 200); // force 200 DPI
Bmp.Free;
Offline
Many thanks.
Other question
Is there a way to set color depth? I need of a tiff with 1bit of color (only black and with, no gray scale). Is it possible?
Thanks again.
Last edited by array81 (2012-08-02 22:43:55)
Offline
You can set the Bmp to be black and white, as such:
Bmp.Monochrome := true;
But the default GDI implementation is very rough and rude.
Result may probably be not aesthetically correct at all.
You'll loose all anti-aliasing features of GDI+, which, like every anti-aliasing, use half tones.
You would need a sub-sample algorithm, like Floyd-Steinberg.
But it is out of the scope of this library, I'm afraid!
Offline
I have solved using ord(evCompressionCCITT4) on SynGDIPlus.SaveAs.
Thanks
Offline
I don't understand the minimum to use the SynGDIPlus.
I have tested my code on Windows 7 without problem, but on Windows XP I get a TIF image of 0 kb...
Which OS I need? Is there a way to extend the use?
Offline
For TIFF support, it will depend on the image WIC drivers available in the OS.
I suspect you will find you answer on Google.
See for instance http://msdn.microsoft.com/en-us/library … 85%29.aspx
Perhaps the WIC update would help: http://www.microsoft.com/en-us/download … aspx?id=32
Offline
My searches have not led to anything.
I have download Windows Imaging Component but when I try to install it I get an error because the last version is just installed on my Windows XP.
I have also copy gdipluss.dll library on my application path, but also this not work.
I don't have an error, only a TIFF file empty...
Other ideas about it?
Offline
Check the gdiplus.dll which is loaded.
There are several versions around.
During intialization of the object, it may use the one supplied with Office.
TIFF is definitively not the best format when using the GDI+ library.
Offline
I will check gdiplus.dll and the I will report the result.
I need to create a TIFF from a BMP with 200dpi and evCompressionCCITT4, do you know other delphi class or small library for this?
Offline
I've been trying to automate saving to 300dpi Tif's for ages and noticed AB's code snippet of 02/08/12 -
Bmp := Gdip.DrawAntiAliased(MF);
Image1.Picture.Assign(Bmp);
SynGDIPlus.SaveAs(Bmp, 'c:\test.tif', gptTIF, 80, 0, 200); // force 200 DPI
Bmp.Free;
Just that I get 'Too many actual parameters'. Knocking off the 200 creates a Tif OK, but the very parameter I need seems to be unavailable.
Any ideas gratefully etc.
Offline
I downloaded SynGdiPlus.zip on 12/9/12 via http://synopse.info/fossil/wiki?name=Downloads. The included SynGdiPlus.pas is dated 17/9/11. As it doesn't run 'stand alone', I downloaded SynPdf.zip to get SQLPages.zip, etc., dated 25/9/11. I notice that mORMOT.7z has newer versions via the same downloads page. I've updated and am now bowled over at being able to convince Photoshop that it really is a 300dpi Tif!
BTW. What are the minimum code requirements for SynGdiPlus? I may well need mORMOT one day, but for now I need SynGdi+. Is including just SQLPages enough?)
The antialiasing, resizing and file format conversion work a treat, by the way. All I need now is LZ compression and conversion to CYMK, but maybe that's asking too much? Could I, if this is the line, ask for amendments to -
SynGDIPlus.SaveAs(Bmp, 'c:\test.tif', gptTIF, 80, 0, 300);
Many thanks for your great work.
Offline
The version included in mORMot is the latest stable version.
The latest available is from http://synopse.info/fossil
The unit is just a wrapper around GDI+ and I suspect GDI+ does not support LZ compression nor CYMK.
So we won't be able to help you much here, sorry...
Offline
Thanks AB,
I ploughed through the mORMot documentation, and found -
'Save the picture into any GIF/PNG/JPG/TIFF format - CompressionQuality is used for gptJPG format saving and is expected to be from 0 to 100; for gptTIF format, use ord(TGDIPPEncoderValue) to define the parameter; by default, will use ord(evCompressionLZW) to save the TIFF picture with LZW - for gptTIF, only valid values are ord(evCompressionLZW), ord(evCompressionCCITT3), ord(evCompressionCCITT4), ord(evCompressionRle) and ord(evCompressionNone) function ToBitmap: TBitmap;'
So I tried -
SynGDIPlus.SaveAs(Bmp, 'c:\test.tif', gptTIF, ord(evCompressionLZW), 0, 300);
which now works and so does ord(evCompressionNone) and would presumably with the other compression settings.
I also noticed the line - 'Sub class to handle .TIF file extension - GDI + seems not able to load all Tiff file formats' which maybe a warning, but there is also -
GDI+ available filling modes TGDIPPEncoderValue = ( evColorTypeCMYK, evColorTypeYCCK, evCompressionLZW, evCompressionCCITT3, evCompressionCCITT4, evCompressionRle, evCompressionNone, evScanMethodInterlaced, evScanMethodNonInterlaced, evVersionGif87, evVersionGif89, evRenderProgressive, evRenderNonProgressive, evTransformRotate90, evTransformRotate180, evTransformRotate270, evTransformFlipHorizontal, evTransformFlipVertical, evMultiFrame, evLastFrame, evFlush, evFrameDimensionTime, evFrameDimensionResolution, evFrameDimensionPage );
I don't understand how I could try this. What would be the Delphi code be that implemented Color, Compression and Dpi? It appears only three parameters are allowed. I tried -
SynGDIPlus.SaveAs(Bmp, 'c:\test.tif', gptTIF, ord(evCompressionLZW), ord(evColorTypeCMYK), 300);
and then
SynGDIPlus.SaveAs(Bmp, 'c:\test.tif', gptTIF, ord(evColorTypeCMYK), 0, 300);
both of which ran OK, but don't do anything to the colour, which remains stubbonly at RGB. Interestingly, there's no evColorTypeRGB mentioned.
Any help appreciated.
Offline
Pages: 1