c# - Sharpdx load bitmap fom file Windows 8 apps -
i've found example in sharpdx "bitmapapp" samples:
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 size2(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); } } }
but problem works wpf or deskop application.
i want build windows store app system.drawing doesn't exist longer. has been replaced windows.graphics.imaging (replacement of system.drawing in developing windows 8 apps)
i'm beginner , dont know how make function works windows 8.
this function perfect me because want load .png file , want transform it. tried , works in bitmappapp samples.
rendertarget2d.transform = matrix.transformation2d(center, 0f, new vector2(500 / _bitmap.size.width, 900 / _bitmap.size.height), center, 0f,vector2.zero); rendertarget2d.drawbitmap(_bitmap, 1.0f, bitmapinterpolationmode.linear);
Comments
Post a Comment