How to make a get image by a NETObject
I don't know much of .net and it probably shows, but at least I got something to work albeit very,very slowly.
Your code (which I also turned into a bitmap on the clipboard using Mathematica's "Copy as Bitmap" menu item):
Needs["NETLink`"]
InstallNET[];
LoadNETType["System.Windows.Forms.Clipboard", StaticsVisible -> True];
img = GetImage[]
Using a few of .Net's Image methods to get pixel information:
res = Table[
{
img@GetPixel[r, c]@R,
img@GetPixel[r, c]@G,
img@GetPixel[r, c]@B,
img@GetPixel[r, c]@A
}, {c, 0, img@Height - 1}, {r, 0, img@Width - 1}];
Image[res, "Byte", ColorSpace -> "RGB"]
And after waiting perhaps a few minutes (I said it was slow) with the above mentioned image already loaded in the clipboard you get this:
Done
Needs["NETLink`"]; InstallNET[];
LoadNETType /@ {"System.Windows.Forms.Clipboard",
"System.Drawing.Rectangle", "System.Drawing.Imaging.ImageLockMode",
"System.Runtime.InteropServices.Marshal"};
img = Clipboard`GetImage[];
width = img[Width];
height = img[Height];
lock = img[
LockBits[Rectangle`FromLTRB[0, 0, width, height],
ImageLockMode`ReadWrite, img[PixelFormat][Format24bppRgb]]];
stride = Abs[lock[Stride]];
intPtr = lock[Scan0];
totalB = stride*height;
byte = NETNew["System.Byte[]", totalB];
Marshal`Copy[intPtr, byte, 0, totalB];
data = NETObjectToExpression[byte];
Marshal`Copy[byte, 0, intPtr, totalB];
img[UnlockBits[lock]];
img = Image[Map[Reverse/@Partition[#, 3] &,Partition[data, width*3,stride]],"Byte"]