2014-04-05 59 views
0

我想知道是否可能: 我得到了一個類似於包含大約11000個圈子的窗體上繪製的顯示的c#應用程序。c#使用自定義像素繪製文本

我想實現的是能夠在該顯示器上繪製文本,但不使用「真實」像素,而是使用在窗體上繪製的圓圈(矩形)作爲像素。

編輯1:

當在C#中繪製文本,你即使用類似Graphics.DrawString(...),給人的方法,其中的文字應中繪製一個矩形(所以座標),那麼繪製文本。在該矩形中使用屏幕像素。我想要做的是繪製文字,但不使用屏幕像素,而是使用我的顯示器組成的自定義像素。用於繪製表格上的圓圈

編輯2

方法; Circles是由Circle對象組成的列表,其中circleRectangle返回應繪製圓的座標,Filled指示方法是否應填充圓。

public void DrawCircles(Graphics g) 
    { 

     graphics = g; 
     graphics.SmoothingMode =System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 
     Pen pen = new Pen(Color.Black, penthickness); 
     SolidBrush brush = new SolidBrush(Color.White); 
     for (int j = 0; j < Circles.Count;j++) 
     { 
      graphics.DrawEllipse(pen, Circles[j].CircleRectangle); 
      if (Circles[j].Filled) 
       brush.Color = fillColor; 
      else 
       brush.Color = Color.White; 
      graphics.FillEllipse(brush, Circles[j].CircleRectangle); 

     } 

    } 

這是可能的,如果是的話,我會怎麼做?

+0

請你能澄清究竟是什麼意思?附: http://en.wikipedia.org/wiki/Pixel – john

回答

3

您可以使用DrawText方法在不可見的BitMap上進行書寫,然後掃描位圖的像素並打開相應的圓圈。

上週做了DataGridView的單元格。真容易。

下面是一些代碼:

public void drawText(string text, Font drawFont) 
    { 
     Bitmap bmp = new Bitmap(canvasWidth, canvasHeight); 
     Graphics G = Graphics.FromImage(bmp); 
     SolidBrush brush = new SolidBrush(paintColor); 
     Point point = new Point(yourOriginX, yourOriginY); 

     G.DrawString(text, drawFont, brush, point); 

     for (int x = 0; x < canvasWidth; x++) 
      for (int y = 0; y < canvasHeight; y++) 
      { 
       Color pix = bmp.GetPixel(x, y); 
        setCell(x, y, pix);  //< -- set your custom pixels here! 
      } 
     bmp.Dispose(); 
     brush.Dispose(); 
     G.Dispose(); 
    } 

編輯:你會用你的尺寸和你的產地爲拉繩,當然

+0

非常感謝你 - 似乎這是我正在尋找的;我會嘗試一下,儘快接受答案! – VGD

+0

當然,祝你好運。我注意到兩件事: - 未設置的像素將有一個Aplha通道值爲0. - 放大顯示抗鋸齒像素暈所有顏色的字母。如果您有問題,請詢問! – TaW

+0

試過了,工作。非常感謝你! – VGD