Синтаксические ошибки после включения & lt; Windows.h & gt;

Итак, в Интернете есть библиотека для обработки растровых файлов: «Bitmap_image.hpp». Это кажется хорошим и хорошо работает для моего проекта, до тех пор, пока я не попытаюсь включить «Windows.h» в свой проект. Компилятор не может идентифицировать как класс «bitmap_image», так и структуру «POINT», которые происходят из «bitmap_image.hpp» и «Windows.h» соответственно.

Я перепробовал все, что знаю, но проблема до сих пор не решена. Кроме того, когда попробуйте скомпилировать другой проект, который включает в себя только cstdio, bitmap_image.hpp а также Windows.h, оно работает.

Я использую Qt и вот весь код:

main.cpp

#include "mainwindow.h"#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtDebug>
#include "bitmap_image.hpp"#include <Windows.h>

using namespace std;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;

};

#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"#include "ui_mainwindow.h"
double compare_bitmap(bitmap_image& large, bitmap_image& small, unsigned int top_left_x, unsigned int top_left_y)
{
/*
Purpose:
compare two bitmaps and return the percentage of matched pixels

Description:
this function concerns the pixels in "large" only if it falls in this square--
top-left:     (top_left_x, top_left_y)
bottom-right: (top_left_x+small.width()-1, top_left_y+small.height()-1)

while all pixels in "small" will be concerned

Rules:
"large" should not be smaller than "small" in either dimensions
top_left_x should be ranged from 0 to (large.width()-small.width())
top_left_y should be ranged from 0 to (large.height()-small.height())
*/

if(large.width()<small.width() || large.height()<small.height()) return -1;
if(top_left_x<0 || top_left_x>(large.width()-small.width()) || top_left_y<0 || top_left_y>(large.height()-small.height())) return -2;

double pixel_count = 0;
double matched_count = 0;

for(unsigned int y=0; y<small.height(); ++y)
{
for(unsigned int x=0; x<small.width(); ++x)
{
if(large.get_pixel(top_left_x+x, top_left_y+y)==small.get_pixel(x,y)) ++matched_count;
++pixel_count;
}
}

return matched_count/pixel_count;
}

bool identify_bitmap(bitmap_image& large, bitmap_image& small, POINT& result_point, double min_match_percent = 1.0)
{
if(large.width()<small.width() || large.height()<small.height()) return false;

unsigned int p_x, p_y;
double match_percent = 0;

for(unsigned int y=0; y<(large.height()-small.height()+1); ++y)
{
for(unsigned int x=0; x<(large.width()-small.width()+1); ++x)
{
double percent = compare_bitmap(large, small, x, y);
if(percent>match_percent)
{
p_x = x;
p_y = y;
match_percent = percent;
}
}
}

if(match_percent<min_match_percent) return false;

result_point.x = p_x;
result_point.y = p_y;
return true;
}

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

string s = "capture_2.bmp";
bitmap_image image(s);

if(!image) qDebug()<<"failed";
else qDebug()<<"succeed";
}

MainWindow::~MainWindow()
{
delete ui;
}

1

Решение

Обновление: я просто нахожу решение для себя. Извините за пост.

Решение: Первый пост в этой теме заявил, что мы можем #define WIN32_LEAN_AND_MEAN незадолго до #include <Windows.h>

Хотя я не до конца понимаю причины …

0

Другие решения


По вопросам рекламы ammmcru@yandex.ru
Adblock
detector