Reputation:
i am trying to add a Bitmap Library to visual studio 2015 when i added header file
#include "bitmap_image.hpp"
underneath the header file a red line and it showing "cannot open source file" in the error window i am attaching a link to website i tried this way but its not help - > https://stackoverflow.com/questions/27466571/add-hpp-file-type-to-visual-studio#
library link http://www.partow.net/programming/bitmap/index.html
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include "bitmap_image.hpp"
int main(){
bitmap_image image("input.bmp");
if (!image)
{
printf("Error - Failed to open: input.bmp\n");
return 1;
}
unsigned int total_number_of_pixels = 0;
const unsigned int height = image.height();
const unsigned int width = image.width();
for (std::size_t y = 0; y < height; ++y)
{
for (std::size_t x = 0; x < width; ++x)
{
rgb_t colour;
image.get_pixel(x, y, colour);
if (colour.red >= 111)
total_number_of_pixels++;
}
}
printf("Number of pixels with red >= 111: %d\n", total_number_of_pixels);
return 0;
}
header is too large i can't paste it here its in the link
Upvotes: 12
Views: 1491
Reputation: 38
If Visual Studio shows "cannot open source file" for bitmap_image.hpp
(denoted by the red squiggles) , it usually means the file can't be found. Make sure bitmap_image.hpp
is in your project directory or a folder included in the project.
To resolve this, I'd recommend to create a folder called external
(or similar) in your project and place the bitmap
folder inside.
Then, add the external
folder to your project's include path in Project Properties > Configuration Properties > C/C++ > General > Additional Include Directories.
Your setup should look like this
MyProject/
├── external/
│ └── bitmap/
│ └── bitmap_image.hpp
├── src/
│ └── main.cpp
With this setup, include the file like this:
#include "bitmap/bitmap_image.hpp"
Alternatively, if you add the bitmap
folder directly to the include path
MyProject/
├── bitmap/
│ └── bitmap_image.hpp
├── src/
│ └── main.cpp
use:
#include "bitmap_image.hpp"
Upvotes: 0
Reputation: 1
To do so you have to click
Upvotes: -1