public void Display() { CSCL.Imaging.Graphic image=new CSCL.Imaging.Graphic((uint)width, (uint)height, Format.RGB); for(Int64 i=Constants.GraphicMemoryDisplayAdressStart; i<width*height; i++) { Int64 x=i%width; Int64 y=i/width; byte r=data[i+0]; byte g=data[i+1]; byte b=data[i+2]; byte a=data[i+3]; image.SetPixel((int)x, (int)y, Color.FromArgb(a, r, g, b)); } image.SaveToPNG("display.png"); }
/// <summary> /// Applies an edge filter to the bitmap. /// </summary> /// <param name="bitmap">A bitmap.</param> /// <returns>Edge bitmap.</returns> public static Graphic DetectEdges(Graphic bitmap) { Graphic grayscaleMap=bitmap.ConvertToGray(); Graphic edgeMap=new Graphic(grayscaleMap.Width, grayscaleMap.Height, Format.RGB); for(int y=1; y<edgeMap.Height-1; y++) { for(int x=1; x<edgeMap.Width-1; x++) { int sum=System.Math.Abs(grayscaleMap.GetPixel(x-1, y-1).R+grayscaleMap.GetPixel(x, y-1).R+grayscaleMap.GetPixel(x+1, y-1).R -grayscaleMap.GetPixel(x-1, y+1).R-grayscaleMap.GetPixel(x, y+1).R-grayscaleMap.GetPixel(x+1, y+1).R); System.Drawing.Color z1=grayscaleMap.GetPixel(x-1, y-1); System.Drawing.Color z2=grayscaleMap.GetPixel(x, y-1); System.Drawing.Color z3=grayscaleMap.GetPixel(x+1, y-1); System.Drawing.Color z4=grayscaleMap.GetPixel(x-1, y+1); System.Drawing.Color z5=grayscaleMap.GetPixel(x, y+1); System.Drawing.Color z6=grayscaleMap.GetPixel(x+1, y+1); int foo=z1.R+z2.R+z3.R-z4.R-z5.R-z6.R; if(sum>255) sum=255; sum=255-sum; edgeMap.SetPixel(x, y, System.Drawing.Color.FromArgb(255, sum, sum, sum)); } } return edgeMap; }