limelect 53 Posted August 10 (edited) I would like to make any picture format into SVG. I have ImgView321: TImgView32; as my bitmap I got to this point from a demo, and it works nicely procedure CreateSVG(const AOutputFileName: string; const AWidth, AHeight: Integer; const ADrawProc: TSkDrawProc); var LStream: TStream; LCanvas: ISkCanvas; begin LStream := TFileStream.Create(AOutputFileName, fmCreate); try LCanvas := TSkSVGCanvas.Make(RectF(0, 0, AWidth, AHeight), LStream, [TSkSVGCanvasFlag.ConvertTextToPaths]); ADrawProc(LCanvas);//, RectF(0, 0, AWidth, AHeight)); LCanvas := nil; finally LStream.Free; end; end; CreateSVG('G:\7\TestPict\output.svg', 256, 256, TSkDrawProc( procedure (const ACanvas: ISkCanvas; const ADest: TRectF) var LFont: ISkFont; LPaint: ISkPaint; begin LFont := TSkFont.Create(TSkTypeface.MakeFromFile('G:\7\TestPicts\2.tiff'), 23); LPaint := TSkPaint.Create; LPaint.Shader := TSkShader.MakeGradientLinear(PointF(0, 0), PointF(256, 145), $FFFF5F5F, $FF5B8DFE, TSkTileMode.Clamp); instead of this >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ACanvas.DrawSimpleText('"Each dream that you', 2, 25, LFont, LPaint); ACanvas.DrawSimpleText('leave behind is a part', 2, 55, LFont, LPaint); ACanvas.DrawSimpleText('of your future that will', 2, 85, LFont, LPaint); ACanvas.DrawSimpleText('no longer exist."', 2, 115, LFont, LPaint); ACanvas.DrawImage(); I like to make this <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Image here is ISkImage, but I have ImgView321. I tried ISkImage(ImgView321) or bitmap LFont := TSkFont.Create(TSkTypeface.MakeFromFile('G:\7\TestPicts\2.tiff'), 28); LPaint.Shader := nil; LPaint.Color := $FF5B8DFE; ACanvas.DrawSimpleText('(Steve Jobs)', 2, 150, LFont, LPaint);<< also delete this end)); end; So any suggestions on how to go about my need any picture to SVG And no DLL, plz PS<<<<<<<<<<<<<<<<<<<<< I tried and it works, but some pictures are bad because it is PNG to SVG procedure TForm1.Button3Click(Sender: TObject); const SVG_START_TAG = '<svg width="%d" height="%d" xmlns="http://www.w3.org/2000/svg">'; SVG_RECT_TAG = ' <rect x="%d" y="%d" width="%d" height="%d" fill="rgb(%d,%d,%d)" fill-opacity="%s" />'; SVG_END_TAG = '</svg>'; var FSVGStrings: TStringList; b: tbitmap; MyPng: TPngImage; LOptions: TPng2SvgOptions; LRects: TArray<TColorRect>; LFormatSettings: TFormatSettings; LRect: TColorRect; begin Include(LOptions, psSaveSvg); b := tbitmap.Create; b.Assign(ImgView321.Bitmap);<< some are jpg FOptions := LOptions; // loses transparency MyPng := TPngImage.Create; try // MyPng.LoadFromFile(FileSave); //Assign(b); MyPng.Assign(b); mypng.SaveToFile(JvDirectoryEdit2.Text + '\' + '55.png'); <<< hear png is ok but output of gpg bad FSVGStrings := TStringList.Create; // Convert; with FSVGStrings do begin Clear; Add(Format(SVG_START_TAG, [MyPng.Width, MyPng.Height])); LFormatSettings := TFormatSettings.Create; LFormatSettings.DecimalSeparator := '.'; LRects := MergePixels(MyPng); for LRect in LRects do Add(Format(SVG_RECT_TAG, [LRect.X, LRect.Y, LRect.Width, LRect.Height, LRect.RValue, LRect.GValue, LRect.BValue, FormatFloat('0.######', LRect.Alpha / 255, LFormatSettings)])); Add(SVG_END_TAG); FSVGStrings.SaveToFile(JvDirectoryEdit2.Text + '\' + Edit1.Text + '.svg'); // Form1.Memo1.Lines.Add( FSVGStrings.Text); end; finally MyPng.Free; FSVGStrings.Free; // LFormatSettings.Free; b.Free; end; end; Edited August 10 by limelect Share this post Link to post
timfrost 81 Posted August 10 Have you looked at POtrace to go from BMP to SVG (if that is your objective; it is not really clear to me other than from your very first line above)? It does work for me to create adequate scalable versions of bitmap images, but it looks as if its license means that your user has to install their own freeware copy of POtrace which your app can then just execute. See https://sourceforge.net/projects/potrace Share this post Link to post
limelect 53 Posted August 10 @timfrost We are talking Delphi, am I to convert C? Share this post Link to post
timfrost 81 Posted August 10 Sorry, I missed your 'no DLL' request above. POtrace is an EXE, so I guess that is even more unwelcome. But I run it from Delphi to do the task I thought you were looking for, to convert a raster graphics file to vector SVG. Its 'else', not Skia, as in your topic title. Share this post Link to post
limelect 53 Posted August 11 (edited) @timfrost Some components use DLL. As for Skia, this is one way to go. I have those above solutions, but they are not perfect for all graphics. This is why I look for help Edited August 11 by limelect Share this post Link to post
limelect 53 Posted August 11 (edited) Let me elaborate I use the unit Png2Svg.Classes; from https://github.com/TextEditorPro/Png2Svg With PNG, it works great Obviously, with another format (jpg), for example, it does not altogh I load it into PNG The SVG result Edited August 11 by limelect Share this post Link to post