/// <summary> /// Draws the text /// </summary> /// <param name="source"></param> /// <param name="g"></param> public override void Draw(string source, Graphics g, Bitmap baseBitmap) { Color b = Slide.GetColor(this.BackColor); List <string> t = GetFile(source); DrawText(t, g, baseBitmap, b); }
/// <summary> /// Draws the text /// </summary> /// <param name="source"></param> /// <param name="g"></param> public override void Draw(string source, Graphics g, Bitmap baseBitmap) { Color b = Slide.GetColor(this.BackColor); List <string> t = new List <string>(1); t.Add(Text); DrawText(t, g, baseBitmap, b); }
/// <summary> /// Draws the shape /// </summary> /// <param name="source"></param> /// <param name="g"></param> public override void Draw(string source, Graphics g, Bitmap baseBitmap) { try { Color orgColor = Slide.GetColor(this.EdgeColor); Color resColor = Slide.GetColor(Text); for (int yy = 0; yy < this.dy; yy++) { int yy1 = yy + this.y; if (yy1 < 0) { continue; } if (yy1 >= baseBitmap.Height) { continue; } for (int xx = 0; xx < this.dx; xx++) { int xx1 = xx + this.x; if (xx1 < 0) { continue; } if (xx1 >= baseBitmap.Width) { continue; } Color c = baseBitmap.GetPixel(xx1, yy1); int RR = c.R - orgColor.R; if (RR < -this.EdgeTolerance || RR > this.EdgeTolerance) { continue; } int GG = c.G - orgColor.G; if (GG < -this.EdgeTolerance || GG > this.EdgeTolerance) { continue; } int BB = c.B - orgColor.B; if (BB < -this.EdgeTolerance || BB > this.EdgeTolerance) { continue; } baseBitmap.SetPixel(xx1, yy1, resColor); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
protected void SetBorderAndCallout(Graphics g) { if (LineSize <= 0f) { return; } Pen p = new Pen(Slide.GetColor(FontColor), LineSize); float half = LineSize * 0.5f; g.DrawRectangle(p, (float)Text_x + half, (float)Text_y + half, (float)Text_dx - LineSize, (float)Text_dy - LineSize); if (Callout_x < 0 || Callout_y < 0) { p.Dispose(); return; } if ((float)Callout_ellipse >= LineSize) { float xEllipse = (float)(Callout_x - Callout_ellipse) + half; float yEllipse = (float)(Callout_y - Callout_ellipse) + half; float dEllipse = Convert.ToSingle(Callout_ellipse << 1) - LineSize; g.DrawEllipse(p, xEllipse, yEllipse, dEllipse, dEllipse); } switch (Callout_index) { case 0: g.DrawLine(p, (float)Callout_x, (float)Callout_y, half + (float)Text_x, half + (float)Text_y); break; case 1: g.DrawLine(p, (float)Callout_x, (float)Callout_y, -half + (float)Text_x + (float)Text_dx, half + (float)Text_y); break; case 2: g.DrawLine(p, (float)Callout_x, (float)Callout_y, -half + (float)Text_x + (float)Text_dx, -half + (float)Text_y + (float)Text_dy); break; case 3: g.DrawLine(p, (float)Callout_x, (float)Callout_y, half + (float)Text_x, -half + (float)Text_y + (float)Text_dy); break; default: break; } p.Dispose(); }
/// <summary> /// Draws the log line /// </summary> /// <param name="source"></param> /// <param name="g"></param> /// <summary> public override void Draw(string source, Graphics g, Bitmap baseBitmap) { Oilfield_Channel chX = null; Oilfield_Channel chY = null; try { GetDataFile(source); } catch (Exception ex) { throw new Exception(ex.Message); } foreach (Oilfield_Channel oc in LastLog.Channels) { if (oc.Name == Name_x) { chX = oc; } if (oc.Name == Name_y) { chY = oc; } } if (chX == null && LastLog.Channels.Count > Order_x) { chX = LastLog.Channels[Order_x]; } if (chY == null && LastLog.Channels.Count > Order_y) { chY = LastLog.Channels[Order_y]; } if (chX == null) { throw new Exception("File " + Text + " has no " + Name_x); } if (chY == null) { throw new Exception("File " + Text + " has no " + Name_y); } try { Rectangle destRectangle = new Rectangle(x, y, dx + 1, dy + 1); g.SetClip(destRectangle); Brush myBrush = new SolidBrush(Slide.GetColor(FrontColor)); Pen myPen = new Pen(myBrush, LineSize); myPen.DashPattern = GetDashStyle(); List <PointF> myPoints = new List <PointF>(); int i = 0; while (i < chX.Data.Count && i < chY.Data.Count) { plotPointScaled(g, myPen, myPoints, chX.Data[i], chY.Data[i]); i++; } // while if (myPoints.Count > 1) // draw the remaining points, if any { g.DrawLines(myPen, myPoints.ToArray()); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (g != null) { g.ResetClip(); } } }
/// <summary> /// Draws the shape /// </summary> /// <param name="source"></param> /// <param name="g"></param> public override void Draw(string source, Graphics g, Bitmap baseBitmap) { try { int dec1 = 0; int dec2 = 0; int q = Convert.ToInt32(LineSize); if (q > 1) { dec1 = q >> 1; dec2 = q - 1; } Rectangle destRectangle = new Rectangle(x, y, dx + 1, dy + 1); Rectangle drawRectangle = new Rectangle(x + dec1, y + dec1, dx - dec2, dy - dec2); g.SetClip(destRectangle); Brush myBrush = new SolidBrush(Slide.GetColor(FrontColor)); Pen myPen = new Pen(myBrush, LineSize); switch (this.Text) { case "rectangle": g.DrawRectangle(myPen, drawRectangle); break; case "ellipse": g.DrawEllipse(myPen, drawRectangle); break; case "cross": g.DrawLine(myPen, x + (dx >> 1), y, x + (dx >> 1), y + dy); g.DrawLine(myPen, x, y + (dy >> 1), x + dx, y + (dy >> 1)); break; case "xcross": g.DrawLine(myPen, x, y, x + dx, y + dy); g.DrawLine(myPen, x + dx, y, x, y + dy); break; case "dnline": g.DrawLine(myPen, x, y, x + dx, y + dy); break; case "upline": g.DrawLine(myPen, x + dx, y, x, y + dy); break; case "hline": g.DrawLine(myPen, x, y + dy / 2, x + dx, y + dy / 2); break; case "vline": g.DrawLine(myPen, x + dx / 2, y, x + dx / 2, y + dy); break; default: break; } } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (g != null) { g.ResetClip(); } } }
/// <summary> /// Draws the shape /// </summary> /// <param name="source"></param> /// <param name="g"></param> public override void Draw(string source, Graphics g, Bitmap baseBitmap) { try { Font myFont = GetFont(); Size myTextSize = TextRenderer.MeasureText(Text, myFont); Rectangle destRectangle = new Rectangle(x, y, dx, dy); g.SetClip(destRectangle); //g.Clear(Color.Bisque); // Test only int lineStep = Convert.ToInt32(LineSize); if (lineStep < 1) { lineStep = 1; } int half = lineStep >> 1; int step = (Text_dy >> 1) - lineStep; int stepIncrement = 1; Brush myBrushF = new SolidBrush(Slide.GetColor(FontColor)); Brush myBrushT = new SolidBrush(Slide.GetColor(TopColor)); Brush myBrushB = new SolidBrush(Slide.GetColor(BottomColor)); g.FillRectangle(myBrushB, Text_x, Text_y + lineStep, Text_dx, Text_dy - (lineStep << 1)); if (Callout_x >= 0 && Callout_y > Text_y + lineStep) { g.FillRectangle(myBrushB, Callout_x, Text_y + lineStep, myTextSize.Width + myFont.Height, Callout_y - Text_y - lineStep); g.DrawString(Text, myFont, myBrushF, (float)Callout_x + myFont.GetHeight() / 2f, Text_y + Text_dy + myFont.GetHeight() / 2f); } if (Callout_x >= 0 && Callout_y >= 0 && Callout_y < Text_y) { g.FillRectangle(myBrushT, Callout_x, Callout_y, myTextSize.Width + myFont.Height, Text_y + lineStep - Callout_y); g.DrawString(Text, myFont, myBrushF, (float)Callout_x + myFont.GetHeight() / 2f, (float)Callout_y + myFont.GetHeight() / 2f); } myBrushB.Dispose(); myBrushT.Dispose(); myBrushF.Dispose(); Color cTop = Slide.GetColor(TopColor); Color cLine = Slide.GetColor(this.FontColor); for (int ix = 0; ix < Text_dx; ix++) { int jx = ix + Text_x; int step1 = step; if (step1 < 0) { step1 = 0; } if (step1 > Text_dy - lineStep) { step1 = Text_dy - lineStep; } for (int iy = lineStep; iy < step1; iy++) { int jy = iy + Text_y; baseBitmap.SetPixel(jx, jy, cTop); } for (int iy = 0; iy < lineStep; iy++) { int jy = iy + Text_y + step1; baseBitmap.SetPixel(jx, jy, cLine); } step += stepIncrement; if (step >= Text_dy) { stepIncrement = -1; } if (step <= -lineStep) { stepIncrement = 1; } } } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (g != null) { g.ResetClip(); } } }
/// <summary> /// Draws one line of text /// </summary> /// <param name="text">Text to draw</param> /// <param name="x">Label size x</param> /// <param name="y">Label Size y</param> /// <param name="bkColor">Background color (set to Color.Transparent for draw over)</param> /// <returns>Bitmap with text</returns> private Bitmap DrawLabelBitmap(string text, int x, int y, Color bkColor) { if (bkColor == Color.Transparent) { Color substitute = Slide.GetColor(BackColor); Bitmap bmp = DrawLabelBitmap(text, x, y, substitute); for (int iy = 0; iy < bmp.Height; iy++) { for (int ix = 0; ix < bmp.Width; ix++) { Color cc = bmp.GetPixel(ix, iy); if (cc != substitute) { continue; } bmp.SetPixel(ix, iy, bkColor); } } return(bmp); } Bitmap img = null; Graphics tmpG = null; try { img = new Bitmap(x, y); tmpG = Graphics.FromImage(img); tmpG.Clear(bkColor); Color fColor = Slide.GetColor(FontColor); Brush myBrush = new SolidBrush(fColor); Font myFont = GetFont(); tmpG.DrawString("|" + text + "|", myFont, myBrush, 0, 0); int leftPosition = locateLeft(img, bkColor); int rightPosition = img.Width - 1; // save the run for left-justified switch (TextPosition) { case "left": tmpG.Clear(bkColor); tmpG.DrawString(text, myFont, myBrush, leftPosition, 0); break; case "right": rightPosition = locateRight(img, bkColor); tmpG.Clear(bkColor); tmpG.DrawString(text, myFont, myBrush, img.Width - rightPosition, 0); break; case "center": rightPosition = locateRight(img, bkColor); tmpG.Clear(bkColor); tmpG.DrawString(text, myFont, myBrush, (img.Width - rightPosition + leftPosition) >> 1, 0); break; case "justified": tmpG.Clear(bkColor); DrawJustifiedBitmap(img, tmpG, text, myFont, myBrush, bkColor, leftPosition); break; default: tmpG.Clear(bkColor); tmpG.DrawString(text, myFont, myBrush, leftPosition, 0); break; } myFont.Dispose(); myBrush.Dispose(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (tmpG != null) { tmpG.Dispose(); } } return(img); }
public Bitmap GetBitmap(int x, int y, int dx, int dy, Color bColor) { Bitmap bmp = new Bitmap(dx, dy); Graphics g = Graphics.FromImage(bmp); g.Clear(bColor); g.Dispose(); if (!File.Exists(FileName)) { return(bmp); } FileStream fs = null; try { fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); for (int iy = 0; iy < dy; iy++) { int jy = y + iy; if (jy < 0) { continue; } string fileLine = ""; fs.Seek(linePositions[jy], SeekOrigin.Begin); byte[] buffer = new byte[lineLengths[jy]]; fs.Read(buffer, 0, buffer.Length); StringBuilder sb = new StringBuilder(); foreach (byte b in buffer) { sb.Append((char)b); } fileLine = sb.ToString(); string[] ss = fileLine.Split(c_Split); for (int ix = 0; ix < dx; ix++) { int jx = x + ix; if (jx < 0) { continue; } if (jx >= ss.Length) { break; } bmp.SetPixel(ix, iy, Slide.GetColor(ss[jx])); } } } catch (Exception) { } finally { if (fs != null) { fs.Close(); } } return(bmp); }