c# - The buffer allocated is insufficient when encoding to Rgba16 UWP -


i encoding canvas control contains textblocks child using following code

the buffer allocated insufficient 

my code

using(inmemoryrandomaccessstream ras = new inmemoryrandomaccessstream()) {     var displayinformation = displayinformation.getforcurrentview();     var rendertargetbitmap = new rendertargetbitmap();     await rendertargetbitmap.renderasync(textify.canvascontrol);     var width = rendertargetbitmap.pixelwidth;     var height = rendertargetbitmap.pixelheight;     ibuffer textbuffer = await rendertargetbitmap.getpixelsasync();     byte[] pixels = textbuffer.toarray();      //encode text png     var encoder = await bitmapencoder.createasync(bitmapencoder.pngencoderid, ras);      encoder.setpixeldata(bitmappixelformat.rgba16,                          bitmapalphamode.premultiplied,                          (uint)width,                           (uint)height,                          displayinformation.logicaldpi,                          displayinformation.logicaldpi,                          pixels);      await encoder.flushasync(); ... 

i know it's byte[] pixels buffer no large enough want encode bitmappixelformat.rgba16. not encounter error when encoding bitmappixelformat.rgba8 or bitmappixelformat.bgra8

i tried calculating buffer using following produce empty white bitmap.

byte[] pixels = new byte[16 * width * height];  int index = 0; (int y = 0; y < height; ++y)     (int x = 0; x < width; ++x)     {         pixels[index++] = 255;  // b         pixels[index++] = 255;  // g         pixels[index++] = 255;  // r         pixels[index++] = 255;  //     } 

i want use bitmappixelformat.rgba16 because want improve image quality. how properly? thanks.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -