Loading/Creating an image into SharpDX in a .NET program -


i'm trying use sharpdx create simple maze-like 2d program using directx.

to end want create bitmaps can render on-screen walls, hallways, outside of maze, etc.

however, can't seem figure out how either load existing image file bitmap class in sharpdx library, or how create new such bitmap class scratch.

since classes said mapped directly directx types, guess means need learn more directx, hoping there simple example somewhere show me need do.

if have construct new bitmap scratch , draw it, can that, it's not difficult getting pixels need right, can't seem figure out part.

does have experience sharpdx library , can give me pointers?

you should ask directly question "issue" tab on sharpdx project, able give quick response there (you lucky i'm checking usage net ;) ). if asking officially, make improvement library , keep record of request in issue database.

concerning particular issue, it's not clear kind of directx api using. assume using direct2d?

if yes, there no api load directly sharpdx.direct2d1.bitmap file (i add method api). have uploaded bitmap sample performing this.

/// <summary> /// loads direct2d bitmap file using system.drawing.image.fromfile(...) /// </summary> /// <param name="rendertarget">the render target.</param> /// <param name="file">the file.</param> /// <returns>a d2d1 bitmap</returns> public static bitmap loadfromfile(rendertarget rendertarget, string file) {     // loads file using system.drawing.image     using (var bitmap = (system.drawing.bitmap)system.drawing.image.fromfile(file))     {         var sourcearea = new system.drawing.rectangle(0, 0, bitmap.width, bitmap.height);         var bitmapproperties = new bitmapproperties(new pixelformat(format.r8g8b8a8_unorm, alphamode.premultiplied));         var size = new system.drawing.size(bitmap.width, bitmap.height);          // transform pixels bgra rgba         int stride = bitmap.width * sizeof(int);         using (var tempstream = new datastream(bitmap.height * stride, true, true))         {             // lock system.drawing.bitmap             var bitmapdata = bitmap.lockbits(sourcearea, imagelockmode.readonly, system.drawing.imaging.pixelformat.format32bpppargb);              // convert pixels              (int y = 0; y < bitmap.height; y++)             {                 int offset = bitmapdata.stride*y;                 (int x = 0; x < bitmap.width; x++)                 {                     // not optimized                      byte b = marshal.readbyte(bitmapdata.scan0, offset++);                     byte g = marshal.readbyte(bitmapdata.scan0, offset++);                     byte r = marshal.readbyte(bitmapdata.scan0, offset++);                     byte = marshal.readbyte(bitmapdata.scan0, offset++);                     int rgba = r | (g << 8) | (b << 16) | (a << 24);                     tempstream.write(rgba);                 }              }             bitmap.unlockbits(bitmapdata);             tempstream.position = 0;              return new bitmap(rendertarget, size, tempstream, stride, bitmapproperties);         }     } } 

as said, sharpdx giving access raw-low-level directx api (unlike example xna giving higher level api), need understand how program raw directx in order use sharpdx.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -