wpf - How to use PixelFormats.IndexedX with RenderTargetBitmap? -


i looking render drawingvisual (visual in example) bitmap using rendertargetbitmap view set bitmap background canvas below:

var bmp = new rendertargetbitmap(2000, 50, 120, 96, pixelformats.indexed2); bmp.render(visual); var brush = new imagebrush(bmp) { stretch = stretch.fill }; canvas.background = brush; 

when using pixelformats.default last argument rendertargetbitmap, image renders expected. however, when choose pixelformats.indexed2 (or of pixelformats.indexedx), code seems exit method without exception, bmp.render line never called , hence image not displayed on canvas.

how use indexedx pixel formats rendertargetbitmap? or there other ways reduce memory footprint of image? uses 3 colors, using palette rather 32bit rgb seemed way go.

you can't. rendertargetbitmap supports pbgra32 pixel format. that's because wpf's rendering system works entirely in 32 bits per pixel. that's format in generates images, , it's format in prefers images in if want render them. (if provide bitmap in other format, it'll need convert 32 bit per pixel representation first.)

what planning bitmap? if want render in wpf application, it'll need converted 32bpp format first in case, risk using more memory if attempt hold internally in other format. (you'll have supposedly memory-efficient representation and version wpf's able work with.) not mention cpu time spent converting between chosen format , format wpf can work with.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -