private void LoadFile(RasterCodecs codec) { if (fileName == null || "".Equals(fileName)) { _image = null; return; } CodecsTiffLoadOptions options = codec.Options.Tiff.Load; /* codec.Options.Load.Compressed = true; */ // codec.Options.Load.XResolution = 204; // codec.Options.Load.YResolution = 196; // CodecsImageInfo info = codec.GetInformation(fileName, true); int firstPage = 1; int lastPage = info.TotalPages; _image = codec.Load(fileName, 0, CodecsLoadByteOrder.BgrOrGray, firstPage, lastPage); //codec.Options.Load. }
private void LoadStream(RasterCodecs codec) { if (stream == null ) { _image = null; return; } CodecsTiffLoadOptions options = codec.Options.Tiff.Load; /* codec.Options.Load.Compressed = true; */ // codec.Options.Load.XResolution = 204; // codec.Options.Load.YResolution = 196; // CodecsImageInfo info = codec.GetInformation(stream, true); int firstPage = 1; int lastPage = info.TotalPages; _image = codec.Load(stream, 0, CodecsLoadByteOrder.BgrOrGray, firstPage, lastPage); }
private void LoadImageList() { if (fileName == null || "".Equals(fileName)) { return; } if (!File.Exists(fileName)) { throw new FileNotFoundException(); } RasterCodecs codec = new RasterCodecs(); CodecsImageInfo info = codec.GetInformation(fileName,true); RasterPaintProperties paintProp = imageList.PaintProperties; paintProp.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray; int lastPage = info.TotalPages; image =codec.Load(fileName,0,CodecsLoadByteOrder.BgrOrGray,1,lastPage); imageList.Items.Clear(); int totalCount = image.PageCount; for (int i = 1; i <= totalCount; ++i) { RasterImageListItem imageItem = new RasterImageListItem(image, i, "Page " + i.ToString()); imageList.Items.Add(imageItem); } LoadCheckBox(totalCount); }
public static RasterImage Tranform(this RasterImage originalImage, Transform transformProperties) { var image = originalImage.Clone(); Transform(transformProperties, image); return(image); }
private void OpenImage(RasterImage image) { Cursor = Cursors.WaitCursor; EnableControls(false); ProcessImage(image); _btnFit_Click(null, null); Cursor = Cursors.Arrow; }
public SeriesImage(string seriesInstanceUID, string sopInstanceUID, RasterImage image, double xDpi, double yDpi) { SeriesInstanceUID = seriesInstanceUID; SOPInstanceUID = sopInstanceUID; Image = image; XDpi = xDpi; YDpi = yDpi; }
public static MemoryStream ToStream(this RasterImage image, RasterImageFormat format, int compression) { MemoryStream fileStream = new MemoryStream(); _Codecs.Options.Jpeg.Save.QualityFactor = compression; _Codecs.Save(image, fileStream, format, 0); return(fileStream); }
internal override void RenderTo(RasterImage img) { // note to self each lay can be draw on the previous layer with an image brush for masking and compositing foreach (var c in Children) { c.RenderTo(img); } }
public MasterForm() { _image = null; _attributes = new FormRecognitionAttributes(); _properties = FormRecognitionProperties.Empty; _processingPages = null; _isDirty = false; }
private void MasterFormsWizard_FormClosing(object sender, FormClosingEventArgs e) { if (scannedImage != null) { scannedImage.Dispose(); scannedImage = null; } }
public ImpressionistDialog(RasterImage TempImage) { InitializeComponent(); _HorizontalSize = 1; _VerticalSize = 1; _RasImage = TempImage; InitializeUI(); }
private void _cmbREFImage_SelectedIndexChanged(object sender, EventArgs e) { _REFImage = _images[_cmbREFImage.SelectedIndex]; _REFViewer.Image = _REFImage; _REFViewer.OffsetImage(_DSTViewer.Offset); _REFViewer.Invalidate(); UpdateValues(); }
private void ShowBookmarksDialog(TreeNode node) { RasterImage page = (RasterImage)_rasterImageList.Items.GetSelected()[0].Tag; _insertBookmaksForm = new InsertBookmarkForm(node, _rasterImageList.Items.Count, CurrentPageNumber - 1, page.Width, page.Height); _insertBookmaksForm.Action += new EventHandler <ActionEventArgs>(_insertBookmaksForm_Action); _insertBookmaksForm.Show(this); }
public static Control CreateControl(string zoomPolicy, Font font, Size layoutSize) { switch (zoomPolicy) { case "RasterImageListZoomPolicy": RasterImageList imageList1 = new RasterImageList(); imageList1.Dock = DockStyle.Fill; using (RasterCodecs codecs = new RasterCodecs()) { MemoryStream stream1 = new MemoryStream(); Properties.Resources.Accnt.Save(stream1, ImageFormat.Png); stream1.Position = 0; RasterImage image1 = codecs.Load(stream1); stream1.Close(); stream1 = new MemoryStream(); Properties.Resources.Bill.Save(stream1, ImageFormat.Png); stream1.Position = 0; RasterImage image2 = codecs.Load(stream1); stream1.Close(); stream1 = new MemoryStream(); Properties.Resources.Check.Save(stream1, ImageFormat.Png); stream1.Position = 0; RasterImage image3 = codecs.Load(stream1); stream1.Close(); stream1 = new MemoryStream(); Properties.Resources.Cust.Save(stream1, ImageFormat.Png); stream1.Position = 0; RasterImage image4 = codecs.Load(stream1); stream1.Close(); imageList1.Items.Add(new RasterImageListItem(image1, 1, "aaa")); imageList1.Items.Add(new RasterImageListItem(image2, 1, "bbb")); imageList1.Items.Add(new RasterImageListItem(image3, 1, "ccc")); imageList1.Items.Add(new RasterImageListItem(image4, 1, "ddd")); } return(imageList1); case "RasterImageViewerZoomPolicy": RasterImageViewer imageViewer1 = new RasterImageViewer(); imageViewer1.Dock = DockStyle.Fill; using (RasterCodecs codecs = new RasterCodecs()) { MemoryStream stream1 = new MemoryStream(); Properties.Resources.Forest.Save(stream1, ImageFormat.Png); stream1.Position = 0; RasterImage image1 = codecs.Load(stream1); stream1.Close(); imageViewer1.Image = image1; } return(imageViewer1); default: break; } return(null); }
private void AddPageToDest(RasterImage image) { RasterImageListItem item = new RasterImageListItem(); item.Image = image; // image.v image.FlipViewPerspective(true); destImageList.Items.Add(item); }
public static void Run() { //ExStart:ManualImageMasking // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); Console.WriteLine("Running example ManualImageMasking"); string sourceFileName = dataDir + "Colored by Faith_small.png"; string outputFileName = dataDir + "Colored by Faith_small_manual.png"; GraphicsPath manualMask = new GraphicsPath(); Figure firstFigure = new Figure(); firstFigure.AddShape(new EllipseShape(new RectangleF(100, 30, 40, 40))); firstFigure.AddShape(new RectangleShape(new RectangleF(10, 200, 50, 30))); manualMask.AddFigure(firstFigure); GraphicsPath subPath = new GraphicsPath(); Figure secondFigure = new Figure(); secondFigure.AddShape( new PolygonShape( new PointF[] { new PointF(310, 100), new PointF(350, 200), new PointF(250, 200) }, true)); secondFigure.AddShape(new PieShape(new RectangleF(10, 10, 80, 80), 30, 120)); subPath.AddFigure(secondFigure); manualMask.AddPath(subPath); using (RasterImage image = (RasterImage)Image.Load(sourceFileName)) { MaskingOptions maskingOptions = new MaskingOptions() { Method = SegmentationMethod.Manual, Args = new ManualMaskingArgs { Mask = manualMask }, Decompose = false, ExportOptions = new PngOptions() { ColorType = PngColorType .TruecolorWithAlpha, Source = new StreamSource( new MemoryStream()) }, }; MaskingResult[] maskingResults = new ImageMasking(image).Decompose(maskingOptions); using (Image resultImage = maskingResults[1].GetImage()) { resultImage.Save(outputFileName); } } Console.WriteLine("Finished example ManualImageMasking"); }
public ProcessingField(FormField processingBox, ProcessingFieldType type, RasterImage image, SolidBrush brush, Pen pen) { _type = type; _brush = brush; _pen = pen; _processingBox = processingBox; _ProcessingBoxRect = _processingBox.Bounds.ToRectangle(_dpiX, _dpiX); AdjustRectPoints(); }
// Update the form (RasterImage) attached to this master form public void WriteForm(RasterImage form) { if (form == null) { throw new ArgumentNullException("form"); } form.DitheringMethod = RasterDitheringMethod.None; _repository.RasterCodecsInstance.Save(form, _path + ".tif", RasterImageFormat.Tif, 1, 1, -1, 1, CodecsSavePageMode.Overwrite); }
public ProcessOmrDocumentsOperation(RasterImage answerKey, ITemplateForm template, IImageManager imageManager, Dictionary <string, string> images) { this.imageManager = imageManager; this.key = answerKey; this.toLoad = images; this._templateForm = template; }
private void _btnRetry_Click(object sender, EventArgs e) { RasterImage image = this.rasterImageViewer1.Image; if (image != null) { ProcessImage(image.Clone()); } }
public MasterForm(string name) { _image = null; _attributes = new FormRecognitionAttributes(); _properties = new FormRecognitionProperties(); _properties.Name = name; _processingPages = null; _isDirty = false; }
/// <summary> /// Called by the main form to set the new raster image and barcodes /// </summary> public void SetDocument(RasterImage image, DocumentBarcodes documentBarcodes) { _documentBarcodes = documentBarcodes; _rasterImageViewer.Image = image; UpdatePageInfo(); UpdateUIState(); }
public override void PrepareToSave(RasterCodecs codecs, RasterImage image, int bpp, int qf) { // Set the quality factor, we might use JPEG compression, so use the same QF as JPEG images codecs.Options.Jpeg.Save.QualityFactor = NormalizeQualityFactor(qf, 0, 9, 2); if (bpp != 0) { // User passed an explicit value, check if PDF supports it if (bpp == 1 || bpp == 4 || bpp == 8 || bpp == 24) { BitsPerPixel = bpp; // Yes } else { BitsPerPixel = 24; // No, default BPP } } else { // User did not pass a value, we need to figure it out from the image to produce an image that does not require more // size than the original keeping the quality the same. if (image.BitsPerPixel == 1) { BitsPerPixel = 1; } else if (image.BitsPerPixel <= 4) { BitsPerPixel = 4; } else if (image.BitsPerPixel <= 8) { BitsPerPixel = 8; } else { BitsPerPixel = 24; } } // For 1-bpp images, we will use FAX G4 compression inside the PDF // For 4 or 8-bpp, we will use LZW compression // For anything else (24-bpp), we will use JPEG 422 // These values produce the smallest size PDF while keeping the image quality high. if (BitsPerPixel == 1) { ImageFormat = RasterImageFormat.RasPdfG4; } else if (BitsPerPixel == 4 || BitsPerPixel == 8) { ImageFormat = RasterImageFormat.RasPdfLzw; } else { ImageFormat = RasterImageFormat.RasPdfJpeg422; } }
public bool Load(IWin32Window owner, RasterCodecs codecs, bool autoLoad) { _fileName = string.Empty; _image = null; StringBuilder sb = new StringBuilder(); for (int i = 0; i < LoadFormat.Entries.Length; i++) { sb.Append(LoadFormat.Entries[i].ToString()); if (i != (LoadFormat.Entries.Length - 1)) { sb.Append("|"); } } OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = sb.ToString(); ofd.FilterIndex = _filterIndex; bool ok = false; try { if (ofd.ShowDialog(owner) == DialogResult.OK) { _fileName = ofd.FileName; ok = true; _filterIndex = ofd.FilterIndex; CodecsImageInfo info; using (WaitCursor wait = new WaitCursor()) info = codecs.GetInformation(ofd.FileName, true); if (autoLoad && ok) { using (WaitCursor wait = new WaitCursor()) { _image = codecs.Load(ofd.FileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1); } } } else { ok = true; } } catch { MessageBox.Show("Failed to load image.\nPlease note that, you can't use this dialog to load a DICOM file as an image.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); ok = false; } return(ok); }
//public static byte[] CreateBarcode( string value, int resolution, int Width, int Height, bool Save2File,bool usingMemory, ref string ErrMsg) //{ // byte[] arrImg; // BarcodeEngine barEngine; // try // { // RasterImage theImage = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)); // // Unlock barcode support. // // Note that this is a sample key, which will not work in your toolkit // BarcodeEngine.Startup(BarcodeMajorTypeFlags.Barcodes1d); // BarcodeEngine.Startup(BarcodeMajorTypeFlags.BarcodesPdfWrite); // BarcodeEngine.Startup(BarcodeMajorTypeFlags.BarcodesDatamatrixWrite); // BarcodeEngine.Startup(BarcodeMajorTypeFlags.BarcodesQrWrite); // // Initialize barcodes // barEngine = new BarcodeEngine(); // BarcodeData data = new BarcodeData(); // LeadRect rc = new LeadRect(0, 0, Width, Height); // data.Unit = BarcodeUnit.ScanlinesPerPixels; // data.Location = rc; // data.SearchType = BarcodeSearchTypeFlags.DatamatrixDefault; // string[] barcodeText; // barcodeText = new string[1]; // barcodeText[0] = value; // data.Data = BarcodeData.ConvertFromStringArray(barcodeText); // BarcodeColor barColor = new BarcodeColor(); // barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black); // barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White); // Barcode1d bar1d = new Barcode1d(); // BarcodeWritePdf barPDF = new BarcodeWritePdf(); // BarcodeWriteDatamatrix barDM = new BarcodeWriteDatamatrix(); // bar1d.StandardFlags = Barcode1dStandardFlags.Barcode1dCode128EncodeA; // barDM.Justify = BarcodeJustifyFlags.Right; // barDM.FileIdHigh = 0; // barDM.FileIdLow = 0; // barDM.GroupNumber = 0; // barDM.GroupTotal = 0; // barDM.XModule = 0; // BarcodeWriteQr barQR = new BarcodeWriteQr(); // string barcodeFileName = AppDomain.CurrentDomain.BaseDirectory + @"\barcode.tif"; // barEngine.Write(theImage, data, barColor, BarcodeWriteFlags.UseColors | BarcodeWriteFlags.Transparent | BarcodeWriteFlags.DisableCompression, bar1d, barPDF, barDM, barQR, LeadRect.Empty); // if (usingMemory) // { // using (MemoryStream _stream = new MemoryStream()) // { // using (RasterCodecs _Codecs = new RasterCodecs()) // { // _Codecs.Save(theImage, _stream, RasterImageFormat.Tif, theImage.BitsPerPixel); // arrImg = _stream.ToArray(); // if (Save2File) // { // _Codecs.Save(theImage, barcodeFileName, RasterImageFormat.Tif, theImage.BitsPerPixel); // } // } // } // } // else // { // using (RasterCodecs _Codecs = new RasterCodecs()) // { // _Codecs.Save(theImage, barcodeFileName, RasterImageFormat.Tif, theImage.BitsPerPixel); // arrImg = System.IO.File.ReadAllBytes(barcodeFileName); // } // } // } // catch (Exception ex) // { // ErrMsg = ex.Message; // return null; // } // return arrImg; //} public static byte[] CreateBarcode(BarcodeSymbology _BarcodeSymbology, string value, int resolution, int Width, int Height, bool Save2File, bool usingMemory, ref string ErrMsg) { ErrMsg = ""; BarcodeEngine barcodeEngineInstance = new BarcodeEngine(); RasterImage theImage = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)); // Create a UPC A barcode BarcodeData data = new BarcodeData(); data.Symbology = _BarcodeSymbology; data.Value = value; data.Bounds = new LogicalRectangle(10, 10, Width, Height, LogicalUnit.Pixel); // Setup the options to enable error checking and show the text on the bottom of the barcode OneDBarcodeWriteOptions options = new OneDBarcodeWriteOptions(); options.EnableErrorCheck = true; options.TextPosition = BarcodeOutputTextPosition.None;// OneDBarcodeTextPosition.Default; byte[] arrImg; try { string barcodeFileName = AppDomain.CurrentDomain.BaseDirectory + @"\barcode.tif"; // Write the barcode barcodeEngineInstance.Writer.WriteBarcode(theImage, data, options); if (usingMemory) { using (MemoryStream _stream = new MemoryStream()) { using (RasterCodecs _Codecs = new RasterCodecs()) { _Codecs.Save(theImage, _stream, RasterImageFormat.Tif, theImage.BitsPerPixel); arrImg = _stream.ToArray(); if (Save2File) { _Codecs.Save(theImage, barcodeFileName, RasterImageFormat.Tif, theImage.BitsPerPixel); } } } } else { using (RasterCodecs _Codecs = new RasterCodecs()) { _Codecs.Save(theImage, barcodeFileName, RasterImageFormat.Tif, theImage.BitsPerPixel); arrImg = System.IO.File.ReadAllBytes(barcodeFileName); } } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); ErrMsg = ex.Message; return(null); } return(arrImg); }
public void CreateChildForm(RasterImage img, string caption) { ChildForm child = new ChildForm(); child.MdiParent = this; child.InsertImage(img, caption); child.Show(); EnableMenuItems(true); }
public LineHistogramDialog(ViewerForm form, ImageViewer viewer, bool isGray) { InitializeComponent(); _image = viewer.Image; _isGrayScale = isGray; _form = form; _viewer = viewer; _button = downButtonPosition.NONE; _viewer.PostRender += new EventHandler <ImageViewerRenderEventArgs>(_viewer_PostRender); }
public FilledForm() { _fileName = null; _name = null; _image = null; _attributes = null; _master = null; _result = null; _alignment = null; }
private static void ChangeImageResolution(RasterImage image, int resolution) { // Rescale the image to 300x300 DPI with Bicubic interpolation var newWidth = (image.Width / (double)image.XResolution) * resolution; var newHeight = (image.Height / (double)image.YResolution) * resolution; new SizeCommand((int)newWidth, (int)newHeight, RasterSizeFlags.Bicubic).Run(image); image.XResolution = resolution; image.YResolution = resolution; }
public LocalHistogramEqualizeDialog(RasterImage TempImage) { InitializeComponent(); _LocalHistogramEqualizeCommand = new LocalHistogramEqualizeCommand(); _MaxWidth = TempImage.Width; _MaxHeight = TempImage.Height; //Set command default values InitializeUI(); }
public void Dispose() { try { RasterImage.Dispose(); RasterImage = null; (ImageItem.Tag as IDisposable).Dispose(); } catch { } }
//in safari, when canvas is captured, that has transparency, it fills transparent areas with 255 not black //we force transparent areas to be black instead static void PreProcessBitmap(RasterImage derivedImage) { using (RasterImage alpha = derivedImage.CreateAlphaImage()) { alpha.AddColorRgbRangeToRegion(new RasterColor(0, 0, 0), new RasterColor(3, 3, 3), RasterRegionCombineMode.Set); derivedImage.SetRegion(null, alpha.GetRegion(null), RasterRegionCombineMode.Set); FillCommand fill = new FillCommand(new RasterColor(0, 0, 0)); fill.Run(derivedImage); } }
public MasterForm(string name, RasterImage image, FormRecognitionAttributes attr, FormRecognitionEngine engine) { _image = image; _attributes = attr; attr.Image = Image; _properties = engine.GetFormProperties(attr); _properties.Name = name; _processingPages = null; _isDirty = false; }
private void InitializeFromStream(Stream stream) { codec = new RasterCodecs(); codec.Options.Txt.Load.Enabled = true; CodecsImageInfo info = codec.GetInformation(stream, true); int lastPage = info.TotalPages; ImageData = codec.Load(stream, 0, CodecsLoadByteOrder.BgrOrGray, 1, lastPage); codec.Options.Load.XResolution = ImageData.XResolution; codec.Options.Load.YResolution = ImageData.YResolution; LoadTagsMetaData(stream); }
public static bool SaveDrawingImage(RasterImage image, string fileName) { try { Leadtools.Codecs.RasterCodecs codecs = new Leadtools.Codecs.RasterCodecs(); codecs.Options.Jpeg.Save.QualityFactor = 255; codecs.Save(image, fileName, RasterImageFormat.Jpeg411, 24, 1, 1, 1, CodecsSavePageMode.Overwrite); } catch(Exception ex) { throw ex; } return true; }
private void LoadPages(TifImage tifImage) { if (tifImage == null) { return; } RasterPaintProperties paintProp = imageList.PaintProperties; paintProp.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray; image = tifImage.ImageData; imageList.Items.Clear(); for (var i = 1; i <= image.PageCount; ++i) { RasterImageListItem imageItem = new RasterImageListItem(image, i, "Page " + i); imageList.Items.Add(imageItem); } LoadCheckBox(image.PageCount); }
public static ImageSource Resize(this ImageSource image, Size maxSize) { var rasterImage = ToRasterImage(image); var currentSize = new Size(rasterImage.ImageSize.Width, rasterImage.ImageSize.Height); var newSize = currentSize.PreserveAspectRatioWithinBounds(maxSize); var destImage = new RasterImage( RasterMemoryFlags.Conventional, (int)newSize.Width, (int)newSize.Height, rasterImage.BitsPerPixel, rasterImage.Order, rasterImage.ViewPerspective, rasterImage.GetPalette(), IntPtr.Zero, 0); var cmd = new ResizeCommand(destImage, RasterSizeFlags.Bicubic); cmd.Run(rasterImage); return ToBitmapSource(destImage); }
public static ObjectId addStaticGoogleMap() { var dialog = new OpenFileDialog("选择文件存储位置", "燃气热源方案比选", "jpg;png;bmp;*", "SaveFile", OpenFileDialog.OpenFileDialogFlags.NoShellExtensions); //var dialog = new OpenFileDialog(); System.Windows.Forms.DialogResult result = dialog.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { return ObjectId.Null; } ObjectId val = ObjectId.Null; string imagePath = dialog.Filename; string szname = "import"; Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; using (Database db = doc.Database) { using (Transaction tm = db.TransactionManager.StartTransaction()) { try { ObjectId imageDictID = RasterImageDef.GetImageDictionary(db); if (imageDictID == ObjectId.Null) { imageDictID = RasterImageDef.CreateImageDictionary(db); } RasterImageDef rasterImageDef = new RasterImageDef(); DBDictionary imageDict = (DBDictionary)tm.GetObject(imageDictID, OpenMode.ForWrite); ObjectId rasterImageDefID; if (imageDict.Contains(szname)) { rasterImageDefID = imageDict.GetAt(szname); rasterImageDef = (RasterImageDef)tm.GetObject(rasterImageDefID, OpenMode.ForWrite); } else { rasterImageDefID = imageDict.SetAt(szname, rasterImageDef); rasterImageDef.SourceFileName = imagePath; rasterImageDef.Load(); rasterImageDef.ImageModified = true; rasterImageDef.ResolutionUnits = Unit.Millimeter; tm.AddNewlyCreatedDBObject(rasterImageDef, true); } RasterImage rasterImage = new RasterImage(); RasterImage.EnableReactors(true); rasterImage.ImageDefId = rasterImageDef.ObjectId; LayerTable lt = (LayerTable)tm.GetObject(db.LayerTableId, OpenMode.ForRead); foreach (ObjectId objId in lt) { LayerTableRecord layer = tm.GetObject(objId, OpenMode.ForWrite) as LayerTableRecord; if (layer.Name != "our_outline_layer" && !layer.Name.StartsWith("方案") && layer.IsErased == false) { rasterImage.LayerId = objId; break; } } BlockTable bt = (BlockTable)tm.GetObject(doc.Database.BlockTableId, OpenMode.ForRead, false); BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false); val = btr.AppendEntity(rasterImage); tm.AddNewlyCreatedDBObject(rasterImage, true); tm.Commit(); tm.Dispose(); } catch (System.Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString()); } } } return val; }
private void AutoApplyWW_WC(RasterImage img) { try { if (lblAppliedLastWL.IsChecked==false || WC == 0 || WW == 0) { AllowAppliedWL = false; return; } using (Leadtools.Commands.Demos.WaitCursor wait = new Leadtools.Commands.Demos.WaitCursor()) { if (img.Order == RasterByteOrder.Gray && img.BitsPerPixel > 8) { // update lookup table try { ApplyLinearVoiLookupTableCommand command = new ApplyLinearVoiLookupTableCommand(); MinMaxBitsCommand minMaxBits = new MinMaxBitsCommand(); MinMaxValuesCommand minMaxValues = new MinMaxValuesCommand(); if (ADJUST_WOB) command.Flags = VoiLookupTableCommandFlags.ReverseOrder; else command.Flags = VoiLookupTableCommandFlags.None; minMaxBits.Run(img); img.LowBit = minMaxBits.MinimumBit; img.HighBit = minMaxBits.MaximumBit; minMaxValues.Run(img); command.Width = WW; command.Center = WC; command.Run(img); //_CurrCell.Invalidate(); } catch { } } } } catch { } finally { } }
private static void Transform(Transform transformProperties, RasterImage result) { var cropCommand = new CropCommand(); var rotateCommand = new RotateCommand { Angle = (int)(transformProperties.Rotation * 100) }; var rectCrop = new LeadRect( (int)transformProperties.Bounds.Left, (int)transformProperties.Bounds.Top, (int)transformProperties.Bounds.Width, (int)transformProperties.Bounds.Height); cropCommand.Rectangle = rectCrop; rotateCommand.Run(result); if (!transformProperties.Bounds.IsEmpty) { cropCommand.Run(result); } }
void RealizeAnnotation(RasterImage img, MedicalViewerMultiCell _cell) { string errMsg = ""; _DicomMedicalViewer.RealizeAnnotation(img, _cell, ref errMsg); if (errMsg.Trim() != "") { strErrorWhenRealizing = strErrorWhenRealizing + " " + errMsg; NoErrorWhilePreparing4Printing = NoErrorWhilePreparing4Printing && false; } MessageBox.Show(errMsg + @"\n Please realize it again or Contact our support staff(VBITJSC)"); }
public void OpenDicom( ref bool IsCroping, ref int _Idx, string fileName, bool IsOnlyImg, bool CanCreatePicBox) { //Stopwatch _sw = new Stopwatch(); try { _DicomMedicalViewer._medicalViewer.BeginUpdate(); pnlScheduled.Enabled = false; //_sw.Start(); #region Chế độ Demo if (_AppMode == AppType.AppEnum.AppMode.Demo && !File.Exists(fileName)) { ScheduledControl _selected = GetSelectedScheduled(); bool _isSelected = true; string RAWFilePath = ""; //Tạo các thư mục theo cấp ngày\Bệnh nhân(Mã bệnh nhân _ Tên Bệnh nhân _ Tuổi) if (!Directory.Exists(txtImgDir.Text + @"\" + SubDirLv1())) Directory.CreateDirectory(txtImgDir.Text + @"\" + SubDirLv1()); if (!Directory.Exists(txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient())) Directory.CreateDirectory(txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient()); //Kiểm tra nếu chưa chọn thủ tục nào thì cần lưu ảnh thành tên file theo định dạng //YYYY_MM_DD_HH_mm_ss if (_selected == null || RAWFileNameWillbeCreated == "NONE_SELECTED") { _isSelected = false; RAWFileNameWillbeCreated = "NONE_SELECTED_" + Utility.GetYYYYMMDDHHMMSS(DateTime.Now); if (!Directory.Exists(txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient() + @"\NONE_SELECTED")) Directory.CreateDirectory(txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient() + @"\NONE_SELECTED"); RAWFilePath = txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient() + @"\NONE_SELECTED\" + RAWFileNameWillbeCreated + ".RAW"; } else RAWFilePath = txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient() + @"\" + RAWFileNameWillbeCreated + ".RAW";//RAWFileNameWillbeCreated=REGNUM+_Detail_ID+_ACode+_Pcode tại phần click của Scheduled fileName = Application.StartupPath + @"\DemoImg\" + m_strCurrACode + "-" + m_strCurrPCode + ".DCM"; string destFile = RAWFilePath.ToUpper().Replace(".RAW", ".DCM"); try2MoveFileInDemoMode(fileName, destFile); fileName = destFile; //Tự động cập nhật kết quả đã có hình ảnh AutoUpdateResultAfterCapturingPictureFromModality(); AutoUpdatePatientInforInDcmFile_DemoMode(Path.GetDirectoryName(fileName), fileName, txtID2.Text, txtName2.Text, txtAge.Text, Sex,_selected.StudyInstanceUID, _selected.SeriesInstanceUID, _selected.SOPInstanceUID); } #endregion isLoadding = true; //stopToolStripMenuItem1_Click(mnuStop, new EventArgs()); TempCrop = IsCroping; int _ww = 0; int _wc = 0; this.Text = MultiLanguage.GetText(globalVariables.DisplayLanguage, "VietBaIT JCS - DROC", "VietBaIT JSC-DROC"); if (!IsCroping) FilePath = fileName; bool IsRawFile = false; _images = 1; try { #region Xử lý lại ảnh dcm từ ảnh gốc(Raw file) try { if (IsGenDcmFromRaw) { IsGenDcmFromRaw = false; string tempf_raw = fileName.ToUpper().Replace(".DCM", ".RAW"); //Kiểm tra xem có ảnh Raw không if (File.Exists(tempf_raw)) { //xóa file Dcm đang có string tempf_dcm = fileName.ToUpper().Replace(".RAW", ".DCM"); try { File.Delete(tempf_dcm); } catch { } //Gán lại giá trị cho fileName để bước kế tiếp load lại raw file fileName = tempf_raw; } } } catch(Exception ex0) { AppLogger.LogAction.LogActions("==>OpenDicom.if (IsGenDcmFromRaw)().Exception occurred at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "." + ex0.ToString()); } try { if (Path.GetExtension(fileName).ToUpper().Contains("RAW")) { if (IsUsingDicomConverter || lblAutoDcmConverter.IsChecked)//Tự động convert thành file Dicom { ConvertRaw2DicomFileReprocess(fileName); AutoUpdateResultAfterCapturingPictureFromModality(); fileName = fileName.ToLower().Replace(".raw", ".dcm"); IsUsingDicomConverter = true; v_blnHasConvertRawin2DicomFile = true; //Thực hiện thuật toán xử lý ảnh ở ngay sau bước load ảnh Dicom } else { new frm_LargeMsgBoxOK(MultiLanguage.GetText(globalVariables.DisplayLanguage, "Thông báo", "Warning"), MultiLanguage.GetText(globalVariables.DisplayLanguage, "Cần vào tab Cấu hình đánh dấu vào mục tự động Convert thành file Dicom", "go to Configuration Tab and check Auto Convert to Dicom File"), MultiLanguage.GetText(globalVariables.DisplayLanguage, "Đã hiểu", "OK"), MultiLanguage.GetText(globalVariables.DisplayLanguage, "Không hiểu", "Cancel")).ShowDialog(); } } } catch (Exception ex01) { AppLogger.LogAction.LogActions("==>OpenDicom.ReGenDcmFromRAWFile().Exception occurred at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "." + ex01.ToString()); } #endregion if (File.Exists(fileName)) { AppLogger.LogAction.AddLog2List(lstFPD560,DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + fileName + " exists"); FreeMemoryCapturedByMedicalviewerCell(); using (RasterCodecs _codecs = new RasterCodecs()) { //using (CounterDialog counter = new CounterDialog(this, _codecs)) //{ // counter.Show(this); // counter.Update(); //if (chkLoadIn2Memory.IsChecked==false ) _codecs.Options.Load.DiskMemory = true; if (_codecs.Options.Load.DiskMemory) SetText(lblUsingMemo, "MEM"); else SetText(lblUsingMemo, "NOTMEM"); using (RasterImage _image = _codecs.Load(fileName)) { cmdCreateDcmfromRaw.Enabled = true; //try2FreeImage(orginalImg); _DicomMedicalViewer.try2FreeImage(ref orginalImg); // try2FreeOriginalImage(); if (_CurrCell != null) { RasterImage img = _CurrCell.Image; _DicomMedicalViewer.try2FreeImage(ref img); } orginalImg = _image.CloneAll(); //Xóa các cell sau khi đã giải phóng bộ nhớ _DicomMedicalViewer._medicalViewer.Cells.Clear(); //Tạo cell mới MedicalViewerMultiCell cell = new MedicalViewerMultiCell(); cell.BeginUpdate(); cell.FitImageToCell = true; cell.Columns = 1; cell.Rows = 1; _DicomMedicalViewer.InitializeCell(cell); _DicomMedicalViewer.CopyPropertiesFromGlobalCell(cell); _Idx = 0; if (IsOnlyImg) return; CurrCellFileName = fileName; //cell.SetTag(4, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Frame); cell.SetTag(6, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Scale); cell.SetTag(2, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.WindowLevelData); //cell.SetTag(1, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.FieldOfView); cell.SetTag(0, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.RulerUnit); DicomDataSet ds = new DicomDataSet(); try { ds.Load(fileName, DicomDataSetLoadFlags.LoadAndClose); CurrentDicomDS = ds; } catch (Exception ex) { ds = null; } //DicomDS.Add(fileName, ds); if (ds != null) { if (IsRawFile) AutpSetDefaultTagForImgInfor(fileName, ds); _ww = Convert.ToInt32(GetStringValue(ds, DicomTag.WindowWidth)); _wc = Convert.ToInt32(GetStringValue(ds, DicomTag.WindowCenter)); string ID_Name = GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientID) + " " + GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientName); string Birthday_Sex_Age = ""; string BD = GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientBirthDate).Trim(); string BT = GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientBirthTime).Trim(); string Sex = TranslateSex(GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientSex).Trim()); string Age = GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientAge).Trim(); ID_Name_Age_Sex = ID_Name + " " + Age + " " + Sex; if (BD != "") Birthday_Sex_Age += BD; //if (BT != "") Birthday_Sex_Age += BD; if (Sex != "") Birthday_Sex_Age += " [" + Sex + "] "; if (Age != "") Birthday_Sex_Age += Age + " T"; //Mã+Tên BN cell.SetTag(0, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, ID_Name); //Ngày sinh-Giới tính-Tuổi cell.SetTag(1, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, Birthday_Sex_Age); //Các thông tin khác cell.SetTag(0, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, HospitalName); cell.SetTag(1, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, DepartmentName); cell.SetTag(2, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")); } else { //Mã+Tên BN cell.SetTag(0, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, ""); //Ngày sinh-Giới tính-Tuổi cell.SetTag(1, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, ""); //Các thông tin khác cell.SetTag(0, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, ""); cell.SetTag(1, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, ""); cell.SetTag(2, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, ""); } //Load Annotation string Anfn = GetAnnPath(fileName); if (System.IO.File.Exists(Anfn)) { LoadAnnotation(cell, Anfn, true); } _DicomMedicalViewer.ApplyToCell(cell); cell.ShowTags = lblDisplayTag.IsChecked; cell.DisplayRulers = (MedicalViewerRulers)cboRuler.SelectedIndex; AddNewMecicalViewerCell(cell); int CellCount = _DicomMedicalViewer._medicalViewer.Cells.Count; _Idx = CellCount - 1; //Dùng CloneAll() để giải phóng _image cell.Tag = fileName; if (GetSelectedScheduled() != null) cell.TabIndex = GetSelectedScheduled().DETAIL_ID; else cell.TabIndex = m_intCurrentDetail_ID <= 0 ? 0 : m_intCurrentDetail_ID; //v_blnHasConvertRawin2DicomFile=true xảy ra ở 2 sự kiện //1. Nhận ảnh từ FPD và có tự động chuyển thành file Dicom //2. Nhận ảnh từ FPD và để dưới dạng file RAW, sau đó tại hàm OpenDicom() nếu chưa có ảnh Dcm sẽ tự động Convert file RAW thành DCM if (v_blnHasConvertRawin2DicomFile && lblDisplayRaw.ImageIndex != 0) { using (Cursor _Cursor = Cursors.WaitCursor) { AppLogger.LogAction.ShowEventStatus(lblFPDStatus,MultiLanguage.GetText(globalVariables.DisplayLanguage, "Đang xử lý ảnh...", "image processing...")); AppLogger.LogAction.AddLog2List(lstFPD560,DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + MultiLanguage.GetText(globalVariables.DisplayLanguage, "Đang xử lý ảnh...", "image processing...")); _DicomMedicalViewer.ApplyIEConfig(_currDRIEData, _image, lblGridMode.IsChecked, lblAppliedMed.IsChecked); AutoApplyWW_WC(_image); AppLogger.LogAction.AddLog2List(lstFPD560,DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + MultiLanguage.GetText(globalVariables.DisplayLanguage, "Đã xử lý xong...", "image processed...")); AppLogger.LogAction.ShowEventStatus(lblFPDStatus,MultiLanguage.GetText(globalVariables.DisplayLanguage, "Đã xử lý xong...", "image processed...")); if ( ((_FPDMode != AppType.AppEnum.FPDMode.Other && chkAutoVFlip1.IsChecked) || (_FPDMode == AppType.AppEnum.FPDMode.Other && ((FPDSeq == 1 && chkAutoVFlip1.IsChecked) || (FPDSeq == 2 && chkAutoVFlip2.IsChecked))))) { _DicomMedicalViewer.ApplyFilter(_image, new FlipCommand(true)); } if (((_FPDMode != AppType.AppEnum.FPDMode.Other && chkAutoHFlip1.IsChecked) || (_FPDMode == AppType.AppEnum.FPDMode.Other && ((FPDSeq == 1 && chkAutoHFlip1.IsChecked) || (FPDSeq == 2 && chkAutoHFlip2.IsChecked))))) { _DicomMedicalViewer.ApplyFilter(_image, new FlipCommand(false)); } if (AUTO_FLIPV == 1) { _DicomMedicalViewer.ApplyFilter(_image, new FlipCommand(true)); } if (AUTO_FLIPH == 1) { _DicomMedicalViewer.ApplyFilter(_image, new FlipCommand(false)); } AutoDetectRowsAndCols(cell, _image.PageCount); cell.Image = _image.CloneAll(); if (!_DicomMedicalViewer.IsValidCell()) return; _DicomMedicalViewer._medicalViewer.Cells.SelectAll(false); _DicomMedicalViewer._medicalViewer.VisibleRow = _Idx; cell.Selected = true; _DicomMedicalViewer._medicalViewer.Invalidate(); if (AllowAppliedWL) { _DicomMedicalViewer.SetWindowLevel(cell, WW,WC); } AllowAppliedWL = true; } _ww = WW; _wc = WC; //Thử tạo thông tin Annotation //CreateDefaultAnnotationOnImage(_DicomMedicalViewer._medicalViewer, Color.White, Color.Black, HospitalName, DepartmentName, ID_Name_Age_Sex, DateTime.Now.ToString("dd/MM/yyyy")); SaveImg(); v_blnHasConvertRawin2DicomFile = false; //Tự động chuyển sang Tab xử lý ảnh tabCtrlAcq.SelectedTab = tabPageImgTools; //PlayBeep(5); } else { AutoDetectRowsAndCols(cell, _image.PageCount); cell.Image = _image.CloneAll(); //cell.Bounds = cell.GetDisplayedClippedImageRectangle(); if (!_DicomMedicalViewer.IsValidCell()) return; _DicomMedicalViewer._medicalViewer.Cells.SelectAll(false); _DicomMedicalViewer._medicalViewer.VisibleRow = _Idx; cell.Selected = true; _DicomMedicalViewer._medicalViewer.Invalidate(); if (_AppMode == AppType.AppEnum.AppMode.Demo && FirstExposure) { SaveImg(); } } //Áp dụng windowLeveling khi thực hiện lưu ảnh. //AutoApplyWW_WC(); if (_ww != 0) { _DicomMedicalViewer.SetWindowLevel(cell,_ww,_wc); _DicomMedicalViewer._medicalViewer.Invalidate(); } cell.EndUpdate(); _DicomMedicalViewer._medicalViewer.Invalidate(); } // } } _DicomMedicalViewer._medicalViewer.EndUpdate(); AppLogger.LogAction.ShowEventStatus(lblFPDStatus,MultiLanguage.GetText(globalVariables.DisplayLanguage, "Mời bạn tiếp tục xử lý", "Image Result")); } else { mdlStatic.isDisplayImg = false; if (_AppMode == AppType.AppEnum.AppMode.License || (_AppMode == AppType.AppEnum.AppMode.Demo && _ViewState == AppType.AppEnum.ViewState.Capture)) MessageBox.Show("Không tồn tại file ảnh sau:\n" + fileName); } } catch (Exception ex) { AppLogger.LogAction.LogActions("==>OpenDicom.SecondsException().Exception occurred at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "." + ex.ToString()); Utility.ShowMsg("2225 " + ex.ToString() + "\n" + fileName); GC.Collect(); isLoadding = false; DeleteCurrentImg(_DicomMedicalViewer._medicalViewer, _DicomMedicalViewer._medicalViewerCellIndex); } finally { isLoadding = false; } isLoadding = false; } catch (Exception ex1) { AppLogger.LogAction.LogActions("==>OpenDicom.FirstException().Exception occurred at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "." + ex1.ToString()); AppLogger.LogAction.AddLog2List(lstFPD560,"0002: " + ex1.Message); } finally { _DicomMedicalViewer._medicalViewer.BeginUpdate(); pnlScheduled.Enabled = true; //_sw.Stop(); //AppLogger.LogAction.ShowEventStatus(lblFPDStatus,((decimal)_sw.ElapsedMilliseconds / 1000).ToString()); IsUsingDicomConverter = false; lblMemory.Text = getAvailableRAM(); //Kiểm tra nếu đang chế độ Crop mà lại chọn mục xem lại ảnh gốc thì cần khôi phục lại chế độ đó if (_DicomMedicalViewer._IsCropping && IsLoadOriginalImage) { cmdAcqCrop_Click(cmdAcqCrop,new EventArgs());//Trạng thái ban đầu cmdAcqCrop_Click(cmdAcqCrop, new EventArgs());//Trạng thái Crop } } }
private void AddPageToDest(RasterImage image) { RasterImageListItem item = new RasterImageListItem(); item.Image = image; // image.v image.FlipViewPerspective(true); destImageList.Items.Add(item); }