c# - Need SlimDX to display images quickly -


i need display images (about 60 fps). picturebox/panel doesn't job @ higher resolutions, turning slimdx, hope right move.

as slimdx uses directx, , directx uses gpu, should able quickly. understanding, gpu works images lot faster cpu.

i doing this:

messagepump.run(form, () => {     device.beginscene();     sprite.begin(slimdx.direct3d9.spriteflags.none);     tx = slimdx.direct3d9.texture.fromstream(device, (new memorystream(reader.readbytes(reader.readint32()))), slimdx.direct3d9.usage.none, slimdx.direct3d9.pool.managed);     sprite.draw(tx, color.transparent);      sprite.end();     device.endscene();     device.present(); }); 

and initializing everything:

var form = new renderform("test"); form.width = 1280; form.height = 720; slimdx.direct3d9.presentparameters presentparams = new slimdx.direct3d9.presentparameters {  backbufferwidth = form.width,  backbufferheight = form.height,  devicewindowhandle = form.handle,  presentflags = slimdx.direct3d9.presentflags.none,  backbuffercount = 0,  presentationinterval = slimdx.direct3d9.presentinterval.immediate,  swapeffect = slimdx.direct3d9.swapeffect.discard,  backbufferformat = slimdx.direct3d9.format.a8r8g8b8,  windowed = true, };  device = new slimdx.direct3d9.device(new slimdx.direct3d9.direct3d(), 0, slimdx.direct3d9.devicetype.hardware, form.handle, slimdx.direct3d9.createflags.hardwarevertexprocessing, presentparams); device.viewport = new slimdx.direct3d9.viewport(0, 0, form.width, form.height);     slimdx.direct3d9.sprite sprite;     slimdx.direct3d9.texture tx;     sprite = new slimdx.direct3d9.sprite(device);     tx = new slimdx.direct3d9.texture(device, form.width, form.height, 0, slimdx.direct3d9.usage.none, slimdx.direct3d9.format.x8r8g8b8, slimdx.direct3d9.pool.managed); 

there 2 problems this:

  1. it's extremely slow; picturebox faster
  2. it shows image incorrectly (it's zoomed in)

enter image description here

you need cache textures, making them every frame slow. e.g.

public class cacheobjects { static list cachescbrushes = new list();

public static solidcolorbrush getcolorbrush(color4 color, direct2d.rendertarget rendertgt) {      // error: not supported in c#: onerrorstatement      solidcolorbrush returnbrush = null;     bool found = false;     foreach (void br_loopvariable in cachescbrushes) {         br = br_loopvariable;         if (br.color.red == color.red) {             if (br.color.green == color.green) {                 if (br.color.blue == color.blue) {                     if (br.color.alpha == color.alpha) {                         found = true;                         returnbrush = br;                         exit for;                     }                 }             }         }     }     if (!found) {         returnbrush = new solidcolorbrush(rendertgt, color);         cachescbrushes.add(returnbrush);     }     return returnbrush; }   public static void clearcache() {     foreach (void brush_loopvariable in cachescbrushes) {         brush = brush_loopvariable;         brush.dispose();     } } 

}

if impossible, [in seperate thread], load next 5 textures...rendering fast, object creation slow.

public void loadtexture () { //load next 5 here } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -