Gma.QrCodeNet.Encoder/Windows/Render/EncapsulatedPostScriptRenderer.cs
/// <summary>
/// Use the 'image' or 'colorimage' PostScript command to render modules
/// </summary>
/// <param name="matrix">The matrix to be rendered</param>
/// <param name="stream">Output text stream</param>
Use the 'image' or 'colorimage' PostScript command to render modules
Use the ' image ' or ' colorimage ' PostScript command to render modules
private void DrawImage(BitMatrix matrix, StreamWriter stream)
		{
			bool bGrayScale =
				LightColor.R == LightColor.G &&
				LightColor.G == LightColor.B &&
				DarkColor.R == DarkColor.G &&
				DarkColor.G == DarkColor.B;
			string strLightColor = string.Empty;
			string strDarkColor = string.Empty;
			if (bGrayScale)
			{
				strLightColor = LightColor.R.ToString("x2");
				strDarkColor = DarkColor.R.ToString("x2");
			}
			else
			{
				strLightColor = string.Format("{0:x2}{1:x2}{2:x2}", LightColor.R, LightColor.G, LightColor.B);
				strDarkColor = string.Format("{0:x2}{1:x2}{2:x2}", DarkColor.R, DarkColor.G, DarkColor.B);
			}
			stream.WriteLine(@"% Draw squares
q q translate
w h scale
w h 8 [w 0 0 h 0 0]
{<");
			for (int y = 0; y < matrix.Height; ++y)
			{
				for (int x = 0; x < matrix.Width; ++x)
					stream.Write(matrix[x, y] ? strDarkColor : strLightColor);
				stream.WriteLine();
			}
			stream.WriteLine(">}");
			stream.WriteLine(bGrayScale ? "image" : "false 3 colorimage");
		}
private void DrawImage ( BitMatrix matrix , StreamWriter stream ) { bool bGrayScale = LightColor . R == LightColor . G && LightColor . G == LightColor . B && DarkColor . R == DarkColor . G && DarkColor . G == DarkColor . B ; string strLightColor = string . Empty ; string strDarkColor = string . Empty ; if ( bGrayScale ) { strLightColor = LightColor . R . ToString ( " " ) ; strDarkColor = DarkColor . R . ToString ( " " ) ; } else { strLightColor = string . Format ( " " , LightColor . R , LightColor . G , LightColor . B ) ; strDarkColor = string . Format ( " " , DarkColor . R , DarkColor . G , DarkColor . B ) ; } stream . WriteLine ( @"% Draw squares
q q translate
w h scale
w h 8 [w 0 0 h 0 0]
{<" ) ; for ( int y = 0 ; y < matrix . Height ; ++ y ) { for ( int x = 0 ; x < matrix . Width ; ++ x ) stream . Write ( matrix [ x , y ] ? strDarkColor : strLightColor ) ; stream . WriteLine ( ) ; } stream . WriteLine ( " " ) ; stream . WriteLine ( bGrayScale ? " " : " " ) ; }
Use the 'image' or 'colorimage' PostScript command to render modules
Use the ' image ' or ' colorimage ' PostScript command to render modules
matrix
BitMatrix
The matrix to be rendered
The matrix to be rendered
stream
StreamWriter
Output text stream
Output text stream