C# 获取GetPixel()函数中的错误
getpixel函数中出现错误…虽然使用了图像比较所需的所有名称空间…但我正在visual studio 2013中制作windows应用程序。。。。 我是否需要在任何地方定义getpixel()函数C# 获取GetPixel()函数中的错误,c#,visual-studio-2013,windows-phone-8.1,C#,Visual Studio 2013,Windows Phone 8.1,getpixel函数中出现错误…虽然使用了图像比较所需的所有名称空间…但我正在visual studio 2013中制作windows应用程序。。。。 我是否需要在任何地方定义getpixel()函数 using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using Syste
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using picture.Resources;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using Microsoft.Expression.Drawing;
namespace picture {
public partial class MainPage: PhoneApplicationPage {
// Constructor
public MainPage() {
InitializeComponent();
BitmapImage image1 = new BitmapImage();
image1.SetSource(Application.GetResourceStream(new Uri(@
"Assets/WP_20150925_09_20_03_Pro (2).jpg", UriKind.Relative)).Stream);
BitmapImage image2 = new BitmapImage();
image2.SetSource(Application.GetResourceStream(new Uri(@
"Assets/WP_20150925_09_20_03_Pro.jpg", UriKind.Relative)).Stream);
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private double get_Percentage_Method(WriteableBitmap wb1, WriteableBitmap wb2) {
var img1 = wb1;
var img2 = wb2;
// Validation of image size code
int width1 = img1.PixelWidth;
int width2 = img2.PixelWidth;
int height1 = img1.PixelHeight;
int height2 = img2.PixelHeight;
if ((width1 != width2) || (height1 != height2)) {
MessageBox.Show("Error: Images dimensions mismatch");
}
long diff = 0;
for (int i = 0; i < width1; i++) {
for (int j = 0; j < height1; j++) {
// get same position pixel of both WirtableBitmap Image object
Color color1 = wb1.GetPixel(i, j);
Color color2 = wb2.GetPixel(i, j);
// converting each value iGetPixelnto Integer
int r1 = (int) color1.R;
int g1 = (int) color1.G;
int b1 = (int) color1.B;
int r2 = (int) color2.R;
int g2 = (int) color1.G;
int b2 = (int) color1.B;
// calculating difference between RGB color value and adding it in Diff variable.
diff += Math.Abs(r1 - r2);
diff += Math.Abs(g1 - g2);
diff += Math.Abs(b1 - b2);
}
}
// Converting difference into percentage and then retun it.
double n = width1 * height1; //* 3;
double p = diff / n / 255.0;
MessageBox.Show("diff percent: " + (p * 100.0));
return (p * 100.0);
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
Net系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Navigation;
使用Microsoft.Phone.Controls;
使用Microsoft.Phone.Shell;
利用图片资源;
使用System.Windows.Media.Imaging;
使用System.Windows.Media;
使用Microsoft.Expression.Drawing;
名称空间图片{
公共部分类主页:PhoneApplicationPage{
//建造师
公共主页(){
初始化组件();
BitmapImage image1=新的BitmapImage();
image1.SetSource(Application.GetResourceStream(新Uri(@
“资产/WP_20150925_09_20_03_Pro(2.jpg)”,UriKind.Relative.Stream);
BitmapImage image2=新的BitmapImage();
image2.SetSource(Application.GetResourceStream(新Uri(@
“资产/WP_20150925_09_20_03_Pro.jpg”,UriKind.Relative.Stream);
//本地化ApplicationBar的示例代码
//BuildLocalizedApplicationBar();
}
私有双get_Percentage_方法(WriteableBitmap wb1,WriteableBitmap wb2){
var img1=wb1;
var-img2=wb2;
//图像大小代码的验证
int width1=img1.PixelWidth;
int width2=img2.PixelWidth;
int height1=img1.PixelHeight;
int height2=img2.PixelHeight;
如果((宽度1!=宽度2)| |(高度1!=高度2)){
MessageBox.Show(“错误:图像尺寸不匹配”);
}
长差=0;
对于(int i=0;i
您将在该行中得到一个错误
Color color1 = wb1.GetPixel(i, j);
这是因为wb1
的类型为WriteableBitmap
in
private double get_Percentage_Method(WriteableBitmap wb1, WriteableBitmap wb2)
这是因为WriteableBitmap
类没有GetPixel()
方法,如中所示。使用另一个类作为输入(例如,普通的图像
或位图
已经可以了),或者使用CopyPixels()
方法()解决它,在该方法中,您必须传递所需像素的坐标数组,与其他图像相关的参数。您的wb1/wb2属于类型,但没有函数GetPixel()
。我想你是在想
我建议再问一个关于如何获取像素的问题,感谢您的帮助……请详细说明……我已将WriteableBitmap类替换为BitmapImage类……但它仍然给出相同的错误……如何获取WriteableBitmap的像素?