找不到GetPixel方法

编程入门 行业动态 更新时间:2024-10-27 16:39:02
本文介绍了找不到GetPixel方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个简单的程序,并且其中包含System.Drawing,并且我无法使用GetPixel()方法.它说找不到.可能是什么原因?

I have a simple program, and ive included System.Drawing and I do not have an ability to use the GetPixel() method. It says its not found. What could be the reason for this?

using System.Drawing; namespace isolatepixels { class Program { static void Main(string[] args) { System.Drawing.Image image1 = System.Drawing.Image.FromFile(@"C:\1.jpg"); int x, y; // Loop through the images pixels to reset color. for (x = 0; x < image1.Width; x++) { for (y = 0; y < image1.Height; y++) { Color pixelColor = image1.GetPixel(x, y); Color newColor = Color.FromArgb(pixelColor.R, 0, 0); image1.SetPixel(x, y, newColor); } } } } }

推荐答案

正如汉斯在上面的评论中所说,如果您不这样做,则可以跳过Image.FromFile()并将文件名直接传递给Bitmap构造函数在任何地方使用图像本身.

As Hans says in his comment above, you can skip the Image.FromFile() and pass the filename directly to the Bitmap constructor if you are not using the image itself anywhere.

Image对象不包含这些方法,Graphics对象也不包含,但是Bitmap对象包含.因此,诀窍是使用 new Bitmap(image) 这样:

An Image object doesn't contain those methods and nor does a Graphics object, but a Bitmap object does. So the trick is to create a Bitmap from the image, using new Bitmap(image) like so:

// Don't need this: Image image1 = Image.FromFile(@"C:\1.jpg"); Bitmap bitmap = new Bitmap(@"C:\1.jpg"); // Save the image in JPEG format. bitmap.Save(@"C:\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp); int x, y; // Loop through the images pixels to reset color. for (x = 0; x < bitmap.Width; x++) { for (y = 0; y < bitmap.Height; y++) { Color pixelColor = bitmap.GetPixel(x, y); Color newColor = Color.FromArgb(pixelColor.R, 0, 0); bitmap.SetPixel(x, y, newColor); } }

请注意,Bitmap是从System.Drawing.Image派生的.

我认为应该起作用.

更多推荐

找不到GetPixel方法

本文发布于:2023-11-14 05:01:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586289.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   方法   GetPixel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!