public static extern ReturnCode DsmWinNew( [In, Out] TWIdentity origin, [In, Out] TWIdentity destination, DataGroups dg, DataArgumentType dat, Message msg, [In, Out] TWImageInfo data);
private static Bitmap GetBitmapFromMemXFer(byte[] memoryData, TWImageInfo imageInfo) { var bytesPerPixel = memoryData.Length / (imageInfo.ImageWidth * imageInfo.ImageLength); var pixelFormat = bytesPerPixel == 0 ? PixelFormat.Format1bppIndexed : PixelFormat.Format24bppRgb; var imageWidth = imageInfo.ImageWidth; var imageHeight = imageInfo.ImageLength; var bitmap = new Bitmap(imageWidth, imageHeight, pixelFormat); var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat); try { var source = memoryData; switch (bytesPerPixel) { case 1: { // No 8-bit greyscale format, so we have to transform into 24-bit var rowWidth = data.Stride; var originalRowWidth = source.Length / imageHeight; var source2 = new byte[rowWidth * imageHeight]; for (var row = 0; row < imageHeight; row++) { for (var col = 0; col < imageWidth; col++) { source2[row * rowWidth + col * 3] = source[row * originalRowWidth + col]; source2[row * rowWidth + col * 3 + 1] = source[row * originalRowWidth + col]; source2[row * rowWidth + col * 3 + 2] = source[row * originalRowWidth + col]; } } source = source2; break; } case 3: { // Colors are provided as BGR, they need to be swapped to RGB var rowWidth = data.Stride; for (var row = 0; row < imageHeight; row++) { for (var col = 0; col < imageWidth; col++) { (source[row * rowWidth + col * 3], source[row * rowWidth + col * 3 + 2]) = (source[row * rowWidth + col * 3 + 2], source[row * rowWidth + col * 3]); } } break; } } Marshal.Copy(source, 0, data.Scan0, source.Length); } finally { bitmap.UnlockBits(data); } return(bitmap); }
public static ReturnCode DsmEntry( TWIdentity origin, TWIdentity destination, Message msg, TWImageInfo data) { if (PlatformInfo.Current.IsWindows) { if (PlatformInfo.Current.UseNewWinDSM) { return(NativeMethods.DsmWinNew(origin, destination, DataGroups.Image, DataArgumentType.ImageInfo, msg, data)); } else { return(NativeMethods.DsmWinOld(origin, destination, DataGroups.Image, DataArgumentType.ImageInfo, msg, data)); } } else if (PlatformInfo.Current.IsLinux) { return(NativeMethods.DsmLinux(origin, destination, DataGroups.Image, DataArgumentType.ImageInfo, msg, data)); } throw new PlatformNotSupportedException(); }
private static Bitmap GetBitmapFromMemXFer(byte[] memoryData, TWImageInfo imageInfo) { int bytesPerPixel = memoryData.Length / (imageInfo.ImageWidth * imageInfo.ImageLength); PixelFormat pixelFormat = bytesPerPixel == 0 ? PixelFormat.Format1bppIndexed : PixelFormat.Format24bppRgb; int imageWidth = imageInfo.ImageWidth; int imageHeight = imageInfo.ImageLength; var bitmap = new Bitmap(imageWidth, imageHeight, pixelFormat); var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat); try { byte[] source = memoryData; if (bytesPerPixel == 1) { // No 8-bit greyscale format, so we have to transform into 24-bit int rowWidth = data.Stride; int originalRowWidth = source.Length / imageHeight; byte[] source2 = new byte[rowWidth * imageHeight]; for (int row = 0; row < imageHeight; row++) { for (int col = 0; col < imageWidth; col++) { source2[row * rowWidth + col * 3] = source[row * originalRowWidth + col]; source2[row * rowWidth + col * 3 + 1] = source[row * originalRowWidth + col]; source2[row * rowWidth + col * 3 + 2] = source[row * originalRowWidth + col]; } } source = source2; } Marshal.Copy(source, 0, data.Scan0, source.Length); } finally { bitmap.UnlockBits(data); } return(bitmap); }
public ReturnCode Get(out TWImageInfo info) { Session.VerifyState(6, 7, DataGroups.Image, DataArgumentType.ImageInfo, Message.Get); info = new TWImageInfo(); return(Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, Message.Get, info)); }