c# - Turn off antialiasing for black and white bitmap Rendered from canvas -


i have problem wpf's anti aliasing of text. in application user designs text or image fields printed using special printing device. using canvas host fields, either textblocks or images

the problem when convert canvas rendertargetbitmap, black , white formatconvertedbitmap, text , images end extremely fuzzy looking.

i have tried using "snaptodevicepixels = true" , "renderoptions.edgemode" = aliased on in application. know anti aliasing great screen, printing real disaster.

here example of code:

private bitmapsource getcanvasasbitmap(canvas cvs)   {       cvs.background = brushes.white;    renderoptions.setedgemode(cvs, edgemode.aliased);    cvs.snapstodevicepixels = true;     // render topcanvas visual tree rendertargetbitmap     size canvassize = new size(cvs.width, cvs.height);    cvs.measure(canvassize);    rect canvasrect = new rect(canvassize);    cvs.arrange(canvasrect);     rendertargetbitmap targetbitmap =     new rendertargetbitmap((int)cvs.actualwidth,      (int)cvs.actualheight,      96, 96,      pixelformats.default);     targetbitmap.render(cvs);      double scale = pixelscale / cvs.height;    scaletransform st = new scaletransform(scale, scale);     transformedbitmap tb = new transformedbitmap(targetbitmap, st);     return tb;   }      private static formatconvertedbitmap recolor(bitmapsource b)   {       bmpbitmapencoder encoder = new bmpbitmapencoder();    encoder.frames.add(bitmapframe.create(b));     using (filestream fs = new filestream("beforerecolor.bmp", filemode.create))    {     encoder.save(fs);         fs.flush();     fs.close();    }     formatconvertedbitmap fcb = new formatconvertedbitmap(b, pixelformats.indexed1, new bitmappalette(new list<color>() { colors.black, colors.white }), 0);     bmpbitmapencoder en = new bmpbitmapencoder();    en.frames.add(bitmapframe.create(fcb));     using (filestream fs = new filestream("afterrecolor.bmp", filemode.create))    {     en.save(fs);     fs.flush();     fs.close();    }     return fcb;   } 

how turn off antiailasing before creating rendertargetbitmap?

http://blogs.msdn.com/b/dwayneneed/archive/2008/06/20/implementing-a-custom-bitmapsource.aspx

apparently dither type hardcoded

formatconvertedbitmap

this class wraps standard wic pixel format converter (iwicimagingfactory::createformatconverter). component provides means of converting 1 pixel format another, handling dithering , halftoning indexed formats, palette translation , alpha thresholding. source, destinationformat, destinationpalette, , alphathreshold properties used initialize underlying component via iwicformatconverter::initialize. the dither type hard-coded wicbitmapdithertypeerrordiffusion. palette translation type hard-coded wicbitmappalettetypemediancut. isupportinitialize interface used snap values of properties when initialization complete. further changes properties ignored.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -