c# - Will using DirectX or OpenGL speed up 2D Rendering on a windows form? -


i'm working on structured light project need project barcodes @ 60fps. these codes built bitmap images 1920x1200. when using gdi in c# i'm getting around 19fps on pretty beastly computer. i'm looking sharpdx , before investing lot of time wondering if rendering images screen via directx or opengl faster?

sample code:

// gets reference current bufferedgraphicscontext currentcontext = bufferedgraphicsmanager.current; list<image> imagesgraycode = new list<image>();  bitmap bitmap = (bitmap)image.fromfile("f:/lab/hardware triggering demo/lib/patterns_11bit_rll.tiff"); int count = bitmap.getframecount(framedimension.page);  (int idx = 0; idx < count; idx++) {     // save each frame bytestream     bitmap.selectactiveframe(framedimension.page, idx);     memorystream bytestream = new memorystream();     bitmap.save(bytestream, imageformat.tiff);      // , create new image     imagesgraycode.add(image.fromstream(bytestream));     //this.progressbar1.value = idx; }   thread.sleep(1000); stopwatch = stopwatch.startnew(); int acq_wait_time = 10;  (int = 0; < 10; i++) {     foreach (image img in imagesgraycode)     {         mybuffer.graphics.drawimage(img, this.displayrectangle);         // renders contents of buffer drawing surface associated buffer.         mybuffer.render();         // renders contents of buffer specified drawing surface.         mybuffer.render(this.creategraphics());          //system.threading.thread.sleep(acq_wait_time);         stopwatch.reset();         stopwatch.start();         while (stopwatch.elapsedmilliseconds < acq_wait_time)         { }         fps++;         application.doevents();     } } 

updated code:

// gets reference current bufferedgraphicscontext currentcontext = bufferedgraphicsmanager.current; list<image> imagesgraycode = new list<image>(); list<bufferedgraphics> imagebuffers = new list<bufferedgraphics>(); bitmap bitmap = (bitmap)image.fromfile("f:/lab/hardware triggering demo/lib/patterns_11bit_rll.tiff"); int count = bitmap.getframecount(framedimension.page);  (int idx = 0; idx < count; idx++) {     // save each frame bytestream     bitmap.selectactiveframe(framedimension.page, idx);     memorystream bytestream = new memorystream();     bitmap.save(bytestream, imageformat.tiff);      // , create new image     imagesgraycode.add(image.fromstream(bytestream));     //this.progressbar1.value = idx; }  //create buffer each image in memory (int = 0; < imagesgraycode.count(); i++) {     imagebuffers.add(currentcontext.allocate(this.creategraphics(),this.displayrectangle));     imagebuffers.elementat(i).graphics.drawimage(imagesgraycode.elementat(i), this.displayrectangle);     imagebuffers.elementat(i).render(); }  thread.sleep(1000); stopwatch = stopwatch.startnew(); int acq_wait_time = 10;  (int x = 0; x < 10; x++) {     //display image buffers sequentially     (int = 0; < imagesgraycode.count(); i++)     {         // renders contents of buffer specified drawing surface.         imagebuffers.elementat(i).render(this.creategraphics());          //system.threading.thread.sleep(acq_wait_time);         stopwatch.reset();         stopwatch.start();         while (stopwatch.elapsedmilliseconds < acq_wait_time)         { }         fps++;         application.doevents();     } } 

you're drawing > rendering > drawing > rendering > drawing > rendering etc. can drawing ahead of time need render on each frame. use more of whatever mybuffer is; 1 each image.

profiler tools awesome these problems. i'm guessing based on partial code , experience, profiler can tell exactly how long each function takes complete.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -