public static ImageRgb toImgRgb(this Bitmap bmp) { ImageRgb img = new ImageRgb(); img.resize(bmp.Width, bmp.Height); try { unsafe { BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, img.width(), img.height()), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); byte[] rawData = new byte[bmpData.Stride * bmpData.Height]; Marshal.Copy(bmpData.Scan0, rawData, 0, rawData.Length); Marshal.Copy(rawData, 0, img.getRawImage(), rawData.Length); bmp.UnlockBits(bmpData); } } catch (Exception e) { Console.Out.WriteLine("Exception while accessing image: " + e); } return(img); }
public static Bitmap toBmp(this ImageRgb img) { int w = img.width(); int h = img.height(); Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb); try { unsafe { BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); byte[] rawData = new byte[bmpData.Stride * bmpData.Height]; Marshal.Copy(img.getRawImage(), rawData, 0, rawData.Length); Marshal.Copy(rawData, 0, bmpData.Scan0, rawData.Length); bmp.UnlockBits(bmpData); } } catch (Exception e) { Console.Out.WriteLine("Exception while accessing image: " + e); } return(bmp); }
// Use this for initialization void Start() { Debug.Log ("Initialising Network ... "); Network.init(); Debug.Log ("Initialising Port"); imagePort = new BufferedPortImageRgb(); Debug.Log ("Open Port"); imagePort.open (sourcePortName); Debug.Log ("Connect Port"); Network.connect(sourcePortName, destPortName); //RenderTexture.active = view; resWidth = view.width; resHeight = view.height; temp2D = new Texture2D(resWidth,resHeight, TextureFormat.ARGB32, false); texImage = imagePort.prepare(); //set resolution and parameters of image texImage.resize(resWidth, resHeight); texImage.setTopIsLowIndex(false); texImage.setQuantum(1); texImage.zero(); System.IntPtr imagePtr = texImage.getRawImage(); int imageSize = texImage.getRawImageSize(); byteArray = new byte[imageSize]; newPtr = Marshal.AllocHGlobal(byteArray.Length); }