1

我正在尝试在 Visual Studio C++ 2008 中创建一个非常简单的“计数”,例如数组。目标是制作 256 位灰度图像的直方图(不显示它)。

#pragma once
using namespace System::Collections::Generic;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System;

ref class Histograma
{
public:

    Histograma(void);
    Histograma(System::IO::FileStream^ archivo, List<Panel^>^ paneles);
    Array^ ejecutar();

private:
    Array ^resultado;
    Bitmap^ imagen;
};

以及这里的实现

#include "StdAfx.h"
#include "Histograma.h"

Histograma::Histograma(void)
{
    resultado = Array::CreateInstance(int::typeid,256);
}

Histograma::Histograma(System::IO::FileStream^ archivo, List<Panel^> ^paneles)
{
    Histograma();
    imagen = gcnew Bitmap(archivo);
}

Array^ Histograma::ejecutar()
{
    System::Byte valor;
    for(int x=0; x < imagen->Width ; x++)
    {
        for(int y=0; y < imagen->Height ; y++)
        {
            valor = imagen->GetPixel(x,y).ToArgb();
            resultado[valor]++;
        }
    }
    return resultado;
}

我收到 c2039 错误:'default' 不是 'System::Array' 的成员

有任何想法吗?这必须是我做错的非常简单的事情,但我不知道会是什么。

提前致谢

4

1 回答 1

1

将声明更改为:

array<int> ^resultado;

在构造函数中:

resultado = gcnew array<int>(256);

编辑

您还可以保留原始System::Array声明,而是使用这种乏味的语法:

resultado->SetValue((int)(resultado->GetValue(valor)) + 1, valor);
于 2013-08-12T22:49:40.443 回答