Tag: image

如何在WinRT中获取像素的RGB值

我想在WinRT应用程序中获取每个像素的RGB值。 我可以访问包含PixelData的字节数组,但我不知道如何使用它,那么如何从字节数组中提取RGB信息? var bd = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream); var pd = await bd.GetPixelDataAsync(); var tempBuffer = pd.DetachPixelData(); var PixelMatrix = new byte[bd.PixelWidth, bd.PixelHeight]; // how do I get the RGB value for PixelMatrix[0,0]?

加载,保存,然后再次加载图像会抛出“GDI +中发生一般错误”

这似乎是臭名昭着的错误 。 我记得在不久的代码中得到了一段时间,但它回来了 ,报复,但有一些我似乎无法弄清楚的新代码。 当然,它绝对是generic ! 目标 我正在尝试构建一个允许用户执行以下操作的表单: 选择图像。 按save(关闭表单),并将图像保存到byte[]到数据库中。 打开表单(从byte[]加载图像)。 允许他们再次按保存。 允许他们再次打开表单,再次显示图像。 一个非常标准的加载/保存方案。 问题 关于加载和保存到SQL Server,一切正常。 我得到的问题是重复加载和保存到byte[]即使我使用相同的设置。 看一下我嘲笑的代码来演示这个问题: static void Main(string[] args) { // Load the image var initialImage = (Bitmap)Bitmap.FromFile(@”D:\picture.jpg”); // Save to a memory stream and get the bytes var initialImageBytes = SaveImageToBytes(initialImage); // Load again from this saved image Bitmap byteLoadedImage […]

如何将图像裁剪成圆圈?

我正在尝试将图像裁剪为圆形,圆形区域外面的区域为白色。 新的图像尺寸将与原始尺寸相同,只是有效地舍入图像。 我熟悉如何使用GDI +裁剪图像,通过拍摄现有图像并将其复制到新图像中来绘制矩形/正方形,但我看不到如何用白色填充圆弧/圆的外部。 这可能吗? 更新 – 我想做服务器端,因为不同的浏览器/平台不同地渲染css半径,或者根本不同 到目前为止我的工作是: public static Image CropCircle2(Image imgSource) { Image imgTarget = new Bitmap(imgSource.Width, imgSource.Height); Graphics g = Graphics.FromImage(imgTarget); var path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddEllipse(0, 0, imgTarget.Width, imgTarget.Height); g.SetClip(path); g.DrawImage(imgSource, 0, 0); return imgTarget; }

从RichTextBox中提取图像

我有一个应用程序,用户可以将图像插入RichTextBox。 我希望能够用一些令牌替换RTF中的所有图像,并将图像存储在单独的文件中。 我稍后会将图像注入RTF。 我设法让插入工作,但最终通过剪贴板粘贴它们(非常像在C#中将图像插入RTF文档 )。 现在的麻烦是如何提取图像。 如何以编程方式选择RichTextBox中的图像? 我是否必须通过剪贴板返回? 就像是: IDataObject data = Clipboard.GetDataObject(); Clipboard.Clear(); _RichTextBox.Select(/* The image */); _RichTextBox.Copy(); Image img = Clipboard.GetImage(); img.Save(“myImage.png”, System.Drawing.Imaging.ImageFormat.Png); Clipboard.Clear(); Clipboard.SetDataObject(data); 有没有更优雅的解决方案,不需要通过剪贴板? 谢谢你的帮助!

GDI中的外部exception+错误保存特定图像

我需要从数据库中获取图像,所以我为它制作了一些代码。 问题是在某些图像中出现该错误,在其他图像中出现无效参数错误。 OleDbConnection l = new OleDbConnection(builder.ConnectionString); List listaImagens = new List(); List listaNomes = new List(); string nome = “”; try { OleDbDataAdapter adapter = new OleDbDataAdapter(“SELECT * FROM [Fotografias e Manuais de Equipamentos] WHERE ID >26 AND ID < 30", l); DataSet ds = new DataSet(); adapter.Fill(ds, "Fotografias e Manuais de Equipamentos"); //string […]

如何在C#中显示GIF图像的特定帧?

我想显示一个gif图像的框架。 我搜索并发现以下代码应该可以工作,但它不起作用。 它正确检测帧数,但它显示的是整个gif帧而不是指定的帧。 谢谢大家。 Image[] frames = new Image[36]; Image GG = Image.FromFile(@”C:\Users\Administrator\TEST C#\TEST2frame2\chef.gif”); FrameDimension dimension = new FrameDimension(GG.FrameDimensionsList[0]); // Number of frames int frameCount = GG.GetFrameCount(dimension); label1.Text = frameCount.ToString(); // Return an Image at a certain index GG.SelectActiveFrame(dimension, 1); frames[1] = ((Image)GG.Clone()); pictureBox1.Image = frames[1];

在c#中从memorystream保存为jpeg

我有一个如下所示的方法将图像保存为jpeg。 我希望保存所有具有相同高度和宽度的图片,而不会失真。 我怎样才能做到这一点? 请帮忙 public void SaveFileOnDisk(MemoryStream ms, string FileName) { try { string appPath = HttpContext.Current.Request.ApplicationPath; string physicalPath = HttpContext.Current.Request.MapPath(appPath); string strpath = physicalPath + “\\Images”; string WorkingDirectory = strpath; System.Drawing.Image imgSave = System.Drawing.Image.FromStream(ms); Bitmap bmSave = new Bitmap(imgSave); Bitmap bmTemp = new Bitmap(bmSave); Graphics grSave = Graphics.FromImage(bmTemp); grSave.DrawImage(imgSave, 0, 0, imgSave.Width, imgSave.Height); bmTemp.Save(WorkingDirectory […]

需要C#function将灰度TIFF转换为黑白(单色/ 1BPP)TIFF

我需要一个C#函数,它将采用8位灰度TIFF的Byte [],并返回1位(黑白)TIFF的字节[]。 我对使用TIFF很新,但一般的想法是我们需要将它们从灰度或彩色转换为黑白/单色/二进制图像格式。 我们通过WCF作为Byte []接收图像,然后我们需要将此转换为黑白,以便将它们发送到进行进一步处理的组件。 我们暂时没有计划将它们保存为文件。 作为参考,在我们的测试客户端中,这是我们创建Byte []的方式: FileStream fs = new FileStream(“test1.tif”, FileMode.Open, FileAccess.Read); this.image = new byte[fs.Length]; fs.Read(this.image, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); ——– ———更新 我认为这里可能有不止一个好的答案,但我们最终使用了CodeProject站点中的代码,并添加了以下方法来重载convert函数以接受Byte []以及位图: public static Byte[] ConvertToBitonal(Byte[] original) { Bitmap bm = new Bitmap(new System.IO.MemoryStream(original, false)); bm = ConvertToBitonal(bm); System.IO.MemoryStream s = new System.IO.MemoryStream(); bm.Save(s, System.Drawing.Imaging.ImageFormat.Tiff); return s.ToArray(); }

如何将.dds文件加载到图片框中?

如何在C#中将.dds纹理文件加载为图像? 我能找到的谷歌没什么用处。 你给我的样本信息越多,我理解它就越好。

“无法将字符串转换为ImageSource。”我该怎么做?

private void HeroMouseEnter(object sender, MouseEventArgs e) { ((Image)sender).Source = GetGlowingImage(((Image)sender).Name); } public ImageSource GetGlowingImage(string name) { switch (name) { case “Andromeda”: return “HeroGlowIcons/64px-Andromeda.gif”; default: return null; } } 我只是想根据鼠标输入的位置制作一个更改图像的事件。 但我无法做到这一点。 编辑:我在Windows窗体中执行此操作,它100%像我想要的那样工作。 我怎么能在WPF中翻译这样的东西? void HeroMouseEnter(object sender, EventArgs e) { ((PictureBox)sender).Image = GetGlowingImage(((PictureBox)sender).Name); } public Image GetGlowingImage(string name) { switch (name) { case “Andromeda”: return Properties.Resources._64px_Andromedahero___copia; case […]