c# - How can I get BitmapSource from Image -


i need system.windows.media.imaging.bitmapsource system.drawing.image.

i need make softwarebitmap image. use filestream create bitmapsource.

private static unsafe softwarebitmap getsoftwarebitmap(string filename) {   filestream file = file.open(filename, filemode.open);   bitmapsource bitmapsource = bitmapdecoder.create(file,    bitmapcreateoptions.none, bitmapcacheoption.onload).frames[0];    writeablebitmap writeablebitmap = new writeablebitmap(bitmapsource);   writeablebitmap.lock();   byte[] pixels = new byte[writeablebitmap.pixelwidth *      writeablebitmap.pixelheight * 4];    byte* pbuf = (byte*)writeablebitmap.backbuffer;   (int = 0; < pixels.length; i++)   {     pixels[i] = *pbuf++;   }   var ibuffer = pixels.asbuffer();   writeablebitmap.unlock();    softwarebitmap softwarebitmap = new      softwarebitmap(bitmappixelformat.bgra8, writeablebitmap.pixelwidth,     writeablebitmap.pixelheight);    softwarebitmap.copyfrombuffer(ibuffer);   return softwarebitmap; } 

i need function take system.drawing.image instead of path(filename) , instead.

private static unsafe softwarebitmap getsoftwarebitmap(image image) {   bitmapsource bitmapsource = fromimagesomehow(image);    // rest stays same.   ...    return softwarebitmap; } 


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -