//.... private void Convolution(Bitmap img, double[,] matrix) { var w = matrix.GetLength(0); var h = matrix.GetLength(1); using (var wr = new ImageWrapper(img) { DefaultColor = Color.Silver }) foreach (var p in wr) { double r = 0d, g = 0d, b = 0d; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { var pixel = wr[p.X + i - 1, p.Y + j - 1]; r += matrix[j, i] * pixel.R; g += matrix[j, i] * pixel.G; b += matrix[j, i] * pixel.B; } } wr.SetPixel(p, r, g, b); } }
public MethodResult <int> AddImageToFileOnDrive(int ArchiveEntityKey, string img, int DriveId) { MethodResult <int> ret = new MethodResult <int>(0) { Success = true }; var cnf = new ConfigurationData(); var lg = new Logger(); var fm = new FileManager(cnf, lg); int ImageKey = 0; // Сохранить изображение, Сохранить эскиз string targetDir = string.Format(@"drive{0}\img{1}", DriveId, ArchiveEntityKey); var im = CreateImage(img, targetDir, cnf, lg, fm); // Сохранить запись об изображении в БД var wrapper = new ImageWrapper(im); Images.Add(wrapper); wrapper.PropertyChanged += Wrapper_PropertyChanged; ArchiveEntity.Model.Images.Add(wrapper.Model); HasChanges = ArchiveEntity != null && !ArchiveEntity.HasErrors; ImageKey = im.ImageKey; return(new MethodResult <int>(ImageKey)); }
public static unsafe IImage ToIImage(this ImageFile file) { if (file == null) { return(null); } byte[] src = file.GetData(); SaintCoinach.Imaging.ImageFormat format = file.Format; int width = file.Width; int height = file.Height; byte[] argb = ImageConverter.GetA8R8G8B8(src, format, width, height); ImageWrapper wrapper = null; try { fixed(byte *p = argb) { IntPtr ptr = (IntPtr)p; Bitmap tempImage = new Bitmap(width, height, width * 4, PixelFormat.Format32bppArgb, ptr); wrapper = new ImageWrapper(tempImage); } } catch (Exception) { } return(wrapper); }
private void timer1_Tick(object sender, EventArgs e) { try { if (_bRecebendo) { return; } _bRecebendo = true; ImageWrapper oImageWrapper = frmClientUsers.oRemoteServer.GetScreen(oViewSession); if (oImageWrapper != null) { pict.Image = oImageWrapper.ToImage(); } else { timer1.Enabled = false; System.Windows.Forms.MessageBox.Show("Você não tem permissão para essa ação!"); this.Close(); } } catch (Exception ex) { timer1.Enabled = false; System.Windows.Forms.MessageBox.Show("[timer1_Tick]" + ex.Message); System.Windows.Forms.MessageBox.Show("[timer1_Tick]" + ex.StackTrace); System.Environment.Exit(0); } _bRecebendo = false; }
private void BuildPicture(string vPath) { ImageViewPanel.Visible = true; ImageBrowserPanel.Visible = false; string path = imageTools.GetPath(vPath); ImageWrapper i = imageTools.GetImageWrapper(path); back = Page.GetPostBackClientHyperlink(this, "directory;" + vPath.Substring(0, vPath.Length - i.Name.Length - 1)); image.NavigateUrl = i.FullImageHref; image.ImageUrl = i.WebImageHref; lbImageText.Visible = false; txtImageText.Visible = false; lnkSaveImageText.Visible = false; lnkSetFolderImage.Visible = false; if (ModuleHasEditRights) { txtImageText.Text = i.Blurb; txtImageText.Visible = true; lnkSaveImageText.Visible = true; lnkSaveImageText.NavigateUrl = Page.GetPostBackClientHyperlink(this, "picturesave;" + vPath); lnkSetFolderImage.Visible = true; lnkSetFolderImage.NavigateUrl = Page.GetPostBackClientHyperlink(this, "setfolderimage;" + vPath); } else { lbImageText.Text = i.Blurb; lbImageText.Visible = true; } }
private void AddPreloadCode(DirectoryWrapper data, int index, WebControl imgCtrl) { const string scriptKey = "ImagePreload"; if (!Page.ClientScript.IsClientScriptBlockRegistered(scriptKey)) { string script = "<script language=\"JavaScript\">\n" + "function PreLoadSiblings()\n{\n"; // Script for the Next end the previous picture, to load them to the browser cache. if (index > 0) { ImageWrapper i = data.Images[index - 1] as ImageWrapper; string path = ResolveUrl(i.WebImageHref); script += "objImageNext = new Image(); objImageNext.src='" + path + "';\n"; } if (index < data.Images.Count - 1) { ImageWrapper i = data.Images[index + 1] as ImageWrapper; string path = ResolveUrl(i.WebImageHref); script += "objImageNext = new Image(); objImageNext.src='" + path + "';\n"; } script += "}\n</script>"; Page.ClientScript.RegisterClientScriptBlock(typeof(Page), scriptKey, script); // Register the Script for the event when the main Image is loaded. imgCtrl.Attributes.Add("onload", "PreLoadSiblings()"); } }
/// <summary> /// 将图片逆时针旋转degress度,返回旋转后的图片对象。 /// </summary> /// <param name="img">图片</param> /// <param name="x">旋转中心x坐标,默认为图片中点</param> /// <param name="y">旋转中心y坐标,默认为图片中点</param> /// <param name="degree">旋转角度。</param> /// <returns></returns> public ImageWrapper rotate(ImageWrapper img, float x, float y, float degree) { var matrix = new Matrix(); matrix.PostRotate(degree, x, y); return(ImageWrapper.OfBitmap(Bitmap.CreateBitmap(img.Bitmap, 0, 0, img.Width, img.Height, matrix, true))); }
/// <summary> /// /// </summary> public BasicFilterWindow(ImageWrapper image, FilterBase filter, int w, int h) : base(filter.Name, w, h, image) { this.filter = filter; InitializeComponent(); this.lblHelp.Text = filter.Description; }
public void Transform(Bitmap bitmap) { var matrix = new double[, ] { { 0, -1, 0 }, { -1, 5, -1 }, { 0, -1, 0 } }; var w = matrix.GetLength(0); var h = matrix.GetLength(1); using (var wr = new ImageWrapper(bitmap) { DefaultColor = Color.Silver }) foreach (var p in wr) { double r = 0d, g = 0d, b = 0d; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { var pixel = wr[p.X + i - 1, p.Y + j - 1]; r += matrix[j, i] * pixel.R; g += matrix[j, i] * pixel.G; b += matrix[j, i] * pixel.B; } } wr.SetPixel(p, r, g, b); } }
/// <summary> /// 从图片img的位置(x, y)处剪切大小为w * h的区域,并返回该剪切区域的新图片。 /// </summary> /// <param name="img">图片</param> /// <param name="x">剪切区域的左上角横坐标</param> /// <param name="y">剪切区域的左上角纵坐标</param> /// <param name="x2">剪切区域的宽度</param> /// <param name="y2">剪切区域的高度</param> /// <returns></returns> public ImageWrapper clip(ImageWrapper img, int x, int y, int x2, int y2) { var w = x2 - x; var h = y2 - y; return(ImageWrapper.OfBitmap(Bitmap.CreateBitmap(img.Bitmap, x, y, w, h))); }
private void OnDeleteImageExecute(int?id) { int ImageKey = (int)id; ImageWrapper image = ArchiveEntity.Images.Where(x => x.ImageKey == ImageKey).First(); var result = MessageDialogService.ShowOKCancelDialog($"Удалить Изображение {image.ImageTitle}?", $"Удалить Изображение {image.ImageTitle}?"); if (result == MessageDialogResult.OK) { if (image != null) { ArchiveEntity.Images.Remove(image); image.PropertyChanged -= Wrapper_PropertyChanged; var wrapper = Images.Where(x => x.ImageKey == ImageKey).First(); Images.Remove(wrapper); _repository.RemoveImage(ArchiveEntity.ArchiveEntityKey, ImageKey); HasChanges = ArchiveEntity != null && !ArchiveEntity.HasErrors; } } /// Дописать удаление файла !!!!!!!!!!!! // RemoveItemFromEntityCollection(_fileOnDriveDataProvider.RemoveImageFromEntity, ImageKey); }
public virtual async Task <UploadInfo> UploadImageAsync(IFormFile formFile, bool avatar) { if (formFile == null) { throw new Exception("上传文件为空"); } string oldName = formFile.FileName; //原始文件名 string extName = Path.GetExtension(oldName); // 获取扩展名 string newName = StringHelper.GetGuidString() + extName; //构建新的文件名 string webRootPath = this.environment.WebRootPath; if (extName != ".jpg" && extName != ".png" && extName != ".gif" && extName != ".jpeg") { throw new Exception("上传图片仅支持jpg,png,gif格式"); } byte[] bytes = await formFile.GetBytes(); ImageWrapper image = new ImageWrapper(bytes); if (!image.IsReallyImage()) { throw new Exception("上传文件不是真实图片"); } if (avatar) { // 上传头像 string updateMark = "avatar"; string diskPath = Path.Combine(webRootPath, UploadDirectory, updateMark); if (!Directory.Exists(diskPath)) { Directory.CreateDirectory(diskPath); } string filePath = Path.Combine(diskPath, newName); image.Resize(128, 128).SaveToFile(filePath); return(new UploadInfo { DiskPath = filePath, FileName = newName, UrlPath = $"/{UploadDirectory}/{updateMark}/{newName}" }); } else { // 上传图片 string updateMark = "image"; string diskPath = Path.Combine(webRootPath, UploadDirectory, updateMark); if (!Directory.Exists(diskPath)) { Directory.CreateDirectory(diskPath); } string filePath = Path.Combine(diskPath, newName); image.SaveToFile(filePath); return(new UploadInfo { DiskPath = filePath, FileName = newName, UrlPath = $"/{UploadDirectory}/{updateMark}/{newName}" }); } }
/// <summary> /// /// </summary> /// <param name="filter"></param> public BasicFilterWindow(ImageWrapper image, FilterBase filter) : this(image, filter, BASE_WIDTH, BASE_HEIGHT) { // // TODO: Add constructor logic here // }
/// <summary> /// 读取在路径path的图片文件并返回一个Image对象。如果文件不存在或者文件无法解码则返回null。 /// </summary> /// <param name="path">图片路径</param> /// <returns></returns> public ImageWrapper read(string path) { path = PFiles.Path(path); var bitmap = BitmapFactory.DecodeFile(path); return(ImageWrapper.OfBitmap(bitmap)); }
public void ApplyExample(Bitmap bitmap) { Images = new Dictionary <string, ImageWrapper>(); OriginalImage = new ImageWrapper(bitmap); Images.Add("Original", OriginalImage); AddExampleImages(Images, OriginalImage.Image); }
/// <summary> /// Constructor /// </summary> private ThumbnailForm(string title, ImageWrapper imagewrapper) : base(title, imagewrapper) { InitializeComponent(); ((Button)this.AcceptButton).Visible = false; ((Button)this.CancelButton).Text = "&Close"; }
/// <summary> /// 读取二维码图片 /// </summary> public static string ReadImage(ImageWrapper image) { using (MemoryStream stream = image.CreateMemoryStream()) { return(ReadStream(stream)); } }
public async Task <IActionResult> CodeImage() { string code = RandomHelper.GetVerifyCode(); ImageWrapper image = ImageWrapper.CreateByVerifyCode(code); await HttpContext.Session.SetVerifyCodeAsync(code); return(new ImageStreamResult(image.ImageBytes)); }
/// <summary> /// This creates a Table object with all the thumbnails in it /// </summary> /// <param name="nofCols">Picture Columns</param> /// <param name="nofRows">Picture Rows</param> /// <param name="startIndex">index of the first displayed picture</param> /// <param name="data">The directory to render</param> /// <param name="url">The URL to use in the links</param> /// <returns></returns> public static Table RenderImageTable(int nofCols, int nofRows, int startIndex, DirectoryWrapper data, System.Web.UI.Control ctrl) { Table table = new Table(); table.Width = Unit.Percentage(100); TableRow tr = null; if (((data.Images.Count - 1) - startIndex) <= 0) // Are some pictures in this range? { startIndex = 0; // No. } int lastIndex = System.Math.Min((data.Images.Count - 1), startIndex + nofCols * nofRows - 1); for (int index = startIndex; index <= lastIndex; index++) { if (tr == null) { tr = new TableRow(); } ImageWrapper image = data.Images[index] as ImageWrapper; HyperLink h = new HyperLink(); h.ImageUrl = image.ThumbHref; h.NavigateUrl = ctrl.Page.GetPostBackClientHyperlink(ctrl, "picture;" + data.VirtualPath + ";" + index); h.Text = image.Tooltip; h.CssClass = "LinkButton"; Label lbText = new Label(); lbText.Text = image.Caption; TableCell td = new TableCell(); td.Attributes.Add("align", "center"); td.Controls.Add(h); if (lbText.Text != "") { lbText.Text = @"<div align=""center"" width=""100%"">" + lbText.Text + @"</div>"; td.Controls.Add(lbText); } tr.Cells.Add(td); if (tr.Cells.Count == nofCols) { table.Rows.Add(tr); tr = null; } } if (tr != null) { table.Rows.Add(tr); } return(table); }
private static void AddImages(IStoryContainer inner, int count) { for (var i = 0; i < count; i++) { var idx = Random.Next(1, 10); var image = Image.FromFile($"./images/{idx}.jpg"); var imageWrapper = new ImageWrapper(image, new Padding(25, 5, 10, 2)); inner.Add(imageWrapper); } }
private void MyCallback(ImageWrapper wrapper) { // since the callback will be running on the // thread associated with the task, if you // want to interact with the UI in the callback // you need to use Dispatcher Dispatcher.BeginInvoke(new Action(() => { Debug.WriteLine(wrapper.Val); })); }
private void chatControl1_BeginToSend(string content) { this.chatControl1.ShowMessage(Common.UserName, DateTime.Now, content, true); imageDict = this.chatControl1.imageDict; //把控件中的图片字典,添加到图片包装类列表中 foreach (KeyValuePair <string, Image> kv in imageDict) { ImageWrapper newWrapper = new ImageWrapper(kv.Key, kv.Value); imageWrapperList.Add(newWrapper); } //清除控件中图片字典的内容 this.chatControl1.ClearImageDic(); //从客户端 Common中获取相应连接 Connection p2pConnection = Common.GetUserConn(this.friendID); if (p2pConnection != null) { MsgEntity chatContract = new MsgEntity(); chatContract.SenderID = Common.UserID; chatContract.Reciver = this.friendID; chatContract.MsgContent = content; chatContract.SendTime = DateTime.Now; //chatContract.ImageList = imageWrapperList; p2pConnection.SendObject("ClientChatMessage", chatContract); this.chatControl1.Focus(); imageWrapperList.Clear(); LogInfo.LogMessage("通过p2p通道发送消息,当前用户ID为" + Common.UserID + "当前Tcp连接端口号" + p2pConnection.ConnectionInfo.LocalEndPoint.Port.ToString(), "P2PINFO"); } else { MsgEntity chatContract = new MsgEntity(); chatContract.SenderID = Common.UserID; chatContract.Reciver = this.friendID; chatContract.MsgContent = content; chatContract.SendTime = DateTime.Now; //chatContract.ImageList = imageWrapperList; Common.TcpConn.SendObject("ChatMessage", chatContract); this.chatControl1.Focus(); imageWrapperList.Clear(); LogInfo.LogMessage("服务器转发消息", "P2PINFO"); } }
public static ThumbnailForm ShowView(Form owner, ImageWrapper image) { var form = new ThumbnailForm($"Thumbnail: {Path.GetFileName(image.Filename)}", image) { Owner = owner, TopMost = true }; form.Show(); return(form); }
/// <summary> /// 把图片image以PNG格式保存到path中。如果文件不存在会被创建;文件存在会被覆盖。 /// </summary> /// <param name="image">图片</param> /// <param name="path">路径</param> /// <param name="format">图片格式,可选的值为:png,jpeg/jpg,webp</param> /// <param name="quality">图片质量,为0~100的整数值</param> /// <returns></returns> /// <exception cref="Exception"></exception> public bool save(ImageWrapper image, string path, string format, int quality) { var compressFormat = ParseImageFormat(format); if (compressFormat == null) { throw new Exception("unknown format " + format); } var outputStream = new FileStream(PFiles.Path(path), FileMode.CreateNew); return(image.Bitmap.Compress(compressFormat, quality, outputStream)); }
protected async Task <AsyncOut <IImage> > ProcessImage(MediaFile file, Stream inStream) { var originalSize = Size.Empty; var format = _imageProcessor.Factory.FindFormatByExtension(file.Extension) ?? new UnsupportedImageFormat(file.MimeType, file.Extension); try { originalSize = ImageHeader.GetPixelSize(inStream, file.MimeType); } catch { } IImage outImage; if (format is UnsupportedImageFormat) { outImage = new ImageWrapper(inStream, originalSize, format); return(new AsyncOut <IImage>(true, outImage)); } var maxSize = _mediaSettings.MaximumImageSize; var query = new ProcessImageQuery(inStream) { Format = file.Extension, DisposeSource = true, ExecutePostProcessor = ImagePostProcessingEnabled, IsValidationMode = true }; if (originalSize.IsEmpty || (originalSize.Height <= maxSize && originalSize.Width <= maxSize)) { // Give subscribers the chance to (pre)-process var evt = new ImageUploadedEvent(query, originalSize); await _eventPublisher.PublishAsync(evt); outImage = evt.ResultImage ?? new ImageWrapper(inStream, originalSize, format); return(new AsyncOut <IImage>(true, outImage)); } query.MaxSize = maxSize; using (var result = await _imageProcessor.ProcessImageAsync(query, false)) { outImage = result.Image; return(new AsyncOut <IImage>(true, outImage)); } }
private void InitializeImages(ICollection <Model.Image> images) { foreach (var wrapper in Images) { wrapper.PropertyChanged -= Wrapper_PropertyChanged; } Images.Clear(); foreach (var image in images) { var wrapper = new ImageWrapper(image); Images.Add(wrapper); wrapper.PropertyChanged += Wrapper_PropertyChanged; } }
private List <ImageWrapper> StringToImageWrapper(List <string> images, int id) { List <ImageWrapper> listToReturn = new List <ImageWrapper>(); foreach (var item in images) { ImageWrapper i = new ImageWrapper { Image = item }; listToReturn.Add(i); } return(listToReturn); }
/// <summary> /// Constructor /// </summary> /// <param name="title">Tool Window title (also used as name)</param> /// <param name="w">Tool Window Width</param> /// <param name="h">Tool Window Height</param> /// <param name="bitmap">Default Image Wrapper to use</param> public PreviewToolForm(string title, int w, int h, ImageWrapper imagewrapper) { InitializeComponent(); this.Text = title; this.ClientSize = new Size(w + 2 * this.imageBox.Location.X, h + 2 * this.imageBox.Location.Y); this.imageBox.Size = new Size(w, h); if (imagewrapper != null) { this.image = imagewrapper; this.image.Changed += OnOriginalBitmapChanged; } }
protected bool ProcessImage(MediaFile file, Stream inStream, out IImage outImage) { outImage = null; var originalSize = Size.Empty; var format = _imageProcessor.Factory.GetImageFormat(file.Extension) ?? new UnsupportedImageFormat(file.MimeType, file.Extension); try { originalSize = ImageHeader.GetDimensions(inStream, file.MimeType); } catch { } if (format is UnsupportedImageFormat) { outImage = new ImageWrapper(inStream, originalSize, format); return(true); } var maxSize = _mediaSettings.MaximumImageSize; var query = new ProcessImageQuery(inStream) { Quality = _mediaSettings.DefaultImageQuality, Format = file.Extension, DisposeSource = true, ExecutePostProcessor = ImagePostProcessingEnabled, IsValidationMode = true }; if (originalSize.IsEmpty || (originalSize.Height <= maxSize && originalSize.Width <= maxSize)) { // Give subscribers the chance to (pre)-process var evt = new ImageUploadedEvent(query, originalSize); _eventPublisher.Publish(evt); outImage = evt.ResultImage ?? new ImageWrapper(inStream, originalSize, format); return(true); } query.MaxSize = maxSize; using (var result = _imageProcessor.ProcessImage(query, false)) { outImage = result.Image; return(true); } }
public HistogramForm(ImageWrapper <Bgr, byte> image) { InitializeComponent(); ibImageBox.Image = image.Image; zoomBox.Image = image.Image.Bitmap; DenseHistogram histogram = new DenseHistogram(256, new RangeF(0.0f, 255.0f)); histogram.Calculate(new Image <Gray, byte>[] { image.Convert <Gray, byte>().Image }, false, null); Mat mat = new Mat(); bhHistogram.AddHistogram("Laplace histogram", Color.Black, mat, 256, new float[] { 0f, 256f }); bhHistogram.Refresh(); }