Pixel
How do I use Pixel
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonGUI.cs
Copy
69 {
70 get
71 {
72 if( m_DefaultRemoveButtonStyle == null )
73 {
74 m_DefaultRemoveButtonStyle = new GUIStyle();
75 m_DefaultRemoveButtonStyle.fixedWidth = 30;
76 m_DefaultRemoveButtonStyle.fixedHeight = 20;
77 m_DefaultRemoveButtonStyle.active.background = ReorderableListResources.CreatePixelTexture( "Dark Pixel (List GUI)", new Color32( 18, 18, 18, 255 ) );
78 m_DefaultRemoveButtonStyle.imagePosition = ImagePosition.ImageOnly;
79 m_DefaultRemoveButtonStyle.alignment = TextAnchor.MiddleCenter;
80 }
81
82 return m_DefaultRemoveButtonStyle;
83 }
84 }
File name: ReorderableListResources.cs
Copy
130 private static void GenerateSpecialTextures()
131 {
132 var splitterColor = EditorGUIUtility.isProSkin
133 ? new Color( 1f, 1f, 1f, 0.14f )
134 : new Color( 0.59f, 0.59f, 0.59f, 0.55f )
135 ;
136 texItemSplitter = CreatePixelTexture( "(Generated) Item Splitter", splitterColor );
137 }
File name: ReorderableListResources.cs
Copy
147 public static Texture2D CreatePixelTexture( string name, Color color )
148 {
149 var tex = new Texture2D( 1, 1, TextureFormat.ARGB32, false, true );
150 tex.name = name;
151 tex.hideFlags = HideFlags.HideAndDontSave;
152 tex.filterMode = FilterMode.Point;
153 tex.SetPixel( 0, 0, color );
154 tex.Apply();
155 return tex;
156 }
File name: ScmlObject.cs
Copy
45 protected virtual void Parse(XmlElement element)
46 {
47 Version = element.GetString("element", "UNKNOWN");
48 Generator = element.GetString("generator", "UNKNOWN");
49 GeneratorVersion = element.GetString("generator_version", "UNKNOWN");
50
51 string pixelArt = element.GetString("pixel_art_mode", "false");
52 PixelArtMode = pixelArt == "true";
53
54 LoadFolders(element);
55 LoadEntities(element);
56 }
File name: PrefabUtils.cs
Copy
34 public static void BakeTransforms(this Ref childRef, out Vector3 localPosition, out Vector3 localEulerAngles, out Vector3 localScale)
35 {
36 TimelineKey key = childRef.Referenced;
37
38 localPosition = Vector3.zero;
39 localScale = Vector3.one;
40 localEulerAngles = Vector3.zero;
41
42 var unmapped = childRef.Unmapped;
43 var spatial = childRef.Referenced as SpatialTimelineKey;
44 if (spatial != null)
45 {
46 localPosition = unmapped.Position;
47
48 var spriteKey = key as SpriteTimelineKey;
49 if (spriteKey != null)
50 {
51 var sinA = Mathf.Sin(unmapped.Angle);
52 var cosA = Mathf.Cos(unmapped.Angle);
53
54 var pvt = spriteKey.GetPivotOffetFromMiddle();
55
56 pvt.x *= unmapped.Scale.x;
57 pvt.y *= unmapped.Scale.y;
58
59 var rotPX = pvt.x * cosA - pvt.y * sinA;
60 var rotPY = pvt.x * sinA + pvt.y * cosA;
61
62 localPosition.x += rotPX;
63 localPosition.y += rotPY;
64
65 localScale.x = unmapped.Scale.x;
66 localScale.y = unmapped.Scale.y;
67 localPosition.z = ((ObjectRef)childRef).ZIndex * -Z_SPACING;
68 }
69
70 localPosition *= PIXEL_SCALE;
71 localEulerAngles = new Vector3(0, 0, unmapped.Angle_Deg);
72 }
73 }
File name: Filters.cs
Copy
15 public void SetAll(int nVal)
16 {
17 TopLeft = TopMid = TopRight = MidLeft = Pixel = MidRight = BottomLeft = BottomMid = BottomRight = nVal;
18 }
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: Filters.cs
Copy
68 public static bool Color(Bitmap b, int red, int green, int blue)
69 {
70 if (red < -255 || red > 255) return false;
71 if (green < -255 || green > 255) return false;
72 if (blue < -255 || blue > 255) return false;
73
74 // GDI+ still lies to us - the return format is BGR, NOT RGB.
75 BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
76
77 int stride = bmData.Stride;
78 System.IntPtr Scan0 = bmData.Scan0;
79
80 unsafe
81 {
82 byte * p = (byte *)(void *)Scan0;
83
84 int nOffset = stride - b.Width*3;
85 int nPixel;
86
87 for(int y=0;y
88 {
89 for(int x=0; x < b.Width; ++x )
90 {
91 nPixel = p[2] + red;
92 nPixel = Math.Max(nPixel, 0);
93 p[2] = (byte)Math.Min(255, nPixel);
94
95 nPixel = p[1] + green;
96 nPixel = Math.Max(nPixel, 0);
97 p[1] = (byte)Math.Min(255, nPixel);
98
99 nPixel = p[0] + blue;
100 nPixel = Math.Max(nPixel, 0);
101 p[0] = (byte)Math.Min(255, nPixel);
102
103 p += 3;
104 }
105 p += nOffset;
106 }
107 }
108
109 b.UnlockBits(bmData);
110
111 return true;
112 }
File name: Filters.cs
Copy
114 public static bool Conv3x3(Bitmap b, ConvMatrix m)
115 {
116 // Avoid divide by zero errors
117 if (0 == m.Factor) return false;
118
119 Bitmap bSrc = (Bitmap)b.Clone();
120
121 // GDI+ still lies to us - the return format is BGR, NOT RGB.
122 BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
123 BitmapData bmSrc = bSrc.LockBits(new Rectangle(0, 0, bSrc.Width, bSrc.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
124
125 int stride = bmData.Stride;
126 int stride2 = stride * 2;
127 System.IntPtr Scan0 = bmData.Scan0;
128 System.IntPtr SrcScan0 = bmSrc.Scan0;
129
130 unsafe
131 {
132 byte * p = (byte *)(void *)Scan0;
133 byte * pSrc = (byte *)(void *)SrcScan0;
134
135 int nOffset = stride + 6 - b.Width*3;
136 int nWidth = b.Width - 2;
137 int nHeight = b.Height - 2;
138
139 int nPixel;
140
141 for(int y=0;y < nHeight;++y)
142 {
143 for(int x=0; x < nWidth; ++x )
144 {
145 nPixel = ( ( ( (pSrc[2] * m.TopLeft) + (pSrc[5] * m.TopMid) + (pSrc[8] * m.TopRight) +
146 (pSrc[2 + stride] * m.MidLeft) + (pSrc[5 + stride] * m.Pixel) + (pSrc[8 + stride] * m.MidRight) +
147 (pSrc[2 + stride2] * m.BottomLeft) + (pSrc[5 + stride2] * m.BottomMid) + (pSrc[8 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
148
149 if (nPixel < 0) nPixel = 0;
150 if (nPixel > 255) nPixel = 255;
151
152 p[5 + stride]= (byte)nPixel;
153
154 nPixel = ( ( ( (pSrc[1] * m.TopLeft) + (pSrc[4] * m.TopMid) + (pSrc[7] * m.TopRight) +
155 (pSrc[1 + stride] * m.MidLeft) + (pSrc[4 + stride] * m.Pixel) + (pSrc[7 + stride] * m.MidRight) +
156 (pSrc[1 + stride2] * m.BottomLeft) + (pSrc[4 + stride2] * m.BottomMid) + (pSrc[7 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
157
158 if (nPixel < 0) nPixel = 0;
159 if (nPixel > 255) nPixel = 255;
160
161 p[4 + stride] = (byte)nPixel;
162
163 nPixel = ( ( ( (pSrc[0] * m.TopLeft) + (pSrc[3] * m.TopMid) + (pSrc[6] * m.TopRight) +
164 (pSrc[0 + stride] * m.MidLeft) + (pSrc[3 + stride] * m.Pixel) + (pSrc[6 + stride] * m.MidRight) +
165 (pSrc[0 + stride2] * m.BottomLeft) + (pSrc[3 + stride2] * m.BottomMid) + (pSrc[6 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
166
167 if (nPixel < 0) nPixel = 0;
168 if (nPixel > 255) nPixel = 255;
169
170 p[3 + stride] = (byte)nPixel;
171
172 p += 3;
173 pSrc += 3;
174 }
175
176 p += nOffset;
177 pSrc += nOffset;
178 }
179 }
180
181 b.UnlockBits(bmData);
182 bSrc.UnlockBits(bmSrc);
183
184 return true;
185 }
Pixel 123 lượt xem
Gõ tìm kiếm nhanh...