2013-03-20 2 views
0

Windows Server 2008 R2 64 비트 (x86)가 설치된 개발 PC를 받았습니다. 그래서 그것은 워크 스테이션으로 사용됩니다. 내 개발 환경은 .NET3.5를 대상으로하는 VS2008입니다 (예, !!!).NET System.Drawing Windows Server 2008R2의 다른 모든 창과 비교 64bit (이미지가 2008R2-64에서는 손상되었지만 다른 Windows에서는 그렇지 않음)

웹 사이트 (현재 몇 년 전)에는 자체 개발 한 보안 문자가 있습니다.

는 짧게 이야기하면, 내 dev에 기계 2008R2-64에 있지만 다른 모든 창 (우리의 테스트 & 라이브 서버 2003 64 비트입니다) 및 가상 PC의 (2008 32 비트 NOT R2, XP에 출력되지 않습니다 문자 , Win7)입니다.

나는 웹에서 픽셀이 측정되는 방식이 일 수도 있고 일 수도 있다고 말했지만 (그 중 일부는 알아 내기가 힘들었지 만) 그 밖의 많은 것들을 보지 못했습니다.

다음은이 문제를 설명하기위한 작은 웹 응용 프로그램입니다.

using System; 
using System.Collections.Generic; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

namespace Captcha1 
{ 
    public partial class _Default : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      Random _randomNumberGenerator = new Random(); 

      /* Output random string */ 
      float _xPosition = 20; 
      float _xPositionMax = 0; 
      float _yPosition = 0; 
      float _yPositionMax = 0; 
      string strRandom = string.Empty; 

      /* Prepare drawing functions to output */ 
      System.Drawing.Bitmap objBmp = new System.Drawing.Bitmap(500, 200); 
      System.Drawing.Graphics objGraphics = System.Drawing.Graphics.FromImage(objBmp); 
      objGraphics.Clear(System.Drawing.Color.AliceBlue); 
      objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; 

      string[] strFont = new string[] { "Arial" }; 
      string[] strArray = new string[] { "a", "b", "c", "d", "e" }; 
      strRandom = "AAAAAA";//these are the characters for the captcha. In normal circumstances it would be random! 

      /* Render the image */ 
      int _rotate = -1; 
      objGraphics.RotateTransform(3); 
      foreach (char _char in strRandom.ToCharArray()) 
      { 
       /* Rotate the image */ 
       objGraphics.RotateTransform((float)(_rotate * 5)); 
       _rotate = (_rotate == 1) ? -1 : 1; 

       /* Generate random y position */ 
       _yPosition = Convert.ToInt32(_randomNumberGenerator.Next(15, 20)); 

       /* Select random font */ 
       System.Drawing.Font objFont = new System.Drawing.Font("Arial", 22, System.Drawing.FontStyle.Bold); 

       /* Output the next character */ 
       objGraphics.DrawString(_char.ToString(), objFont, System.Drawing.Brushes.Black, _xPosition, _yPosition); 

       /* Get the width of the string added */ 
       System.Drawing.SizeF _stringSize = objGraphics.MeasureString(_char.ToString(), objFont); 

       /* Dispose of the font */ 
       objFont.Dispose(); 

       /* Output the next character */ 
       objGraphics.DrawImage(objBmp, _xPosition, _yPosition); 

       /* Increment x position */ 
       _xPosition = _xPosition + (_stringSize.Width * (float)0.8); 

       /* Get bounding area */ 
       _xPositionMax = _xPosition; 
       _yPositionMax = (int)(_yPosition + _stringSize.Height); 
      } 
      _xPositionMax += 20; 
      _yPositionMax += 15; 

      System.Drawing.Bitmap objBmpFinal = new System.Drawing.Bitmap((int)_xPositionMax, (int)_yPositionMax); 
      System.Drawing.Graphics objGraphicsFinal = System.Drawing.Graphics.FromImage(objBmpFinal); 
      System.Drawing.Rectangle _rectDest = new System.Drawing.Rectangle(0, 0, (int)_xPositionMax, (int)_yPositionMax); 
      objGraphicsFinal.DrawImageUnscaledAndClipped(objBmp, _rectDest); 

      /* Draw a curve over the image */ 
      float _yPositionMaxCurve = _yPositionMax - 20; 
      System.Drawing.Pen _penCurve = new System.Drawing.Pen(System.Drawing.Color.Black, 2); 
      objGraphicsFinal.DrawBezier(_penCurve, 
       _randomNumberGenerator.Next(5, 10), _randomNumberGenerator.Next(5, (int)_yPositionMaxCurve), 
       _randomNumberGenerator.Next((int)(_xPositionMax/6), (int)(_xPositionMax/5)), _randomNumberGenerator.Next((int)(_yPositionMaxCurve/2), (int)_yPositionMaxCurve),    // y2 
       _randomNumberGenerator.Next((int)(_xPositionMax/4), (int)(_xPositionMax/3)), _randomNumberGenerator.Next(5, (int)_yPositionMaxCurve),        // y3 
       _randomNumberGenerator.Next((int)(_xPositionMax - 5), (int)_xPositionMax), _randomNumberGenerator.Next(5, (int)_yPositionMaxCurve));       // y4 
      _penCurve.Dispose(); 

      /* Draw diagonal lines */ 
      System.Drawing.Pen _penHatch = new System.Drawing.Pen(System.Drawing.Color.Black, 1); 
      for (int _i = -100; _i < _xPositionMax; _i += ((int)_xPositionMax/8)) 
      { 
       float _bottomPos = ((float)Math.Tan((Math.PI * 45/180.0)) * _yPositionMax); 
       objGraphicsFinal.DrawLine(_penHatch, _i, 0, _bottomPos + _i, _yPositionMax); 
      } 
      for (int _i = 0; _i < (_xPositionMax + 100); _i += ((int)_xPositionMax/8)) 
      { 
       float _bottomPos = ((float)Math.Tan((Math.PI * 45/180.0)) * _yPositionMax); 
       objGraphicsFinal.DrawLine(_penHatch, _i, 0, ((-_bottomPos) + _i), _yPositionMax); 
      } 
      _penHatch.Dispose(); 

      /* Draw bounding rectangle */ 
      System.Drawing.Pen _penBorder = new System.Drawing.Pen(System.Drawing.Color.Black, 1); 
      objGraphicsFinal.DrawRectangle(_penBorder, 0, 0, (int)(_xPositionMax - 1), (int)(_yPositionMax - 1)); 
      _penBorder.Dispose(); 

      /* Draw random speckles */ 
      for (int _speckle = 0; _speckle < 100; _speckle++) 
      { 
       /* Generate a random colour */ 
       System.Drawing.Color _speckleColor = System.Drawing.Color.FromArgb((byte)_randomNumberGenerator.Next(0, 255), (byte)_randomNumberGenerator.Next(0, 255), (byte)_randomNumberGenerator.Next(0, 255)); 

       /* Create a brush */ 
       System.Drawing.SolidBrush _speckleBrush = new System.Drawing.SolidBrush(_speckleColor); 

       /* Select random font */ 
       System.Drawing.Font _speckleFont = new System.Drawing.Font(strFont[_randomNumberGenerator.Next(0, (strFont.Length - 1))], _randomNumberGenerator.Next(2, 6), System.Drawing.FontStyle.Regular); 

       /* Get speckle character */ 
       int i = Convert.ToInt32(_randomNumberGenerator.Next(0, (strArray.Length - 1))); 
       string _speckleCharacter = strArray[i].ToString(); 

       /* Draw speckle */ 
       objGraphicsFinal.DrawString(_speckleCharacter, _speckleFont, _speckleBrush, _randomNumberGenerator.Next(0, (int)_xPositionMax), _randomNumberGenerator.Next(0, (int)_yPositionMax)); 

       /* Dispose of objects */ 
       _speckleBrush.Dispose(); 
       _speckleFont.Dispose(); 
      } 

      /* Output the image */ 
      Response.ContentType = "image/GIF"; 
      objBmpFinal.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); 

      objGraphics.Dispose(); 
      objGraphicsFinal.Dispose(); 

      objBmpFinal.Dispose(); 
      objBmp.Dispose(); 

      /* End the response */ 
      Response.End(); 
     } 
    } 
} 

여기에 몇 가지 이미지가 어떻게 보일지하고 승리 2008R2 (64)

에 모습을 보이게하는 방법을 보여주고있다 : Working Captcha Image

작동하지 않음! ! enter image description here

"역할"이 켜져 있지 않을 수도 있으므로 (ASP.NET, .NET3.5, 정적 컨텐츠는 모두 체크 표시되어 있음)이 PC 만 있습니다.

누구나 멋진 아이디어가 있습니까?

+0

너의 maschine에 설치된 arial-bold 글꼴이 손상되었습니다. arial-regular 또는 다른 글꼴을 대신 사용하면 어떻게됩니까? –

+0

모든 글꼴과 동일합니다. 코드 샘플을 쉽게 이해할 수 있도록 Arial을 붙였습니다. – DomBat

답변

0

이 문제를 나누고 정복해야합니다. 이렇게하는 방법은 출력에 영향을 미치지 않는 사항 (배경 항목)을 제거하는 것입니다. 그런 다음 무작위 요소 (동일한 결과를 얻을 수 있도록 생성기를 시드 할 수 있음)를 제거하거나 상수를 사용합니다. "이 줄이있을 때 텍스트가 없지만 꺼내면 텍스트가 있습니다."라고 생각하면 그 원인을 찾을 수 있습니다.

captcha로 주변을 둘러 보는 것은 재미 있지만, 디버깅과 검증을 매우 어렵게 만들었습니다. 이 유형의 코드는 단위 테스트를 거쳐 단위 테스트가 가능해야 특정 시작 시드를 통해 일관된 결과를 얻을 수 있습니다.

우리 환경에서는 한 테스트 서버에 글꼴 버전이 있고 글꼴 버전이 하나도 없기 때문에 글꼴이 픽셀 동일하지 않은 문제가 있습니다. 나는 당신의 문제로 보지 못합니다.

+0

동의하지 마십시오. 이 코드는 다른 사람들이 작성한 오래된 코드이며 재 작성되지 않습니다. 문제가되는 줄이 objGraphics.DrawImage (objBmp, _xPosition, _yPosition); 그것을 밖으로 자르고 captcha는 2008R2에 작동하고 다른 버전에 검사하고 아직도 일한다. 좋은 – DomBat