c# - Loading WMF is failing, yet converting a PNG to WMF succeeds but loss of background -


working richtextbox, gave on trying make png have transparent background, , don't code microsoft in order convert image object wmf, must write 2 files, read in memory stream, cracked open illustrator, , converted 1 emote wmf allegedly in format rtf requires.

enclosed images in formats trying :

the trouble having right now, following code, results in no image being displayed:

public string getimage( string file, int width, int height ) {     float dpix;     float dpiy;     string rtfimage;      using ( graphics g= this.creategraphics() ) {         dpix=g.dpix;         dpiy=g.dpiy;     }      using ( memorystream ms=new memorystream() ) {         byte[] data=file.readallbytes( file );         ms.write( data, 0, data.length );         rtfimage=@"{\pict\wmetafile8\picw"+(int)( ( (float)width/dpix )*2540 )                             +@"\pich"+(int)( ( (float)height/dpiy )*2540 )                             +@"\picwgoal"+(int)( ( (float)width/dpix )*1440 )                             +@"\pichgoal"+(int)( ( (float)height/dpiy )*1440 )                             +" "                     +bitconverter.tostring( ms.toarray() ).replace( "-", "" ).tolower()                             +"}";     }     return rtfimage; } 

while following code works (but non-wmf files) :

public static string getembedimagestring( image image ) {     metafile metafile=null;     float dpix;     float dpiy;      using ( graphics g=graphics.fromimage( image ) ) {         intptr hdc=g.gethdc();         metafile=new metafile( hdc, emftype.emfonly );         g.releasehdc( hdc );     }      using ( graphics g=graphics.fromimage( metafile ) ) {         g.compositingmode = compositingmode.sourceover;         g.compositingquality = compositingquality.highquality;         g.drawimage( image, 0, 0 );         g.clear( color.white );         dpix=g.dpix;         dpiy=g.dpiy;     }      intptr _hemf=metafile.gethenhmetafile();     uint _buffersize=gdipemftowmfbits( _hemf, 0, null, mm_anisotropic,     emftowmfbitsflags.emftowmfbitsflagsdefault );     byte[] _buffer=new byte[_buffersize];     gdipemftowmfbits( _hemf, _buffersize, _buffer, mm_anisotropic,                                 emftowmfbitsflags.emftowmfbitsflagsdefault );     intptr hmf=setmetafilebitsex( _buffersize, _buffer );     string tempfile=path.gettempfilename();     copymetafile( hmf, tempfile );     deletemetafile( hmf );     deleteenhmetafile( _hemf );      var stream=new memorystream();     byte[] data=file.readallbytes( tempfile );     //file.delete (tempfile);     int count=data.length;     stream.write( data, 0, count );      string proto=@"{\pict\wmetafile8\picw"+(int)( ( (float)image.width/dpix )*2540 )                       +@"\pich"+(int)( ( (float)image.height/dpiy )*2540 )                       +@"\picwgoal"+(int)( ( (float)image.width/dpix )*1440 )                       +@"\pichgoal"+(int)( ( (float)image.height/dpiy )*1440 )                       +" "                       +bitconverter.tostring( stream.toarray() ).replace( "-", "" )                       +"}";      return proto; } 

they both return appropriate string format embedding wmf file in richtextbox control follows

{\pict\wmetafile8\picw[width]\pich[height]\picwgoal[width (twips)]\pichgoal[height (twips)] [hex byte array of file]} 

i looking way appropriate string value that works winforms richtextbox component.

i feel specific question relating specific problem , have given more enough code , details in order duplicate problem. ideally, if have experienced issue , have found work-around not involve messing users clipboard (i aware of copy/paste method not slower, interferes users clipboard. aware of work-around clipboard issue stores old clipboard data in memory , sets back, not without flaw in cases data can not set back).

i not looking easy road, although think 2015, richtextbox control in winforms have evolved during 10 years in .net.

i realize, other option use wpf opens pandora's box other problems (as benefits) of using wpf. prefer stick language overall more mature.

what need with, specific: posted thread referencing else regarding matter, closed under claim not specific. same question, many many more details, in hopes see how specific is.

c# > winforms > richtextbox > replace string image requires format specific , in wmf specific byte string specific formatting tags string > problem getting images load in format required while maintaining transparency or @ least using definable color if can't keep transparency on vector.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -