//------------------------------- internal MyGdiPlusCanvas( int horizontalPageNum, int verticalPageNum, int left, int top, int width, int height) { #if DEBUG debug_canvas_id = dbug_canvasCount + 1; dbug_canvasCount += 1; #endif this.pageNumFlags = (horizontalPageNum << 8) | verticalPageNum; //2. dimension this.left = left; this.top = top; this.right = left + width; this.bottom = top + height; currentClipRect = new System.Drawing.Rectangle(0, 0, width, height); CreateGraphicsFromNativeHdc(width, height); this.gx = System.Drawing.Graphics.FromHdc(win32MemDc.DC); //------------------------------------------------------- //managed object internalPen = new System.Drawing.Pen(System.Drawing.Color.Black); internalSolidBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); this.StrokeWidth = 1; }
/// <summary> /// 初始化 /// </summary> public void Intitial( FontMgr.FontLoadInfo fontLoadInfo ) { try { privateFontCollection = new PrivateFontCollection(); foreach (FontMgr.FontInfo info in fontLoadInfo.UnitCodeFontInfos) { privateFontCollection.AddFontFile( info.path ); } fontFamilys = privateFontCollection.Families; if (fontFamilys.Length != fontLoadInfo.UnitCodeFontInfos.Count) throw new Exception( "导入的各个字体必须属于不同类别" ); for (int i = 0; i < fontFamilys.Length; i++) { fonts.Add( fontLoadInfo.UnitCodeFontInfos[i].name, new System.Drawing.Font( fontFamilys[i], fontLoadInfo.DefualtEmSize ) ); } System.Drawing.Bitmap tempBitMap = new System.Drawing.Bitmap( 1, 1 ); mesureGraphics = System.Drawing.Graphics.FromImage( tempBitMap ); } catch (Exception) { throw new Exception( "读取字体文件出错" ); } }
public void Preview(Surface surface, SGraphics g) { /* todo: include the player * in the brush so we can color new buildings too */ surface.DrawActor(g, surface.GetBrushLocation(), Actor, null); }
public void Preview(Surface surface, SGraphics g) { g.DrawImage(Brush.Bitmap, surface.TileSet.TileSize * surface.GetBrushLocation().X * surface.Zoom + surface.GetOffset().X, surface.TileSet.TileSize * surface.GetBrushLocation().Y * surface.Zoom + surface.GetOffset().Y, Brush.Bitmap.Width * surface.Zoom, Brush.Bitmap.Height * surface.Zoom); }
public DrawContext(System.Drawing.Image image) { this.LastBitmap = image as System.Drawing.Bitmap; this.graphics = System.Drawing.Graphics.FromImage(image); this.pen = new System.Drawing.Pen(this.polygonColor); this.dashPen = new System.Drawing.Pen(this.polygonColor); this.dashPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; }
private void EnsureGraphicsCreated() { if (null == _graphics) { _bmp = new System.Drawing.Bitmap(16, 16); _graphics = System.Drawing.Graphics.FromImage(_bmp); } }
public void Preview(Surface surface, SGraphics g) { g.DrawImage(brushTemplate.Bitmap, surface.TileSetRenderer.TileSize * surface.GetBrushLocation().X * surface.Zoom + surface.GetOffset().X, surface.TileSetRenderer.TileSize * surface.GetBrushLocation().Y * surface.Zoom + surface.GetOffset().Y, brushTemplate.Bitmap.Width * surface.Zoom, brushTemplate.Bitmap.Height * surface.Zoom); }
internal BufferedGraphics(System.Drawing.Graphics bufferedGraphicsSurface, BufferedGraphicsContext context, System.Drawing.Graphics targetGraphics, IntPtr targetDC, Point targetLoc, Size virtualSize) { this.context = context; this.bufferedGraphicsSurface = bufferedGraphicsSurface; this.targetDC = targetDC; this.targetGraphics = targetGraphics; this.targetLoc = targetLoc; this.virtualSize = virtualSize; }
public WFCairoGraphics(System.Drawing.Graphics g) { this.g = g; System.Drawing.RectangleF cb = g.ClipBounds; surf = new Cairo.Win32Surface(g.GetHdc()); cr = new Cairo.Context(surf); cr.Rectangle(cb.X, cb.Y, cb.Width, cb.Height); cr.Clip(); }
public override void Draw(Graphics g) { base.Draw(g); if (Annotation.Polygon.Length == 0) return; var sortedPolyIndices = this.Annotation.Polygon.SortPointsClockwise(); var poly = Annotation.Polygon.GetAt(sortedPolyIndices); var pictureBoxPoly = poly .Select(x => Element.ToPictureBoxCoordinate(x.ToPt())) .ToArray(); g.DrawPolygon(Pen, pictureBoxPoly); }
public override void Draw(Graphics g) { base.Draw(g); if (Annotation.Polygon.Length == 0) return; var pt = this.Annotation.Polygon .Select(x => Element.ToPictureBoxCoordinate(x.ToPt()).ToPt()) .Select(x => x.Round()) .First(); //pt = Element.ToPictureBoxCoordinate(new Point(475, 306).ToPt()).ToPt().Round(); g.DrawRectangle(Pen, new System.Drawing.Rectangle(pt.X - RECT_SIZE / 2, pt.Y - RECT_SIZE / 2, RECT_SIZE, RECT_SIZE)); g.DrawLine(Pen, pt.X - RECT_SIZE / 2, pt.Y - RECT_SIZE / 2, pt.X + RECT_SIZE / 2, pt.Y + RECT_SIZE / 2); // \ g.DrawLine(Pen, pt.X + RECT_SIZE / 2, pt.Y - RECT_SIZE / 2, pt.X - RECT_SIZE / 2, pt.Y + RECT_SIZE / 2); // / }
void OnGUI() { if (Control == null) return; if (Control.Disposing || Control.IsDisposed) { _control = null; return; } System.Drawing.Graphics g = new System.Drawing.Graphics(); g.Control = Control; Control.RaiseOnPaint(new System.Windows.Forms.PaintEventArgs() { Graphics = g }); GUI.skin.label.font = null; GUI.skin.label.fontSize = 13; }
public void ShowBorders(object sender,MouseEventArgs e) { Panel tPanel = (Panel)sender; if (objGraphics != null) return; else objGraphics = null; objGraphics = tPanel.CreateGraphics(); objGraphics.Clear(System.Drawing.SystemColors.Control); foreach(Control pp in tPanel.Controls) { if (pp is PictureBox) { //画边界 objGraphics.DrawRectangle(System.Drawing.Pens.BlueViolet, pp.Left - 1, pp.Top - 1, pp.Width + 1, pp.Height + 1); } else objGraphics = null; } }
public WindowsGraphics(System.Drawing.Graphics g, double w, double h) { graphics = g; graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; // Initial Values alphamultiplier.Add(1); brush.Add(new System.Drawing.SolidBrush(System.Drawing.Color.Black)); dashsize.Add(0); fontfamily.Add("sans-serif"); fontsize.Add(12); path.Add(new System.Drawing.Drawing2D.GraphicsPath()); strokesize.Add(1); }
private void Dispose(bool disposing) { if (disposing) { if (this.context != null) { this.context.ReleaseBuffer(this); if (this.DisposeContext) { this.context.Dispose(); this.context = null; } } if (this.bufferedGraphicsSurface != null) { this.bufferedGraphicsSurface.Dispose(); this.bufferedGraphicsSurface = null; } } }
public BaseCore() { m_SystemGraphics = System.Drawing.Graphics.FromHwnd(this.Window.Handle); Settings.ScreenDPI = new Vector2(m_SystemGraphics.DpiX / 96f, m_SystemGraphics.DpiY / 96f); m_Graphics = new GraphicsDeviceManager(this); m_Graphics.IsFullScreen = false; m_Graphics.PreferredBackBufferWidth = 256; m_Graphics.PreferredBackBufferHeight = 240; m_Graphics.SynchronizeWithVerticalRetrace = false; m_Input = new InterXLib.InputState(); m_Input.Initialize(this.Window.Handle); m_Actions = new ActionBinder(); m_SpriteBatch = new InterXLib.Display.YSpriteBatch(this); this.Components.Add(m_SpriteBatch); m_XGUI = new GUIManager(); this.IsMouseVisible = true; }
public GdiPlusCanvasPainter(System.Drawing.Bitmap gfxBmp) { _width = 800;// gfxBmp.Width; _height = 600;// gfxBmp.Height; _gfxBmp = gfxBmp; _gfx = System.Drawing.Graphics.FromImage(_gfxBmp); //credit: //http://stackoverflow.com/questions/1485745/flip-coordinates-when-drawing-to-control _gfx.ScaleTransform(1.0F, -1.0F);// Flip the Y-Axis _gfx.TranslateTransform(0.0F, -(float)Height);// Translate the drawing area accordingly _currentFillBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); _currentPen = new System.Drawing.Pen(System.Drawing.Color.Black); // _bmpStore = new BufferBitmapStore(_width, _height); }
public void Paint(System.Drawing.Graphics g, IPlotArea layer, PlotItemCollection coll) { Dictionary <G2DPlotItem, Processed2DPlotData> plotDataDict; if (!CanUseStyle(layer, coll, out plotDataDict)) { CoordinateTransformingStyleBase.Paint(g, layer, coll); return; } AltaxoVariant[] yArray = null; // First, add up all items since we start always with the last item int idx = -1; Processed2DPlotData previousItemData = null; foreach (IGPlotItem pi in coll) { if (pi is G2DPlotItem) { idx++; G2DPlotItem gpi = pi as G2DPlotItem; Processed2DPlotData pdata = plotDataDict[gpi]; yArray = AddUp(yArray, pdata); if (idx > 0) // this is not the first item { int j = -1; foreach (int originalIndex in pdata.RangeList.OriginalRowIndices()) { j++; Logical3D rel = new Logical3D( layer.XAxis.PhysicalVariantToNormal(pdata.GetXPhysical(originalIndex)), layer.YAxis.PhysicalVariantToNormal(yArray[j])); double xabs, yabs; layer.CoordinateSystem.LogicalToLayerCoordinates(rel, out xabs, out yabs); pdata.PlotPointsInAbsoluteLayerCoordinates[j] = new System.Drawing.PointF((float)xabs, (float)yabs); } } // we have also to exchange the accessor for the physical y value and replace it by our own one AltaxoVariant[] localArray = (AltaxoVariant[])yArray.Clone(); pdata.YPhysicalAccessor = new IndexedPhysicalValueAccessor(delegate(int i) { return(localArray[i]); }); pdata.PreviousItemData = previousItemData; previousItemData = pdata; } } for (int i = coll.Count - 1; i >= 0; --i) { IGPlotItem pi = coll[i]; if (pi is G2DPlotItem) { G2DPlotItem gpi = pi as G2DPlotItem; Processed2DPlotData pdata = plotDataDict[gpi]; gpi.Paint(g, layer, pdata); } else { pi.Paint(g, layer); } } }
private void button_Click(object sender, RoutedEventArgs e) { for (int im = 0; im < listFiles.Length; im++) { table = new System.Drawing.Bitmap(1281, 1025); gfxTable = System.Drawing.Graphics.FromImage(table); canvas.Children.Clear(); risCanvas(); Directory.CreateDirectory(putSave + @"\Level" + int.Parse(textBoxLevel.Text)); file = new StreamWriter(putSave + @"\Level" + int.Parse(textBoxLevel.Text) + @"\Level" + int.Parse(textBoxLevel.Text) + ".txt"); int narisKvadratov = 0; //Колличество нарисованных квадратов for (int i = 0; i < hPole; i++) for (int j = 0; j < wPole; j++) { if (pole[i, j] == 0) { narisKvadratov++; risuem(i, j, narisKvadratov, listFiles[im]); } } gfxTable.Dispose(); file.Close(); //Сохраняем разметку table.Save(putSave + @"\Level" + textBoxLevel.Text + @"\razmetka.png", System.Drawing.Imaging.ImageFormat.Png); table.Dispose(); table = new System.Drawing.Bitmap(listFiles[im]); table.Save(putSave + @"\Level" + textBoxLevel.Text + @"\success.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); table.Dispose(); textBoxLevel.Text = (Int32.Parse(textBoxLevel.Text) + 1).ToString(); // Вывести массив if (true) { for (int i = 0; i < hPole; i++) { for (int j = 0; j < wPole; j++) { pole[i, j] = 0; } } } } }
public Player(System.Drawing.Graphics graph) { gameObjects = new List<GameObject>(); graphics = graph; }
/// <summary> /// Closes this instance. /// </summary> /// <param name="skipFileSave">if set to <c>true</c> don't save the thumbnail page.</param> public void Close(bool skipFileSave) { if (!skipFileSave && !(_currentCol == 0 && _currentRow == 0)) { _pageBitmap.Save (_filename, _creator._imageCodec, _creator._qualityParameters); } if (_pageBitmap != null) _pageBitmap.Dispose (); _pageBitmap = null; if (_graphics != null) _graphics.Dispose (); _graphics = null; if (_font != null) _font.Dispose (); _font = null; if (_brushWhite != null) _brushWhite.Dispose (); _brushWhite = null; if (_brushBlack != null) _brushBlack.Dispose (); _brushBlack = null; if (_borderPen != null) _borderPen.Dispose (); _borderPen = null; if (_borderHilightPen != null) _borderHilightPen.Dispose (); _borderHilightPen = null; if (_thumbFormat != null) _thumbFormat.Dispose (); _thumbFormat = null; if (_headerFormat != null) _headerFormat.Dispose (); _headerFormat = null; }
private static int MakePic(string sourceImg, string toPath, int pW, int pH) { System.Drawing.Image originalImage = null; System.Drawing.Image bitmap = null; System.Drawing.Graphics g = null; try { originalImage = System.Drawing.Image.FromFile(sourceImg); int oW = originalImage.Width; //原始图片宽 int oH = originalImage.Height; //原始图片高 int tW = oW; //最终显示到页面宽 int tH = oH; //最终显示到页面高 if (oW > pW) //如果原始宽度大于固定宽度 { tW = pW; //最终的宽度等于固定的宽度 tH = pW * oH / oW; //最终的高度等于固定宽度乘以原始高度除以原始宽度 if (tH > pH) { tH = pH; tW = pH * oW / oH;//最终的宽度等于固定高度乘以原始宽度除以原始高度 } } else if (oW < pW)//如果原始宽度小于固定宽度 { tW = oW; if (oH > pH) { tH = pH; tW = pH * oW / oH;//最终的宽度等于固定高度乘以原始宽度除以原始高度 } } else//如果原始宽度等于固定宽度 { if (oH > pH) { tH = pH; tW = pH * oW / oH;//最终的宽度等于固定高度乘以原始宽度除以原始高度 } if (oH < pH) { tH = oH; tW = pH * oW / oH;//最终的宽度等于固定高度乘以原始宽度除以原始高度 } if (oH == pH) { tH = oH; tW = oW; } } //新建一个bmp图片 bitmap = new System.Drawing.Bitmap(tW, tH); //新建一个画板 g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, tW, tH), new System.Drawing.Rectangle(0, 0, oW, oH), System.Drawing.GraphicsUnit.Pixel); //以jpg格式保存缩略图 bitmap.Save(toPath, System.Drawing.Imaging.ImageFormat.Jpeg); return(1); } catch { throw; } finally { if (originalImage != null) { originalImage.Dispose(); } if (bitmap != null) { bitmap.Dispose(); } if (g != null) { g.Dispose(); } } }
/// <summary> /// /// </summary> /// <param name="M"></param> /// <returns></returns> public bool func_啟用毛玻璃(Window M) { //win10 啟用毛玻璃特效 if (IsWindows10()) { try { var c_毛玻璃_win10 = new C_window_AERO(); c_毛玻璃_win10.EnableBlur(M); } catch { return(false); } return(true); }//win10 //win7 啟用毛玻璃特效 if (IsWindows7()) { try { //取得最高的螢幕 int h = 0; foreach (var screen in System.Windows.Forms.Screen.AllScreens) //列出所有螢幕資訊 { int xx = screen.Bounds.Y + screen.Bounds.Height; if (xx > h) { h = xx; } } h += 50; // Obtain the window handle for WPF application IntPtr mainWindowPtr = new WindowInteropHelper(M).Handle; HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr); mainWindowSrc.CompositionTarget.BackgroundColor = System.Windows.Media.Color.FromArgb(0, 0, 0, 0); // Get System Dpi System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr); float DesktopDpiX = desktop.DpiX; float DesktopDpiY = desktop.DpiY; // Set Margins MARGINS margins = new MARGINS(); // Extend glass frame into client area // Note that the default desktop Dpi is 96dpi. The margins are // adjusted for the system Dpi. margins.cxLeftWidth = Convert.ToInt32(0 * (DesktopDpiX / 96)); margins.cxRightWidth = Convert.ToInt32(0 * (DesktopDpiX / 96)); margins.cyTopHeight = Convert.ToInt32(((int)h) * (DesktopDpiX / 96)); margins.cyBottomHeight = Convert.ToInt32(0 * (DesktopDpiX / 96)); int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); // if (hr < 0) { //DwmExtendFrameIntoClientArea Failed } M.BorderThickness = new Thickness(10, 0, 10, h); } catch { // If not Vista, paint background white. //Application.Current.MainWindow.Background = Brushes.White; return(false); } return(true); }//win7 //win8 return(false); }
public void Preview(Surface surface, SGraphics g) { surface.DrawActor(g, surface.GetBrushLocation(), actorTemplate, surface.GetPaletteForPlayer(surface.NewActorOwner)); }
public override void RenderSelection(System.Drawing.Graphics g) { }
public java.awt.Graphics2D createGraphics(System.Drawing.Graphics g) { return(new PrintGraphics(g)); }
/// <summary> /// 生成缩略图 /// </summary> /// <param name="originalImagePath">源图路径(物理路径)</param> /// <param name="thumbnailPath">缩略图路径(物理路径)</param> /// <param name="width">缩略图宽度</param> /// <param name="height">缩略图高度</param> /// <param name="mode">生成缩略图的方式</param> public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode) { System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath); int towidth = width; int toheight = height; int x = 0; int y = 0; int ow = originalImage.Width; int oh = originalImage.Height; switch (mode) { case "HW": //指定高宽缩放(可能变形) break; case "W": //指定宽,高按比例 toheight = originalImage.Height * width / originalImage.Width; break; case "H": //指定高,宽按比例 towidth = originalImage.Width * height / originalImage.Height; break; case "Cut": //指定高宽裁减(不变形) if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight) { oh = originalImage.Height; ow = originalImage.Height * towidth / toheight; y = 0; x = (originalImage.Width - ow) / 2; } else { ow = originalImage.Width; oh = originalImage.Width * height / towidth; x = 0; y = (originalImage.Height - oh) / 2; } break; default: break; } //新建一个bmp图片 System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight); //新建一个画板 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //清空画布并以透明背景色填充 g.Clear(System.Drawing.Color.Transparent); //在指定位置并且按指定大小绘制原图片的指定部分 g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel); try { //以jpg格式保存缩略图 bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (System.Exception e) { throw e; } finally { originalImage.Dispose(); bitmap.Dispose(); g.Dispose(); } }
static public int MeasureDisplayStringWidth(System.Drawing.Graphics graphics, string text, System.Drawing.Font font) { return((int)MeasureDisplayString(graphics, text, font).Width); }
/// <summary> /// Initializes the media events. /// </summary> private void InitializeMediaEvents() { Media.MediaOpened += Media_MediaOpened; Media.MediaOpening += Media_MediaOpening; Media.MediaFailed += Media_MediaFailed; Media.MessageLogged += Media_MessageLogged; Media.PropertyChanged += Media_PropertyChanged; Unosquare.FFME.MediaElement.FFmpegMessageLogged += MediaElement_FFmpegMessageLogged; #if HANDLE_RENDERING_EVENTS #region Audio and Video Frame Rendering Variables System.Drawing.Bitmap overlayBitmap = null; System.Drawing.Graphics overlayGraphics = null; var overlayTextFont = new System.Drawing.Font("Arial", 14, System.Drawing.FontStyle.Bold); var overlayTextFontBrush = System.Drawing.Brushes.WhiteSmoke; var overlayTextOffset = new System.Drawing.PointF(12, 8); var overlayBackBuffer = IntPtr.Zero; var vuMeterLeftPen = new System.Drawing.Pen(System.Drawing.Color.OrangeRed, 12); var vuMeterRightPen = new System.Drawing.Pen(System.Drawing.Color.GreenYellow, 12); var vuMeterRmsLock = new object(); var vuMeterLeftRms = new SortedDictionary <TimeSpan, double>(); var vuMeterRightRms = new SortedDictionary <TimeSpan, double>(); var vuMeterLeftValue = 0d; var vuMeterRightValue = 0d; const float vuMeterLeftOffset = 16; const float vuMeterTopOffset = 50; const float vuMeterScaleFactor = 20; // RMS * pixel factor = the length of the VU meter lines #endregion #region Rendering Event Examples Media.RenderingVideo += (s, e) => { #region Create the overlay buffer to work with if (overlayBackBuffer != e.Bitmap.BackBuffer) { lock (vuMeterRmsLock) { vuMeterLeftRms.Clear(); vuMeterRightRms.Clear(); } if (overlayGraphics != null) { overlayGraphics.Dispose(); } if (overlayBitmap != null) { overlayBitmap.Dispose(); } overlayBitmap = new System.Drawing.Bitmap( e.Bitmap.PixelWidth, e.Bitmap.PixelHeight, e.Bitmap.BackBufferStride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, e.Bitmap.BackBuffer); overlayBackBuffer = e.Bitmap.BackBuffer; overlayGraphics = System.Drawing.Graphics.FromImage(overlayBitmap); overlayGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default; } #endregion #region Read the instantaneous RMS of the audio lock (vuMeterRmsLock) { vuMeterLeftValue = vuMeterLeftRms.Where(kvp => kvp.Key > Media.Position).Select(kvp => kvp.Value).FirstOrDefault(); vuMeterRightValue = vuMeterRightRms.Where(kvp => kvp.Key > Media.Position).Select(kvp => kvp.Value).FirstOrDefault(); // do some cleanup so the dictionary does not grow too big. if (vuMeterLeftRms.Count > 256) { var keysToRemove = vuMeterLeftRms.Keys.Where(k => k < Media.Position).OrderBy(k => k).ToArray(); foreach (var k in keysToRemove) { vuMeterLeftRms.Remove(k); vuMeterRightRms.Remove(k); if (vuMeterLeftRms.Count < 256) { break; } } } } #endregion #region Draw the text and the VU meter e.Bitmap.Lock(); var differenceMillis = TimeSpan.FromTicks(e.Clock.Ticks - e.StartTime.Ticks).TotalMilliseconds; overlayGraphics.DrawString($"Clock: {e.StartTime.TotalSeconds:00.000} | Skew: {differenceMillis:00.000} | PN: {e.PictureNumber}", overlayTextFont, overlayTextFontBrush, overlayTextOffset); // draw a simple VU meter overlayGraphics.DrawLine(vuMeterLeftPen, vuMeterLeftOffset, vuMeterTopOffset, vuMeterLeftOffset + 5 + (Convert.ToSingle(vuMeterLeftValue) * vuMeterScaleFactor), vuMeterTopOffset); overlayGraphics.DrawLine(vuMeterRightPen, vuMeterLeftOffset, vuMeterTopOffset + 20, vuMeterLeftOffset + 5 + (Convert.ToSingle(vuMeterRightValue) * vuMeterScaleFactor), vuMeterTopOffset + 20); e.Bitmap.AddDirtyRect(new Int32Rect(0, 0, e.Bitmap.PixelWidth, e.Bitmap.PixelHeight)); e.Bitmap.Unlock(); #endregion }; Media.RenderingAudio += (s, e) => { // The buffer contains all the samples var buffer = new byte[e.BufferLength]; Marshal.Copy(e.Buffer, buffer, 0, e.BufferLength); // We need to split the samples into left and right samples var leftSamples = new double[e.SamplesPerChannel]; var rightSamples = new double[e.SamplesPerChannel]; // Iterate through the buffer var isLeftSample = true; var sampleIndex = 0; var samplePercent = default(double); for (var i = 0; i < e.BufferLength; i += e.BitsPerSample / 8) { samplePercent = 100d * Math.Abs((double)((short)(buffer[i] | (buffer[i + 1] << 8)))) / (double)short.MaxValue; if (isLeftSample) { leftSamples[sampleIndex] = samplePercent; } else { rightSamples[sampleIndex] = samplePercent; } sampleIndex += !isLeftSample ? 1 : 0; isLeftSample = !isLeftSample; } // Compute the RMS of the samples and save it for the given point in time. lock (vuMeterRmsLock) { // The VU meter should show the audio RMS, we compute it and save it in a dictionary. vuMeterLeftRms[e.StartTime] = Math.Sqrt((1d / leftSamples.Length) * (leftSamples.Sum(n => n))); vuMeterRightRms[e.StartTime] = Math.Sqrt((1d / rightSamples.Length) * (rightSamples.Sum(n => n))); } }; Media.RenderingSubtitles += (s, e) => { // a simple example of suffixing subtitles if (e.Text != null && e.Text.Count > 0) { e.Text[0] = $"{e.Text[0]}\r\n(subtitles)"; } }; #endregion #endif }
public void PaintValue(object value, System.Drawing.Graphics canvas, System.Drawing.Rectangle rectangle) { }
public override void Draw(System.Drawing.Graphics g, System.Drawing.Pen p) { g.DrawLine(p, D1.X, D1.Y, D2.X, D2.Y); }
void BuildFontSheetBitmap(System.Drawing.Font font, System.Drawing.Graphics charGraphics, System.Drawing.Bitmap charBitmap, System.Drawing.Graphics fontSheetGraphics) { System.Drawing.Brush whiteBrush = System.Drawing.Brushes.White; int fontSheetX = 0; int fontSheetY = 0; for (int i = 0; i < NumChars; ++i) { charGraphics.Clear(System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black)); charGraphics.DrawString(((char)(StartChar + i)).ToString(), font, whiteBrush, new System.Drawing.PointF(0.0f, 0.0f)); int minX = GetCharMinX(charBitmap); int maxX = GetCharMaxX(charBitmap); int charWidth = maxX - minX + 1; if (fontSheetX + charWidth >= _texWidth) { fontSheetX = 0; fontSheetY += (int)(_charHeight) + 1; } _charRects[i] = new Rectangle(fontSheetX, fontSheetY, charWidth, _charHeight); fontSheetGraphics.DrawImage(charBitmap, fontSheetX, fontSheetY, new System.Drawing.Rectangle(minX, 0, charWidth, _charHeight), System.Drawing.GraphicsUnit.Pixel); fontSheetX += charWidth + 1; } }
public void DrawEan13Barcode(System.Drawing.Graphics g, System.Drawing.PointF pt) //System.Drawing.Point pt ) { float width = this.Width * this.Scale; float height = this.Height * this.Scale; // EAN13 Barcode should be a total of 113 modules wide. float lineWidth = width / 113f; // Save the GraphicsState. System.Drawing.Drawing2D.GraphicsState gs = g.Save(); // Set the PageUnit to Inch because all of our measurements are in inches. g.PageUnit = System.Drawing.GraphicsUnit.Millimeter; // Set the PageScale to 1, so a millimeter will represent a true millimeter. g.PageScale = 1; System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); //float xPosition = 0; float xPosition = pt.X; System.Text.StringBuilder strbEAN13 = new System.Text.StringBuilder(); System.Text.StringBuilder sbTemp = new System.Text.StringBuilder(); float xStart = pt.X; float yStart = pt.Y; float xEnd = 0; System.Drawing.Font font = new System.Drawing.Font("Arial", this._fFontSize * this.Scale); // Calculate the Check Digit. this.CalculateChecksumDigit(); sbTemp.AppendFormat("{0}{1}{2}{3}", this.CountryCode, this.ManufacturerCode, this.ProductCode, this.ChecksumDigit); string sTemp = sbTemp.ToString(); string sLeftPattern = ""; // Convert the left hand numbers. sLeftPattern = ConvertLeftPattern(sTemp.Substring(0, 7)); // Build the UPC Code. strbEAN13.AppendFormat("{0}{1}{2}{3}{4}{1}{0}", this._sQuiteZone, this._sLeadTail, sLeftPattern, this._sSeparator, ConvertToDigitPatterns(sTemp.Substring(7), this._aRight)); string sTempUPC = strbEAN13.ToString(); float fTextHeight = g.MeasureString(sTempUPC, font).Height; // Draw the barcode lines. for (int i = 0; i < strbEAN13.Length; i++) { if (sTempUPC.Substring(i, 1) == "1") { if (xStart == pt.X) { xStart = xPosition; } // Save room for the UPC number below the bar code. if ((i > 12 && i < 55) || (i > 57 && i < 101)) { // Draw space for the number g.FillRectangle(brush, xPosition, yStart, lineWidth, height - fTextHeight); } else { // Draw a full line. g.FillRectangle(brush, xPosition, yStart, lineWidth, height); } } xPosition += lineWidth; xEnd = xPosition; } // Draw the upc numbers below the line. xPosition = xStart - g.MeasureString(this.CountryCode.Substring(0, 1), font).Width; float yPosition = yStart + (height - fTextHeight); // Draw 1st digit of the country code. g.DrawString(sTemp.Substring(0, 1), font, brush, new System.Drawing.PointF(xPosition, yPosition)); xPosition += (g.MeasureString(sTemp.Substring(0, 1), font).Width + 43 * lineWidth) - (g.MeasureString(sTemp.Substring(1, 6), font).Width); // Draw MFG Number. g.DrawString(sTemp.Substring(1, 6), font, brush, new System.Drawing.PointF(xPosition, yPosition)); xPosition += g.MeasureString(sTemp.Substring(1, 6), font).Width + (11 * lineWidth); // Draw Product ID. g.DrawString(sTemp.Substring(7), font, brush, new System.Drawing.PointF(xPosition, yPosition)); // Restore the GraphicsState. g.Restore(gs); }
public void DrawDynamic(System.Drawing.Graphics graphics) { }
public SepLinePainter(System.Drawing.Graphics g) { this.g = g; //width = Form1.ActiveForm.Width; //height = Form1.ActiveForm.Height; }
/// <summary> /// Set window parameters /// </summary> /// <param name="width">Width of the Window</param> /// <param name="height">Height of the Window</param> /// <param name="title">Title of the Window</param> public void createWindow(int width, int height, string title, borderStyles borderStyle = borderStyles.Normal, bool fullscreen = false) { FormBorderStyle b = FormBorderStyle.FixedSingle; switch(borderStyle){ case borderStyles.Normal: b = FormBorderStyle.FixedSingle; break; case borderStyles.Borderless: b = FormBorderStyle.None; break; default: break; } f.ShowIcon = false; f.MinimizeBox = false; f.MaximizeBox = false; f.ControlBox = false; f.UseWaitCursor = false; f.Cursor = Cursors.Arrow; if (fullscreen) { //f.TopMost = true; f.FormBorderStyle = FormBorderStyle.None; f.WindowState = FormWindowState.Maximized; } else { f.Width = width; f.Height = height; f.FormBorderStyle = b; } f.Text = title; g = f.CreateGraphics(); // Set console crap up and all that jazz... Console.Title = title + " - CONSOLE"; }
/// <summary> /// 加图片水印 /// </summary> /// <param name="filename">文件名</param> /// <param name="watermarkFilename">水印文件名</param> /// <param name="watermarkStatus">图片水印位置:0=不使用 1=左上 2=中上 3=右上 4=左中 ... 9=右下</param> /// <param name="quality">是否是高质量图片 取值范围0--100</param> /// <param name="watermarkTransparency">图片水印透明度 取值范围1--10 (10为不透明)</param> public static void AddImageSignPic(string Path, string filename, string watermarkFilename, int watermarkStatus, int quality, int watermarkTransparency) { System.Drawing.Image img = System.Drawing.Image.FromFile(Path); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img); //设置高质量插值法 //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; System.Drawing.Image watermark = new System.Drawing.Bitmap(watermarkFilename); if (watermark.Height >= img.Height || watermark.Width >= img.Width) { return; } System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes(); System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0); System.Drawing.Imaging.ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); float transparency = 0.5F; if (watermarkTransparency >= 1 && watermarkTransparency <= 10) { transparency = (watermarkTransparency / 10.0F); } float[][] colorMatrixElements = { new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, transparency, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }; System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); int xpos = 0; int ypos = 0; switch (watermarkStatus) { case 1: xpos = (int)(img.Width * (float).01); ypos = (int)(img.Height * (float).01); break; case 2: xpos = (int)((img.Width * (float).50) - (watermark.Width / 2)); ypos = (int)(img.Height * (float).01); break; case 3: xpos = (int)((img.Width * (float).99) - (watermark.Width)); ypos = (int)(img.Height * (float).01); break; case 4: xpos = (int)(img.Width * (float).01); ypos = (int)((img.Height * (float).50) - (watermark.Height / 2)); break; case 5: xpos = (int)((img.Width * (float).50) - (watermark.Width / 2)); ypos = (int)((img.Height * (float).50) - (watermark.Height / 2)); break; case 6: xpos = (int)((img.Width * (float).99) - (watermark.Width)); ypos = (int)((img.Height * (float).50) - (watermark.Height / 2)); break; case 7: xpos = (int)(img.Width * (float).01); ypos = (int)((img.Height * (float).99) - watermark.Height); break; case 8: xpos = (int)((img.Width * (float).50) - (watermark.Width / 2)); ypos = (int)((img.Height * (float).99) - watermark.Height); break; case 9: xpos = (int)((img.Width * (float).99) - (watermark.Width)); ypos = (int)((img.Height * (float).99) - watermark.Height); break; } g.DrawImage(watermark, new System.Drawing.Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes); System.Drawing.Imaging.ImageCodecInfo[] codecs = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders(); System.Drawing.Imaging.ImageCodecInfo ici = null; foreach (System.Drawing.Imaging.ImageCodecInfo codec in codecs) { //if (codec.MimeType.IndexOf("jpeg") > -1) if (codec.MimeType.Contains("jpeg")) { ici = codec; } } System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters(); long[] qualityParam = new long[1]; if (quality < 0 || quality > 100) { quality = 80; } qualityParam[0] = quality; System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam); encoderParams.Param[0] = encoderParam; if (ici != null) { img.Save(filename, ici, encoderParams); } else { img.Save(filename); } g.Dispose(); img.Dispose(); watermark.Dispose(); imageAttributes.Dispose(); }
// Needs to be called once to know associated object public void SetDrawDestination(ref System.Windows.Forms.PictureBox obj) { Video = obj.CreateGraphics(); VBlank(); }
public Graphics(System.Drawing.Graphics internalGraphics) { InternalGraphics = internalGraphics; }
public void DrawStatic(System.Drawing.Graphics graphics) { }
/// <summary> /// Initializes a new instance of the <see cref="ThumbnailPage"/> class. /// </summary> /// <param name="creator">The <see cref="ThumbnailCreator"/> /// (only used to get a jpeg compression encoder).</param> /// <param name="tgrid">The <see cref="ThumbnailGrid"/> that specifies /// the page layout.</param> /// <param name="displayFilename">The display name of the <see cref="AVFileSet"/> /// from which the thumbnails are generated.</param> /// <param name="filename">The fullpath of thumbnail page to create.</param> /// <param name="nFiles">The number of files in set (>0 for multi-part videos).</param> /// <param name="time">The time of first thumbnail on page.</param> /// <param name="pageNum">The page number (0 for overview page).</param> /// <param name="duration">The duration of the <see cref="AVFileSet"/>.</param> /// <param name="nPages">The total number of thumbnail pages.</param> /// <param name="stats">The stats of the <see cref="AVFileSet"/> to display /// in header.</param> public ThumbnailPage(ThumbnailCreator creator, ThumbnailGrid tgrid, string displayFilename, string filename, int nFiles, TimeSpan time, int pageNum, TimeSpan duration, int nPages, string stats) { this._creator = creator; this._tgrid = tgrid; this._filename = filename; _pageBitmap = new System.Drawing.Bitmap (tgrid.Layout.Width, tgrid.Layout.Height); _graphics = System.Drawing.Graphics.FromImage (_pageBitmap); _graphics.PageUnit = System.Drawing.GraphicsUnit.Pixel; _graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; //_graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; _graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; //_graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; _graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None; // can't use TextRenderingHint.ClearTypeGridFit with CompositingMode.SourceCopy //_graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; //_graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; _graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; // Affects image resizing _graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; // Affects anti-aliasing of filled edges //_graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; _graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; _font = new System.Drawing.Font ("Arial", (float) (7 * creator.TNSettings.ScaleFactor), System.Drawing.FontStyle.Bold); _brushWhite = new System.Drawing.SolidBrush (System.Drawing.Color.White); _brushBlack = new System.Drawing.SolidBrush (System.Drawing.Color.Black); _borderPen = new System.Drawing.Pen (System.Drawing.Color.Wheat, tgrid.Layout.Border <= 1 ? 0 : tgrid.Layout.Border); _borderHilightPen = new System.Drawing.Pen (System.Drawing.Color.Red, tgrid.Layout.Border <= 1 ? 0 : tgrid.Layout.Border); //_borderPen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset; //_borderPen.LineJoin = System.Drawing.Drawing2D.LineJoin.Miter; _graphics.FillRectangle (_brushBlack, 0, 0, tgrid.Layout.Width, tgrid.Layout.Height); _thumbFormat = new System.Drawing.StringFormat (); switch (creator.TNSettings.LabelPosition) { case ThumbnailSettings.LabelPositions.None: case ThumbnailSettings.LabelPositions.LowerRight: { _thumbFormat.LineAlignment = System.Drawing.StringAlignment.Far; _thumbFormat.Alignment = System.Drawing.StringAlignment.Far; break; } case ThumbnailSettings.LabelPositions.LowerLeft: { _thumbFormat.LineAlignment = System.Drawing.StringAlignment.Far; _thumbFormat.Alignment = System.Drawing.StringAlignment.Near; break; } case ThumbnailSettings.LabelPositions.UpperRight: { _thumbFormat.LineAlignment = System.Drawing.StringAlignment.Near; _thumbFormat.Alignment = System.Drawing.StringAlignment.Far; break; } case ThumbnailSettings.LabelPositions.UpperLeft: { _thumbFormat.LineAlignment = System.Drawing.StringAlignment.Near; _thumbFormat.Alignment = System.Drawing.StringAlignment.Near; break; } } _headerFormat = new System.Drawing.StringFormat (); _headerFormat.LineAlignment = System.Drawing.StringAlignment.Center; _headerFormat.Alignment = System.Drawing.StringAlignment.Near; float inset = 2*tgrid.Layout.Margin; System.Drawing.RectangleF headerRectF = new System.Drawing.RectangleF (inset, 0, this._tgrid.Layout.Width - 2*inset, this._tgrid.Layout.HeaderHeight); //_graphics.DrawRectangle (_borderPen, // headerRectF.X, // headerRectF.Y, // headerRectF.Width, // headerRectF.Height); string leftSide; string timeformat = @"h\:mm\:ss"; if (time.Milliseconds > 0 && creator.TNSettings.AlwaysShowMilliseconds) timeformat = @"h\:mm\:ss\.ffff"; if (pageNum > 0) leftSide = String.Format ("{0} / {1} ({2} of {3})", time.ToString (timeformat), duration.ToString (@"h\:mm\:ss"), pageNum, nPages); else leftSide = String.Format ("{0}", duration.ToString (@"h\:mm\:ss")); if (nFiles > 0) leftSide += String.Format (" {0} files", nFiles); using (System.Drawing.Font headerFont = new System.Drawing.Font ( ThumbnailPageLayout.FONT_NAME, (float) (ThumbnailPageLayout.FONT_SIZE * creator.TNSettings.ScaleFactor), System.Drawing.FontStyle.Bold)) { _graphics.DrawString (leftSide, headerFont, _brushWhite, headerRectF, _headerFormat); _headerFormat.Alignment = System.Drawing.StringAlignment.Far; _graphics.DrawString (stats, headerFont, _brushWhite, headerRectF, _headerFormat); float left = headerRectF.Left + _graphics.MeasureString(leftSide, headerFont).Width; float right = headerRectF.Right - _graphics.MeasureString (stats, headerFont).Width; headerRectF = new System.Drawing.RectangleF ( left, headerRectF.Top, right - left, headerRectF.Height); _headerFormat.Alignment = System.Drawing.StringAlignment.Center; _graphics.DrawString (displayFilename, headerFont, _brushWhite, headerRectF, _headerFormat); } _pageNum = pageNum; _currentCol = 0; _currentRow = 0; }
public void RenderLayer(IVectorLayer layer, Map map, System.Drawing.Graphics g) { if (map.Center == null) { throw (new ApplicationException("Cannot render map. View center not specified")); } g.SmoothingMode = layer.SmoothingMode; SharpMap.Geometries.BoundingBox envelope = map.Envelope; //View to render if (layer.CoordinateTransformation != null) { envelope = GeometryTransform.TransformBox( envelope, layer.CoordinateTransformation.MathTransform.Inverse()); } //List<SharpMap.Geometries.Geometry> features = this.DataSource.GetGeometriesInView(map.Envelope); if (layer.DataSource == null) { throw (new ApplicationException("DataSource property not set on layer '" + layer.LayerName + "'")); } //If thematics is enabled, we use a slighty different rendering approach if (layer.Theme != null) { SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet(); layer.DataSource.Open(); layer.DataSource.ExecuteIntersectionQuery(envelope, ds); layer.DataSource.Close(); FeatureDataTable features = (FeatureDataTable)ds.Tables[0]; if (layer.CoordinateTransformation != null) { for (int i = 0; i < features.Count; i++) { features[i].Geometry = GeometryTransform.TransformGeometry(features[i].Geometry, layer.CoordinateTransformation.MathTransform); } } //Linestring outlines is drawn by drawing the layer once with a thicker line //before drawing the "inline" on top. if (layer.Style.EnableOutline) { //foreach (SharpMap.Geometries.Geometry feature in features) for (int i = 0; i < features.Count; i++) { SharpMap.Data.FeatureDataRow feature = features[i]; //Draw background of all line-outlines first if (feature.Geometry is SharpMap.Geometries.LineString) { IVectorStyle outlinestyle1 = layer.Theme.GetStyle(feature); if (outlinestyle1.Enabled && outlinestyle1.EnableOutline) { SharpMap.Rendering.VectorRenderer.DrawLineString(g, feature.Geometry as LineString, outlinestyle1.Outline, map); } } else if (feature.Geometry is SharpMap.Geometries.MultiLineString) { IVectorStyle outlinestyle2 = layer.Theme.GetStyle(feature); if (outlinestyle2.Enabled && outlinestyle2.EnableOutline) { SharpMap.Rendering.VectorRenderer.DrawMultiLineString(g, feature.Geometry as MultiLineString, outlinestyle2.Outline, map); } } } } for (int i = 0; i < features.Count; i++) { SharpMap.Data.FeatureDataRow feature = features[i]; IVectorStyle style = layer.Theme.GetStyle(feature); RenderGeometry(g, map, layer.ClippingEnabled, feature.Geometry, style); } } else { layer.DataSource.Open(); Collection <Geometry> geoms = layer.DataSource.GetGeometriesInView(envelope); layer.DataSource.Close(); if (layer.CoordinateTransformation != null) { for (int i = 0; i < geoms.Count; i++) { geoms[i] = GeometryTransform.TransformGeometry(geoms[i], layer.CoordinateTransformation.MathTransform); } } //Linestring outlines is drawn by drawing the layer once with a thicker line //before drawing the "inline" on top. if (layer.Style.EnableOutline) { foreach (SharpMap.Geometries.Geometry geom in geoms) { if (geom != null) { //Draw background of all line-outlines first switch (geom.GetType().FullName) { case "SharpMap.Geometries.LineString": SharpMap.Rendering.VectorRenderer.DrawLineString(g, geom as LineString, layer.Style.Outline, map); break; case "SharpMap.Geometries.MultiLineString": SharpMap.Rendering.VectorRenderer.DrawMultiLineString(g, geom as MultiLineString, layer.Style.Outline, map); break; default: break; } } } } for (int i = 0; i < geoms.Count; i++) { if (geoms[i] != null) { RenderGeometry(g, map, layer.ClippingEnabled, geoms[i], layer.Style); } } } //base.Render(g, map); }
public static void PaintUsingSystemDrawing(GdiGraphics graphics, string text, GdiRectangle clientRectangle) { graphics.Clear(GdiColor.CornflowerBlue); using (var brush = new GdiSolidBrush(GdiColor.Black)) using (var format = new GdiStringFormat()) { format.Alignment = GdiStringAlignment.Center; format.LineAlignment = GdiStringAlignment.Center; graphics.DrawString(text, GdiSystemFonts.MessageBoxFont, brush, clientRectangle, format); } }
public void RenderLayer(ILayer layer, Map map, System.Drawing.Graphics g) { RenderLayer((IVectorLayer)layer, map, g); }
public void Preview(Surface surface, SGraphics g) { surface.DrawImage(g, resourceTemplate.Bitmap, surface.GetBrushLocation(), false, null); }
public void pictureResulting_Paint(Object sender, PaintEventArgs e) { // 背景を描画 int raw_width = pictureResulting.Width; int raw_height = pictureResulting.Height; System.Drawing.Graphics g = e.Graphics; g.FillRectangle(System.Drawing.Brushes.LightGray, 0, 0, raw_width, raw_height); // 選択中のハンドルを取得 VibratoHandle handle = mSelected; if (handle == null) { return; } // 描画の準備 LineGraphDrawer d = getDrawerResulting(); d.setGraphics(g); // ビブラートのピッチベンドを取得するイテレータを取得 int width = raw_width; int vib_length = 960; int tempo = 500000; double vib_seconds = tempo * 1e-6 / 480.0 * vib_length; // 480クロックは0.5秒 VsqFileEx vsq = new VsqFileEx("Miku", 1, 4, 4, tempo); VibratoBPList list_rate = handle.getRateBP(); VibratoBPList list_depth = handle.getDepthBP(); int start_rate = handle.getStartRate(); int start_depth = handle.getStartDepth(); if (list_rate == null) { list_rate = new VibratoBPList(new float[] { 0.0f }, new int[] { start_rate }); } if (list_depth == null) { list_depth = new VibratoBPList(new float[] { 0.0f }, new int[] { start_depth }); } // 解像度 float resol = (float)(vib_seconds / width); if (resol <= 0.0f) { return; } VibratoPointIteratorBySec itr = new VibratoPointIteratorBySec( vsq, list_rate, start_rate, list_depth, start_depth, 0, vib_length, resol); // 描画 int height = raw_height - MARGIN * 2; d.clear(); //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; int x = 0; int lastx = 0; int lasty = -10; int tx = 0, ty = 0; for (; itr.hasNext(); x++) { double pitch = itr.next().getY(); int y = height - (int)((pitch + 1.25) / 2.5 * height) + MARGIN - 1; int dx = x - lastx; // xは単調増加 int dy = Math.Abs(y - lasty); tx = x; ty = y; //if ( dx > MIN_DELTA || dy > MIN_DELTA ) { d.append(x, y); lastx = x; lasty = y; //} } d.append(tx, ty); d.flush(); }
/// <summary> /// Resizes an image (down) or returns the original if no resize is needed. /// </summary> /// <param name="contents">The image stream to resize.</param> /// <param name="size">The desired size of the image (highest value between height and width).</param> /// <param name="resizefactor">The factor to use for sizing down the image. Only used if size is 0.</param> /// <param name="quality">The quality of the resized image, between 1 and 100.</param> /// <returns></returns> public static Stream ResizeImage(Stream contents, int size, decimal resizefactor, long quality) { Stream output; if (resizefactor <= 0 || resizefactor > 100) { resizefactor = 100; } decimal coefficient = resizefactor / 100; if (size <= 0 && (coefficient > 1 || coefficient < 0)) // cannot scale up or to a negative value, return original { return(contents); } using (System.Drawing.Image original = System.Drawing.Image.FromStream(contents)) { //calculate new width and height based on size or coefficient int width, height; if (original.Height > original.Width) { if (size <= 0) { size = (int)(original.Height * coefficient); } height = size; width = (int)(original.Width * ((float)size / (float)original.Height)); } else { if (size <= 0) { size = (int)(original.Width * coefficient); } width = size; height = (int)(original.Height * ((float)size / (float)original.Width)); } using (System.Drawing.Bitmap resized = new System.Drawing.Bitmap(width, height, original.PixelFormat)) { resized.SetResolution(original.HorizontalResolution, original.VerticalResolution); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(resized)) { graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.DrawImage(original, new System.Drawing.Rectangle(0, 0, width, height), 0, 0, original.Width, original.Height, System.Drawing.GraphicsUnit.Pixel); } #region codec info //if (contentType == "image/gif") //{ // using (thumbnail) // { // OctreeQuantizer quantizer = new OctreeQuantizer(255, 8); // using (Bitmap quantized = quantizer.Quantize(bitmap)) // { // Response.ContentType = "image/gif"; // quantized.Save(Response.OutputStream, ImageFormat.Gif); // } // } //} //if (contentType == "image/jpeg") //{ // var info = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders(); // EncoderParameters encoderParameters; // encoderParameters = new EncoderParameters(1); // encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L); // Response.ContentType = "image/jpeg"; // thumbnail.Save(Response.OutputStream, info[1], encoderParameters); //} #endregion //encode the image ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg); Encoder myEncoder = Encoder.Quality; EncoderParameters myEncoderParameters = new EncoderParameters(1); EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, quality); myEncoderParameters.Param[0] = myEncoderParameter; //save it to server output = new MemoryStream(); resized.Save(output, jgpEncoder, myEncoderParameters); } } return(output); }
/// <summary> /// 生成缩略图 /// </summary> /// <param name="originalImagePath">源图路径(物理路径)</param> /// <param name="thumbnailPath">缩略图路径(物理路径)</param> /// <param name="width">缩略图宽度</param> /// <param name="height">缩略图高度</param> /// <param name="mode">生成缩略图的方式</param> public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode) { using (System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath)) { int towidth = width; int toheight = height; int x = 0; int y = 0; int ow = originalImage.Width; int oh = originalImage.Height; if (originalImage.Width <= width && originalImage.Height <= height && mode.ToUpper() != "CUT" && mode.ToUpper() != "CUTA") { File.Copy(originalImagePath, thumbnailPath, true); return; } switch (mode.ToUpper()) { case "HW": //指定高宽缩放(可能变形) break; case "W": //指定宽,高按比例 toheight = originalImage.Height * width / originalImage.Width; break; case "H": //指定高,宽按比例 towidth = originalImage.Width * height / originalImage.Height; break; case "CUTA": //指定高宽裁减(不变形) if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight) { oh = originalImage.Height; ow = originalImage.Height * towidth / toheight; y = 0; x = (originalImage.Width - ow) / 2; } else { ow = originalImage.Width; oh = originalImage.Width * height / towidth; x = 0; y = (originalImage.Height - oh) / 2; } break; case "CUT": //指定高宽裁减(不变形)自定义 //if (ow <= towidth && oh <= toheight) //{ // x = -(towidth - ow) / 2; // y = -(toheight - oh) / 2; // ow = towidth; // oh = toheight; //} //else //{ if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight) { ow = originalImage.Width; oh = originalImage.Width * height / towidth; x = 0; y = (originalImage.Height - oh) / 2; } else { oh = originalImage.Height; ow = originalImage.Height * towidth / toheight; y = 0; x = (originalImage.Width - ow) / 2; } //if (ow > oh)//宽大于高 //{ // x = 0; // y = -(ow - oh) / 2; // oh = ow; //} //else//高大于宽 //{ // y = 0; // x = -(oh - ow) / 2; // ow = oh; //} //} break; case "CUT1": if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight) { toheight = originalImage.Height * width / originalImage.Width; } else { towidth = originalImage.Width * height / originalImage.Height; } break; default: break; } //新建一个bmp图片 System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight); //新建一个画板 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; //设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //清空画布并以透明背景色填充 //g.Clear(System.Drawing.Color.Transparent); g.Clear(System.Drawing.Color.White); //在指定位置并且按指定大小绘制原图片的指定部分 g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel); try { //string fileExtension = Path.GetExtension(originalImagePath).ToLower(); //switch (fileExtension) //{ // case ".jpg": // //以jpg格式保存缩略图 // bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg); break; // case ".jpeg": // //以jpg格式保存缩略图 // bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg); break; // case ".gif": // //以jpg格式保存缩略图 // bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Gif); break; // case ".png": // bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Png); break; //} //以jpg格式保存缩略图 //bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg); ImageCodecInfo ici; System.Drawing.Imaging.Encoder enc; EncoderParameter ep; EncoderParameters epa; // Initialize the necessary objects ici = GetEncoderInfo("image/jpeg"); enc = System.Drawing.Imaging.Encoder.Quality;//设置保存质量 epa = new EncoderParameters(1); // Set the compression level ep = new EncoderParameter(enc, 90L);//质量等级为90% epa.Param[0] = ep; bitmap.Save(thumbnailPath, ici, epa); } catch (System.Exception e) { throw e; } finally { originalImage.Dispose(); bitmap.Dispose(); g.Dispose(); } } }
public Graphics( System.Drawing.Graphics g ) { nativeGraphics = g; }
public virtual void Draw(Graphics g) { var rect = BoundingRectangle; var annLabel = ShowLabel ? ann.Label : ""; var labelSize = g.MeasureString(annLabel, drawingFont); g.DrawString(annLabel, drawingFont, new System.Drawing.SolidBrush(DefaultPen.Color), new System.Drawing.PointF { X = rect.X, Y = rect.Y - labelSize.Height - 5 }); }
public abstract bool GdiDrawString( System.Drawing.Graphics pGraphics, LOGFONT pLogFont, string pszText, System.Drawing.Rectangle rtDraw);
public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // Prepare the Graphics elements for the drawing // picture1Graphics = picture1.CreateGraphics(); Color = new System.Drawing.Color(); BlackPen = new System.Drawing.Pen(Color.Black,1); }
public void Draw(System.Drawing.Graphics g) { g.DrawEllipse(System.Drawing.Pens.Black, X1, Y1, Width, Height); }
internal void NextPage(PlatformGraphics pg) { this.hasMorePages = false; var sheet = this.CurrentWorksheet; if (sheet == null) { return; } // out of print areas if (this.CurrentRowIndex >= sheet.pageBreakRows.Count && this.CurrentColIndex >= sheet.pageBreakCols.Count) { return; } int row = sheet.pageBreakRows[this.CurrentRowIndex]; int col = sheet.pageBreakCols[this.CurrentColIndex]; int endRow = sheet.pageBreakRows[this.CurrentRowIndex + 1]; int endCol = sheet.pageBreakCols[this.CurrentColIndex + 1]; switch (this.CurrentPrintSettings.PageOrder) { default: case PrintPageOrder.DownThenOver: { if (this.CurrentRowIndex < sheet.pageBreakRows.Count - 2) { this.CurrentRowIndex++; this.hasMorePages = true; } else { if (this.CurrentColIndex < sheet.pageBreakCols.Count - 2) { this.CurrentRowIndex = 0; this.CurrentColIndex++; this.hasMorePages = true; } else { this.hasMorePages = false; } } } break; case PrintPageOrder.OverThenDown: { if (this.CurrentColIndex < sheet.pageBreakCols.Count - 2) { this.CurrentColIndex++; this.hasMorePages = true; } else { if (this.CurrentRowIndex < sheet.pageBreakRows.Count - 2) { this.CurrentColIndex = 0; this.CurrentRowIndex++; this.hasMorePages = true; } else { this.hasMorePages = false; } } } break; } if (this.DrawingContext.Graphics == null) { this.DrawingContext.Graphics = new unvell.ReoGrid.WinForm.GDIRenderer(pg); } else { this.DrawingContext.Graphics.Reset(); } var ig = this.DrawingContext.Renderer; ig.PlatformGraphics = pg; #if DEBUG Debug.WriteLine(string.Format("print page {0,3},{1,3} - {2,3},{3,3}", row, col, endRow, endCol)); #endif // DEBUG GridRegion gr = new GridRegion(row, col, endRow, endCol); if (this.printViewportController == null) { this.printViewportController = new ViewportController(sheet); } else { this.printViewportController.worksheet = sheet; } this.PrintViewport = new SheetViewport(this.printViewportController); this.PrintViewport.Bounds = this.CurrentPaperBounds; // refresh cells text boundary sheet.IterateCells(gr.ToRange(), (_unused_r, _unused_c, cell) => { sheet.UpdateCellTextBounds(ig, cell, DrawMode.Print, this.CurrentPrintSettings.PageScaling, Core.UpdateFontReason.ScaleChanged); return(true); }); this.PrintViewport.VisibleRegion = gr; this.PrintViewport.ScaleFactor = this.CurrentPrintSettings.PageScaling; this.PrintViewport.ViewStart = new Point(sheet.cols[col].Left, sheet.rows[row].Top); this.PrintViewport.UpdateView(); this.PrintViewport.Draw(this.DrawingContext); if (this.CurrentPrintSettings.ShowMargins) { var m = this.CurrentPaperBounds; var p = this.DrawingContext.Renderer.GetPen(SolidColor.Gray); lock (p) { ig.DrawLine(p, m.X - 50, m.Y, m.X, m.Y); ig.DrawLine(p, m.Right + 50, m.Y, m.Right, m.Y); ig.DrawLine(p, m.X - 50, m.Bottom, m.X, m.Bottom); ig.DrawLine(p, m.Right + 50, m.Bottom, m.Right, m.Bottom); ig.DrawLine(p, m.X, m.Y - 50, m.X, m.Y); ig.DrawLine(p, m.X, m.Bottom + 50, m.X, m.Bottom); ig.DrawLine(p, m.Right, m.Y - 50, m.Right, m.Y); ig.DrawLine(p, m.Right, m.Bottom + 50, m.Right, m.Bottom); } } if (!this.hasMorePages) { this.NextWorksheet(); this.hasMorePages = this.CurrentWorksheet != null; } }