c# - FileLabels are not visible -
i try capture desktop screenshot using sharpdx. application able capture screenshot without labels in windows explorer. tryed 2 solutions without change. tried find in documentation information, without change.
here mi code:
public void scr() { uint numadapter = 0; // # of graphics card adapter uint numoutput = 0; // # of output device (i.e. monitor) // create device , factory var device = new sharpdx.direct3d11.device(sharpdx.direct3d.drivertype.hardware); var factory = new factory1(); // creating cpu-accessible texture resource var texdes = new sharpdx.direct3d11.texture2ddescription { cpuaccessflags = sharpdx.direct3d11.cpuaccessflags.read, bindflags = sharpdx.direct3d11.bindflags.none, format = format.b8g8r8a8_unorm, height = factory.adapters1[numadapter].outputs[numoutput].description.desktopbounds.height, width = factory.adapters1[numadapter].outputs[numoutput].description.desktopbounds.width, optionflags = sharpdx.direct3d11.resourceoptionflags.none, miplevels = 1, arraysize = 1 }; texdes.sampledescription.count = 1; texdes.sampledescription.quality = 0; texdes.usage = sharpdx.direct3d11.resourceusage.staging; var screentexture = new sharpdx.direct3d11.texture2d(device, texdes); // duplicate output stuff var output = new output1(factory.adapters1[numadapter].outputs[numoutput].nativepointer); var duplicatedoutput = output.duplicateoutput(device); sharpdx.dxgi.resource screenresource = null; sharpdx.datastream datastream; surface screensurface; var = 0; var miliseconds = 2500000; while (true) { i++; // try duplicated frame within given time try { sharpdx.dxgi.outputduplicateframeinformation duplicateframeinformation; duplicatedoutput.acquirenextframe(miliseconds, out duplicateframeinformation, out screenresource); } catch (sharpdx.sharpdxexception e) { if (e.resultcode.code == sharpdx.dxgi.resultcode.waittimeout.result.code) { // has not been successful capture // @randy // keep retrying continue; } else { throw e; } } device.immediatecontext.copyresource(screenresource.queryinterface<sharpdx.direct3d11.resource>(), screentexture); screensurface = screentexture.queryinterface<surface>(); // screensurface.map(sharpdx.dxgi.mapflags.read, out datastream); int width = output.description.desktopbounds.width; int height = output.description.desktopbounds.height; var boundsrect = new system.drawing.rectangle(0, 0, width, height); var mapsource = device.immediatecontext.mapsubresource(screentexture, 0, mapmode.read, sharpdx.direct3d11.mapflags.none); using (var bitmap = new system.drawing.bitmap(width, height, pixelformat.format32bppargb)) { // copy pixels screen capture texture gdi bitmap var bitmapdata = bitmap.lockbits(boundsrect, imagelockmode.writeonly, bitmap.pixelformat); var sourceptr = mapsource.datapointer; var destinationptr = bitmapdata.scan0; (int y = 0; y < height; y++) { // copy single line utilities.copymemory(destinationptr, sourceptr, width * 4); // advance pointers sourceptr = intptr.add(sourceptr, mapsource.rowpitch); destinationptr = intptr.add(destinationptr, bitmapdata.stride); } // release source , dest locks bitmap.unlockbits(bitmapdata); device.immediatecontext.unmapsubresource(screentexture, 0); bitmap.save(string.format(@"d:\scr\{0}.png", i)); } // var image = frombyte(tobyte(datastream)); //var image = getimagefromdxstream(1920, 1200, datastream); //image.save(string.format(@"d:\scr\{0}.png", i)); // datastream.close(); //screensurface.unmap(); screensurface.dispose(); screenresource.dispose(); duplicatedoutput.releaseframe(); } }
after few hours of research , googling found working solution:
from:
pixelformat.format32bppargb
to:
pixelformat.format32bpprgb
Comments
Post a Comment