>SaveRTFImage(oRTF.TextRTF, 1, "MyImage.png") > >**************************************************** >FUNCTION SaveRTFImage(tcRTF, tnImage, tcFileName) >**************************************************** >** Extracts an image from RTF text and saves it to a file >** Parameters: >** tcRTF : The RTF text that contains the image >** tnImage : The image number within the RTF (default = 1) >** tcFileName : The name of the file to be created >** >** Notes: >** The GDIPlusX Library is required. It can be downloaded from: >** www.codeplex.com/vfpx >** >** Also, the file is saved as a PNG. You can change the image format >** on the save method for other formats >**************************************************** > LOCAL lnStart, lnLen, lcPict > LOCAL lcTags, lcData, lqData > LOCAL lnWidth, lnHeight > LOCAL loStream, loImg, loBmp, loGfx > > tnImage = EVL(tnImage,1) > tcFileName = EVL(tcFileName,"MyImage.png") > tcFileName = FORCEEXT(tcFileName,"png") > > lcPict = STREXTRACT(tcRTF, "{\pict", "}", tnImage) > IF EMPTY(lcPict) > RETURN .F. > ENDIF > > lcTags = STREXTRACT(lcPict, "", CHR(13)) > ** Image data as Hex > lcData = STREXTRACT(lcPict, CHR(13), "") > ** Convert to binary > lqData = STRCONV(lcData,16) > > lnWidth = VAL(STREXTRACT(lcTags, [\picwgoal], [\], 1, 2)) > lnWidth = BITAND(lnWidth, 0xFFFF)/15 > lnHeight = VAL(STREXTRACT(lcTags, [\pichgoal], [\], 1, 2)) > lnHeight = BITAND(lnHeight, 0xFFFF)/15 > > IF NOT VARTYPE(_SCREEN.System) = "O" > DO (LOCFILE("system.app","app","Where is the GDIPlusX Library?")) > ENDIF > > loStream = _SCREEN.System.IO.MemoryStream.New(lqData) > > WITH _SCREEN.System.Drawing > loImg = .Image.FromStream(loStream) > > loBmp = .Bitmap.New(lnWidth, lnHeight, 0, ; > .Imaging.PixelFormat.Format24bppRGB) > loGfx = .Graphics.FromImage(loBmp) > loGfx.Clear(.Color.White) > loGFX.SmoothingMode = .Drawing2D.SmoothingMode.HighQuality > loGFX.InterpolationMode = .Drawing2D.InterpolationMode.HighQualityBicubic > loGfx.DrawImage(loImg, 0, 0, lnWidth, lnHeight) > loBmp.Save(tcFileName, .Imaging.ImageFormat.Png) > > ENDWITH > loGfx = NULL > loBmp = NULL > loImg = NULL > loStream = NULL >ENDFUNC >