GRAY









How do I use G R A Y
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: TiledAssetPostProcessor.cs Copy
150         private void OnPreprocessTexture()
151         {
152             if (!UseThisImporter())
153                 return;
154
155             TextureImporter textureImporter = this.assetImporter as TextureImporter;
156             textureImporter.textureType = TextureImporterType.Default;
157             textureImporter.npotScale = TextureImporterNPOTScale.None;
158             textureImporter.convertToNormalmap = false;
159             textureImporter.lightmap = false;
160             textureImporter.alphaIsTransparency = true;
161             textureImporter.grayscaleToAlpha = false;
162             textureImporter.linearTexture = false;
163             textureImporter.spriteImportMode = SpriteImportMode.None;
164             textureImporter.mipmapEnabled = false;
165             textureImporter.generateCubemap = TextureImporterGenerateCubemap.None;
166             textureImporter.filterMode = FilterMode.Point;
167             textureImporter.wrapMode = TextureWrapMode.Clamp;
168             textureImporter.textureFormat = TextureImporterFormat.AutomaticTruecolor;
169         }
File name: Filters.cs Copy
25   public static bool GrayScale(Bitmap b)
26   {
27    // GDI+ still lies to us - the return format is BGR, NOT RGB.
28    BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
29
30             //dia chi o nho chua diem anh dau tien
31    int stride = bmData.Stride;
32
33             //so byte tren 1 hang
34    System.IntPtr Scan0 = bmData.Scan0;
35             //kiem soat con tro(ma ko an toan)
36    unsafe
37    {
38                 //khai bao con tro p co dia chi o scan0
39     byte * p = (byte *)(void *)Scan0;
40                 //ria cua anh, de con tro chay den hang thu 2
41     int nOffset = stride - b.Width*3;
42
43     byte red, green, blue;
44              //cho chay het 1 cot
45     for(int y=0;y
46     {
47                     //cho theo hang
48      for(int x=0; x < b.Width; ++x )
49      {
50       blue = p[0];
51       green = p[1];
52       red = p[2];
53                         //cong thuc bien doi anh xam
54       p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue);
55                         //sang diem anh ke tiep
56       p += 3;
57      }
58                     //xuong hang ke tiep(ria cua anh)
59      p += nOffset;
60     }
61    }
62             //giai phong bien bmData
63    b.UnlockBits(bmData);
64
65    return true;
66   }
File name: frmMain.cs Copy
59   private void InitializeComponent()
60   {
61             this.components = new System.ComponentModel.Container();
62             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));
63             this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
64             this.menuItem1 = new System.Windows.Forms.MenuItem();
65             this.FileLoad = new System.Windows.Forms.MenuItem();
66             this.FileSave = new System.Windows.Forms.MenuItem();
67             this.FileExit = new System.Windows.Forms.MenuItem();
68             this.menuItem4 = new System.Windows.Forms.MenuItem();
69             this.FilterGrayScale = new System.Windows.Forms.MenuItem();
70             this.FilterColor = new System.Windows.Forms.MenuItem();
71             this.menuItem3 = new System.Windows.Forms.MenuItem();
72             this.EmbossLaplacian = new System.Windows.Forms.MenuItem();
73             this.EdgeDetectQuick = new System.Windows.Forms.MenuItem();
74             this.SuspendLayout();
75             //
76             // mainMenu1
77             //
78             this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
79             this.menuItem1,
80             this.menuItem4,
81             this.menuItem3});
82             //
83             // menuItem1
84             //
85             this.menuItem1.Index = 0;
86             this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
87             this.FileLoad,
88             this.FileSave,
89             this.FileExit});
90             this.menuItem1.Text = "File";
91             //this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
92             //
93             // FileLoad
94             //
95             this.FileLoad.Index = 0;
96             this.FileLoad.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
97             this.FileLoad.Text = "Mở file";
98             this.FileLoad.Click += new System.EventHandler(this.File_Load);
99             //
100             // FileSave
101             //
102             this.FileSave.Index = 1;
103             this.FileSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
104             this.FileSave.Text = "Lưu file";
105             this.FileSave.Click += new System.EventHandler(this.File_Save);
106             //
107             // FileExit
108             //
109             this.FileExit.Index = 2;
110             this.FileExit.Text = "Thoát";
111             this.FileExit.Click += new System.EventHandler(this.File_Exit);
112             //
113             // menuItem4
114             //
115             this.menuItem4.Index = 1;
116             this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
117             this.FilterGrayScale,
118             this.FilterColor});
119             this.menuItem4.Text = "Biến đổi màu";
120             //
121             // FilterGrayScale
122             //
123             this.FilterGrayScale.Index = 0;
124             this.FilterGrayScale.Text = "Xám";
125             this.FilterGrayScale.Click += new System.EventHandler(this.Filter_GrayScale);
126             //
127             // FilterColor
128             //
129             this.FilterColor.Index = 1;
130             this.FilterColor.Text = "Màu";
131             this.FilterColor.Click += new System.EventHandler(this.Filter_Color);
132             //
133             // menuItem3
134             //
135             this.menuItem3.Index = 2;
136             this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
137             this.EmbossLaplacian,
138             this.EdgeDetectQuick});
139             this.menuItem3.Text = "Phát hiện biên";
140             //this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
141             //
142             // EmbossLaplacian
143             //
144             this.EmbossLaplacian.Index = 0;
145             this.EmbossLaplacian.Text = "Laplacian_Emboss";
146             this.EmbossLaplacian.Click += new System.EventHandler(this.OnEmbossLaplacian);
147             //
148             // EdgeDetectQuick
149             //
150             this.EdgeDetectQuick.Index = 1;
151             this.EdgeDetectQuick.Text = "EdgeDetectQuick";
152             this.EdgeDetectQuick.Click += new System.EventHandler(this.OnEdgeDetectQuick);
153             //
154             // frmMain
155             //
156             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
157             this.BackColor = System.Drawing.SystemColors.ControlLightLight;
158             this.BackgroundImage = global::CSharpFilters.Properties.Resources.Daewoo;
159             this.ClientSize = new System.Drawing.Size(349, 237);
160             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
161             this.Menu = this.mainMenu1;
162             this.Name = "frmMain";
163             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
164             this.Text = "Xu ly anh";
165             //this.Load += new System.EventHandler(this.Form1_Load);
166             this.ResumeLayout(false);
167
168   }
File name: bubble.cs Copy
14         public bubble(string message, msgtype messagetype)
15         {
16             InitializeComponent();
17
18             // Set the text in the bubble from the message in the parameter.
19             lblmessage.Text = message;
20
21             // Change Color based on Message type.
22             if (messagetype.ToString() == "In")
23             {
24                 // incoming User message
25                 this.BackColor = Color.Gray;
26             }
27             else
28             {
29                 // Outgoing Bot Message
30                 this.BackColor = Color.FromArgb(0, 164, 147);
31             }
32             Setheight();
33         }
File name: Program.cs Copy
18         ConsoleColor color = ConsoleColor.Gray)
19     {
20         Console.SetCursorPosition(x, y);
21         Console.ForegroundColor = color;
22         Console.Write(c);
23     }
File name: Program.cs Copy
25         ConsoleColor color = ConsoleColor.Gray)
26     {
27         Console.SetCursorPosition(x, y);
28         Console.ForegroundColor = color;
29         Console.Write(str);
30     }
File name: Program.cs Copy
23         static void Main(string[] args)
24         {
25             byte right = 0;
26             byte left = 1;
27             byte down = 2;
28             byte up = 3;
29             int lastFoodTime = 0;
30             int foodDissapearTime = 8000;
31             int negativePoints = 0;
32
33             Position[] directions = new Position[]
34             {
35                 new Position(0, 1), // right
36                 new Position(0, -1), // left
37                 new Position(1, 0), // down
38                 new Position(-1, 0), // up
39             };
40             double sleepTime = 100;
41             int direction = right;
42             Random randomNumbersGenerator = new Random();
43             Console.BufferHeight = Console.WindowHeight;
44             lastFoodTime = Environment.TickCount;
45
46             List obstacles = new List()
47             {
48                 new Position(12, 12),
49                 new Position(14, 20),
50                 new Position(7, 7),
51                 new Position(19, 19),
52                 new Position(6, 9),
53             };
54             foreach (Position obstacle in obstacles)
55             {
56                 Console.ForegroundColor = ConsoleColor.Cyan;
57                 Console.SetCursorPosition(obstacle.col, obstacle.row);
58                 Console.Write("=");
59             }
60
61             Queue snakeElements = new Queue();
62             for (int i = 0; i <= 5; i++)
63             {
64                 snakeElements.Enqueue(new Position(0, i));
65             }
66
67             Position food;
68             do
69             {
70                 food = new Position(randomNumbersGenerator.Next(0, Console.WindowHeight),
71                     randomNumbersGenerator.Next(0, Console.WindowWidth));
72             }
73             while (snakeElements.Contains(food) || obstacles.Contains(food));
74             Console.SetCursorPosition(food.col, food.row);
75             Console.ForegroundColor = ConsoleColor.Yellow;
76             Console.Write("@");
77
78             foreach (Position position in snakeElements)
79             {
80                 Console.SetCursorPosition(position.col, position.row);
81                 Console.ForegroundColor = ConsoleColor.DarkGray;
82                 Console.Write("*");
83             }
84
85             while (true)
86             {
87                 negativePoints++;
88
89                 if (Console.KeyAvailable)
90                 {
91                     ConsoleKeyInfo userInput = Console.ReadKey();
92                     if (userInput.Key == ConsoleKey.LeftArrow)
93                     {
94                         if (direction != right) direction = left;
95                     }
96                     if (userInput.Key == ConsoleKey.RightArrow)
97                     {
98                         if (direction != left) direction = right;
99                     }
100                     if (userInput.Key == ConsoleKey.UpArrow)
101                     {
102                         if (direction != down) direction = up;
103                     }
104                     if (userInput.Key == ConsoleKey.DownArrow)
105                     {
106                         if (direction != up) direction = down;
107                     }
108                 }
109
110                 Position snakeHead = snakeElements.Last();
111                 Position nextDirection = directions[direction];
112
113                 Position snakeNewHead = new Position(snakeHead.row + nextDirection.row,
114                     snakeHead.col + nextDirection.col);
115
116                 if (snakeNewHead.col < 0) snakeNewHead.col = Console.WindowWidth - 1;
117                 if (snakeNewHead.row < 0) snakeNewHead.row = Console.WindowHeight - 1;
118                 if (snakeNewHead.row >= Console.WindowHeight) snakeNewHead.row = 0;
119                 if (snakeNewHead.col >= Console.WindowWidth) snakeNewHead.col = 0;
120
121                 if (snakeElements.Contains(snakeNewHead) || obstacles.Contains(snakeNewHead))
122                 {
123                     Console.SetCursorPosition(0, 0);
124                     Console.ForegroundColor = ConsoleColor.Red;
125                     Console.WriteLine("Game over!");
126                     int userPoints = (snakeElements.Count - 6) * 100 - negativePoints;
127                     //if (userPoints < 0) userPoints = 0;
128                     userPoints = Math.Max(userPoints, 0);
129                     Console.WriteLine("Your points are: {0}", userPoints);
130                     return;
131                 }
132
133                 Console.SetCursorPosition(snakeHead.col, snakeHead.row);
134                 Console.ForegroundColor = ConsoleColor.DarkGray;
135                 Console.Write("*");
136
137                 snakeElements.Enqueue(snakeNewHead);
138                 Console.SetCursorPosition(snakeNewHead.col, snakeNewHead.row);
139                 Console.ForegroundColor = ConsoleColor.Gray;
140                 if (direction == right) Console.Write(">");
141                 if (direction == left) Console.Write("<");
142                 if (direction == up) Console.Write("^");
143                 if (direction == down) Console.Write("v");
144
145
146                 if (snakeNewHead.col == food.col && snakeNewHead.row == food.row)
147                 {
148                     // feeding the snake
149                     do
150                     {
151                         food = new Position(randomNumbersGenerator.Next(0, Console.WindowHeight),
152                             randomNumbersGenerator.Next(0, Console.WindowWidth));
153                     }
154                     while (snakeElements.Contains(food) || obstacles.Contains(food));
155                     lastFoodTime = Environment.TickCount;
156                     Console.SetCursorPosition(food.col, food.row);
157                     Console.ForegroundColor = ConsoleColor.Yellow;
158                     Console.Write("@");
159                     sleepTime--;
160
161                     Position obstacle = new Position();
162                     do
163                     {
164                         obstacle = new Position(randomNumbersGenerator.Next(0, Console.WindowHeight),
165                             randomNumbersGenerator.Next(0, Console.WindowWidth));
166                     }
167                     while (snakeElements.Contains(obstacle) ||
168                         obstacles.Contains(obstacle) ||
169                         (food.row != obstacle.row && food.col != obstacle.row));
170                     obstacles.Add(obstacle);
171                     Console.SetCursorPosition(obstacle.col, obstacle.row);
172                     Console.ForegroundColor = ConsoleColor.Cyan;
173                     Console.Write("=");
174                 }
175                 else
176                 {
177                     // moving...
178                     Position last = snakeElements.Dequeue();
179                     Console.SetCursorPosition(last.col, last.row);
180                     Console.Write(" ");
181                 }
182
183                 if (Environment.TickCount - lastFoodTime >= foodDissapearTime)
184                 {
185                     negativePoints = negativePoints + 50;
186                     Console.SetCursorPosition(food.col, food.row);
187                     Console.Write(" ");
188                     do
189                     {
190                         food = new Position(randomNumbersGenerator.Next(0, Console.WindowHeight),
191                             randomNumbersGenerator.Next(0, Console.WindowWidth));
192                     }
193                     while (snakeElements.Contains(food) || obstacles.Contains(food));
194                     lastFoodTime = Environment.TickCount;
195                 }
196
197                 Console.SetCursorPosition(food.col, food.row);
198                 Console.ForegroundColor = ConsoleColor.Yellow;
199                 Console.Write("@");
200
201                 sleepTime -= 0.01;
202
203                 Thread.Sleep((int)sleepTime);
204             }
205         }
File name: EigenObjectRecognizer.cs Copy
94       public EigenObjectRecognizer(Image[] images, ref MCvTermCriteria termCrit)
95          : this(images, GenerateLabels(images.Length), ref termCrit)
96       {
97       }
File name: EigenObjectRecognizer.cs Copy
113       public EigenObjectRecognizer(Image[] images, String[] labels, ref MCvTermCriteria termCrit)
114          : this(images, labels, 0, ref termCrit)
115       {
116       }
File name: EigenObjectRecognizer.cs Copy
129       public EigenObjectRecognizer(Image[] images, String[] labels, double eigenDistanceThreshold, ref MCvTermCriteria termCrit)
130       {
131          Debug.Assert(images.Length == labels.Length, "The number of images should equals the number of labels");
132          Debug.Assert(eigenDistanceThreshold >= 0.0, "Eigen-distance threshold should always >= 0.0");
133
134          CalcEigenObjects(images, ref termCrit, out _eigenImages, out _avgImage);
135
136          /*
137          _avgImage.SerializationCompressionRatio = 9;
138
139          foreach (Image img in _eigenImages)
140              //Set the compression ration to best compression. The serialized object can therefore save spaces
141              img.SerializationCompressionRatio = 9;
142          */
143
144          _eigenValues = Array.ConvertAll, Matrix>(images,
145              delegate(Image img)
146              {
147                 return new Matrix(EigenDecomposite(img, _eigenImages, _avgImage));
148              });
149
150          _labels = labels;
151
152          _eigenDistanceThreshold = eigenDistanceThreshold;
153       }

Download file with original file name:GRAY

GRAY 119 lượt xem

Gõ tìm kiếm nhanh...