Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Microsoft Rich Textcontrol
Message
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01348848
Message ID:
01349019
Views:
20
Bo ...

You are my saver !!!
Cant thank you enouph..

;-)


>Pedro,
>
>Here is a function that may help you. You pass it the RTF text and an image number (defaults to 1) and it will extract the image and save it to the file name specified. NOTE: It will not be identical to the image that was originally added to the RTF, the RTF converts it to a WMF and we have to convert it back, so there will be some image loss.
>
>You will need to download the GDIPlusX Library from: www.codeplex.com/vfpx
>
>
>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
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform