private void _imageViewer_PostRender(object sender, ImageViewerRenderEventArgs e) { RasterImage image = _imageViewer.Image; if (image == null || _overlayRect.IsEmpty) { // No image or the overlay rectangle hasn't been set yet return; } // Convert the overlay rectangle (it is in image coordinates) to viewer coordinates LeadRect imageRect = LeadRect.Create(_overlayRect.X, _overlayRect.Y, _overlayRect.Width, _overlayRect.Height); // We must pass false for 'accountForViewPerspective' in this case because _overlayRect is always // in top-left coordinates in this demo LeadRect viewerRect = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, imageRect); if (!viewerRect.IsEmpty) { // Otherwise, we zoomed out too much and it is too small to paint Graphics g = e.PaintEventArgs.Graphics; using (Brush brush = new SolidBrush(Color.FromArgb(128, Color.Black))) { Rectangle rect = Rectangle.FromLTRB(viewerRect.Left, viewerRect.Top, viewerRect.Right, viewerRect.Bottom); g.FillRectangle(brush, rect); g.DrawRectangle(Pens.Yellow, viewerRect.X, viewerRect.Y, viewerRect.Width - 1, viewerRect.Height - 1); } } }
private void Form1_Paint(object sender, PaintEventArgs e) { if (_lmvMyCallback != null && _lmvMyCallback.Image != null) { LeadRect destRect = LeadRect.Create(0, 0, this.ClientSize.Width, this.ClientSize.Height); using (RasterImage destImage = new RasterImage(RasterMemoryFlags.Conventional, this.ClientSize.Width, this.ClientSize.Height, _lmvMyCallback.Image.BitsPerPixel, _lmvMyCallback.Image.Order, _lmvMyCallback.Image.ViewPerspective, _lmvMyCallback.Image.GetPalette(), IntPtr.Zero, 0)) { // Resize the source image into the destination image ResizeCommand command = new ResizeCommand(); command.DestinationImage = destImage; command.Flags = RasterSizeFlags.Bicubic; command.Run(_lmvMyCallback.Image); destRect = RasterImage.CalculatePaintModeRectangle(destImage.ImageWidth, destImage.ImageHeight, destRect, RasterPaintSizeMode.FitAlways, RasterPaintAlignMode.Center, RasterPaintAlignMode.Center); LeadRect destClipRect = LeadRect.Create(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height); using (RasterGraphics rg = RasterImagePainter.CreateGraphics(destImage)) { rg.Graphics.DrawRectangle(new Pen(Color.Red), _lmvMyCallback.GuideRect.X, _lmvMyCallback.GuideRect.Y, _lmvMyCallback.GuideRect.Width, _lmvMyCallback.GuideRect.Height); } RasterImagePainter.Paint(destImage, e.Graphics, LeadRect.Empty, LeadRect.Empty, destRect, destClipRect, RasterPaintProperties.Default); } } }
public Stream GetImageTile(string authenticationCookie, string sopInstanceUID, int frame, int x, int y, int width, int height, int xResolution, int yResolution, Boolean wldata, string userData) { ServiceUtils.Authorize(authenticationCookie, PermissionsTable.Instance.CanRetrieve); LeadRect tile = LeadRect.Create(x, y, width, height); string mime; var stream = AddinsFactory.CreateObjectRetrieveAddin().GetImageTile(sopInstanceUID, frame, tile, xResolution, yResolution, wldata, userData, out mime); WebOperationContext.Current.OutgoingResponse.ContentType = mime; return(stream); }
public Task <Tuple <Stream, string> > GetImageTile(string authenticationCookie, string sopInstanceUID, int frame, int x, int y, int width, int height, int xResolution, int yResolution, Boolean wldata, string userData) { AuthHandler.Authorize(authenticationCookie, PermissionsTable.Instance.CanRetrieve); return(Task.Factory.StartNew <Tuple <Stream, string> >(() => { LeadRect tile = LeadRect.Create(x, y, width, height); string mime; var stream = _ret.Value.GetImageTile(sopInstanceUID, frame, tile, xResolution, yResolution, wldata, userData, out mime); return new Tuple <Stream, string>(stream, mime); })); }
private void ApplyEncryptDecrypt(ScrambleCommandFlags flags, LeadRectD bounds, int key) { LeadRect boundsInImage = _image.RectangleToImage(RasterViewPerspective.TopLeft, bounds.ToLeadRect()); LeadRect imageRect = LeadRect.Create(0, 0, _image.ImageWidth, _image.ImageHeight); flags |= ScrambleCommandFlags.Intersect; ScrambleCommand scrambleCommand = new ScrambleCommand(boundsInImage, key, flags); if (imageRect.Contains(boundsInImage)) { scrambleCommand.Run(_image); } }
private void _printDocument_PrintPage(object sender, PrintPageEventArgs e) { // Get the print document object PrintDocument document = sender as PrintDocument; SvgDocument svgDoc = _viewer.DocumentList[_currentPrintPageNumber - 1].Document; var svgResolution = svgDoc.Bounds.Resolution; var svgBounds = svgDoc.Bounds.Bounds; // Get page size in pixels var pixelSize = LeadSizeD.Create(svgBounds.Width, svgBounds.Height); using (Bitmap bitmap = new Bitmap((int)pixelSize.Width, (int)pixelSize.Height, PixelFormat.Format32bppPArgb)) { // Convert to DPI var size = LeadSizeD.Create(pixelSize.Width * bitmap.HorizontalResolution / svgResolution.Width, pixelSize.Height * bitmap.VerticalResolution / svgResolution.Height).ToLeadSize(); // Fit in the margin bounds var destRect = LeadRect.Create(e.MarginBounds.X, e.MarginBounds.Y, e.MarginBounds.Width, e.MarginBounds.Height); destRect = RasterImage.CalculatePaintModeRectangle( size.Width, size.Height, destRect, RasterPaintSizeMode.Fit, RasterPaintAlignMode.Center, RasterPaintAlignMode.Center); using (Graphics g = Graphics.FromImage(bitmap)) { using (var engine = RenderingEngineFactory.Create(g)) { var options = new SvgRenderOptions(); options.Bounds = svgBounds; svgDoc.Render(engine, options); } } e.Graphics.DrawImage(bitmap, destRect.X, destRect.Y, destRect.Width, destRect.Height); } // Go to the next page _currentPrintPageNumber++; // Inform the printer whether we have more pages to print if (_currentPrintPageNumber <= document.PrinterSettings.ToPage) { e.HasMorePages = true; } else { e.HasMorePages = false; } }
private void ApplyEncryptDecrypt(ScrambleCommandFlags flags, LeadRectD bounds, int key) { LeadRect rect = bounds.ToLeadRect(); LeadRect imageRect = LeadRect.Create(0, 0, _image.ImageWidth, _image.ImageHeight); flags |= ScrambleCommandFlags.Intersect; ScrambleCommand scrambleCommand = new ScrambleCommand(rect, key, flags); if (imageRect.Contains(rect)) { scrambleCommand.Run(_image); } }
void RectInteractiveMode_RubberBandCompleted(object sender, ImageViewerRubberBandEventArgs e) { string actionName = null; if (InteractiveMode == ViewerControlInteractiveMode.ReadBarcodeMode) { actionName = "ReadBarcode"; } else if (InteractiveMode == ViewerControlInteractiveMode.WriteBarcodeMode) { actionName = "WriteBarcode"; } if (actionName != null) { LeadRect MyRect = LeadRect.Create(e.InteractiveEventArgs.Origin.X, e.InteractiveEventArgs.Origin.Y, e.InteractiveEventArgs.Position.X - e.InteractiveEventArgs.Origin.X, e.InteractiveEventArgs.Position.Y - e.InteractiveEventArgs.Origin.Y); Rectangle pixels = new Rectangle((int)MyRect.X, (int)MyRect.Y, (int)MyRect.Width, (int)MyRect.Height); if (pixels.Left > pixels.Right) { pixels = Rectangle.FromLTRB(pixels.Right, pixels.Top, pixels.Left, pixels.Bottom); } if (pixels.Top > pixels.Bottom) { pixels = Rectangle.FromLTRB(pixels.Left, pixels.Bottom, pixels.Right, pixels.Top); } if (pixels.Width > 2 && pixels.Height > 2) { RectangleF pixelsF = pixels; using (Matrix m = GetMatrixFromLeadMatrix(_rasterImageViewer.GetImageTransformWithDpi(true))) { Transformer trans = new Transformer(m); pixelsF = trans.RectangleToLogical(pixelsF); } pixelsF = RectangleF.Intersect(new RectangleF(0, 0, _rasterImageViewer.Image.ImageWidth, _rasterImageViewer.Image.ImageHeight), pixelsF); pixels = Rectangle.Round(pixelsF); LeadRect bounds = new LeadRect(pixels.X, pixels.Y, pixels.Width, pixels.Height); BeginInvoke(new DoActionDelegate(DoAction), new object[] { actionName, bounds }); } } }
private RasterImage AddTextFooter(RasterImage image, string tag, int footerMaxHeight) { LeadRect bounds = LeadRect.Create(0, 0, image.Width, image.Height); using (var imageTag = CreateTextFooter(LeadSize.Create(bounds.Width, footerMaxHeight), tag)) { bounds.Height += imageTag.Height; var bpp = 24; var byteOrder = RasterByteOrder.Bgr; var viewPerspective = RasterViewPerspective.TopLeft; if (image.ViewPerspective != viewPerspective) { image.ChangeViewPerspective(viewPerspective); } if (image.BitsPerPixel != bpp || image.Order != byteOrder) { var colorResCommand = new ColorResolutionCommand( ColorResolutionCommandMode.InPlace, bpp, byteOrder, RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null); colorResCommand.Run(image); } RasterImage imageResult = new RasterImage(RasterMemoryFlags.Conventional, bounds.Width, bounds.Height, bpp, byteOrder, viewPerspective, null, null, 0); { var combine = new CombineFastCommand(imageResult, bounds, LeadPoint.Create(0, 0), CombineFastCommandFlags.SourceCopy); combine.Run(image); } { var combine = new CombineFastCommand(imageResult, LeadRect.Create(bounds.X, image.Height, bounds.Width, bounds.Height - image.Height), LeadPoint.Create(0, 0), CombineFastCommandFlags.SourceCopy); combine.Run(imageTag); } return(imageResult); } }
private void _imageViewer_MouseDown(object sender, MouseEventArgs e) { RasterImage image = _imageViewer.Image; if (image == null || rubberBandMode.IsEnabled) { // Nothing for us to do return; } if (_isMovingOverlayRect) { // Previously moving the rectangle, end the move operation EndMovingOverlayRect(); } if (!_overlayRect.IsEmpty && e.Button == MouseButtons.Left) { // Check if we are on the overlay rect. Get current mouse position // in image coordinates. Using TopLeft since the overlay rect is in // TopLeft always LeadPoint viewerPoint = LeadPoint.Create(e.X, e.Y); LeadPoint imagePoint = _imageViewer.ConvertPoint(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, viewerPoint); if (_overlayRect.Contains(imagePoint.X, imagePoint.Y)) { // Yes, start moving _lastMovePoint = viewerPoint; _isMovingOverlayRect = true; // Optional: clip the cursor to not move outside the image bounds LeadRect imageRect = LeadRect.Create(0, 0, image.ImageWidth, image.ImageHeight); LeadRect viewerRect = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, imageRect); // Note, the above returns the same value as _rasterImageViewer.PhysicalViewRectangle Rectangle clipRect = Rectangle.Intersect(Rectangle.FromLTRB(viewerRect.Left, viewerRect.Top, viewerRect.Right, viewerRect.Bottom), _imageViewer.ClientRectangle); Cursor.Clip = _imageViewer.RectangleToScreen(clipRect); _imageViewer.Capture = true; } } }
private void _imageViewer_MouseMove(object sender, MouseEventArgs e) { RasterImage image = _imageViewer.Image; if (image == null) { return; } // Here is the point in viewer (physical or client) coordinates // This point is the mouse position LeadPoint viewerPoint = LeadPoint.Create(e.X, e.Y); // Convert to image coordinates (top-left view perspective, since we are // only interested in the zoom/scroll values and not trying to get to a // certain pixel in the image data) LeadPoint imagePoint = _imageViewer.ConvertPoint(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, viewerPoint); ShowMousePositionAndImageColor(image, viewerPoint, imagePoint); if (_isMovingOverlayRect) { // We are moving the overlay rect // After we are done with moving the overlay rect to a new position, // we need to re-paint to show the effect. To optimize the code, we will // only repaint the combination of the old and new rects // Get the current (soon to be old) overlay rect in viewer coordinates LeadRect oldImageRect = LeadRect.Create(_overlayRect.X, _overlayRect.Y, _overlayRect.Width, _overlayRect.Height); LeadRect oldViewerRect = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, oldImageRect); // Get the difference int dx = e.X - _lastMovePoint.X; int dy = e.Y - _lastMovePoint.Y; if (dx != 0 || dy != 0) { // Has moved LeadRect newViewerRect = oldViewerRect; newViewerRect.Offset(dx, dy); // Now re-calculate new overlay rectangle in image coordinates LeadRect newImageRect = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, newViewerRect); // Make sure the image rectangle does not go outside the image boundaries if (newImageRect.X < 0) { newImageRect.Offset(-newImageRect.X, 0); } if (newImageRect.Y < 0) { newImageRect.Offset(0, -newImageRect.Y); } if ((newImageRect.X + newImageRect.Width) > image.ImageWidth) { newImageRect.Offset(-(newImageRect.X + newImageRect.Width - image.ImageWidth), 0); } if ((newImageRect.Y + newImageRect.Height) > image.ImageHeight) { newImageRect.Offset(0, -(newImageRect.Y + newImageRect.Height - image.ImageHeight)); } // Check if it has really changed if (newImageRect.X != oldImageRect.X || newImageRect.Y != oldImageRect.Y || newImageRect.Width != oldImageRect.Width || newImageRect.Height != oldImageRect.Height) { // Yes _overlayRect = new LeadRect(newImageRect.X, newImageRect.Y, newImageRect.Width, newImageRect.Height); _imageViewer.Invalidate(); } // Save the new moving position _lastMovePoint = LeadPoint.Create(e.X, e.Y); } } }
void _viewer_PostRender(object sender, ImageViewerRenderEventArgs args) { LeadPoint firstPoint = _viewer.ConvertPoint(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadPoint.Create(_xStart, _yStart)); LeadPoint endPoint = _viewer.ConvertPoint(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadPoint.Create(_xEnd, _yEnd)); float[] dashValuesWhite = { 4, 4, 4, 4 }; Pen penBlack = new Pen(Color.Black, 1); Pen penWhite = new Pen(Color.White, 1); PaintEventArgs e = args.PaintEventArgs; penWhite.DashPattern = dashValuesWhite; e.Graphics.DrawLine(penBlack, firstPoint.X, firstPoint.Y, endPoint.X, endPoint.Y); e.Graphics.DrawLine(penWhite, firstPoint.X, firstPoint.Y, endPoint.X, endPoint.Y); LeadRect startRect = _viewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadRect.Create(_startRect.X, _startRect.Y, _startRect.Width, _startRect.Height)); LeadRect endRect = _viewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadRect.Create(_endRect.X, _endRect.Y, _endRect.Width, _endRect.Height)); if (_cbMovable.Checked) { e.Graphics.DrawRectangle(penBlack, startRect.X, startRect.Y, startRect.Width, startRect.Height); e.Graphics.DrawRectangle(penWhite, startRect.X, startRect.Y, startRect.Width, startRect.Height); e.Graphics.DrawRectangle(penBlack, endRect.X, endRect.Y, endRect.Width, endRect.Height); e.Graphics.DrawRectangle(penWhite, endRect.X, endRect.Y, endRect.Width, endRect.Height); } }