Open zjian361 opened 3 weeks ago
I check the breakpoint,Abnormalities occur in 'vips_foreign_find_load(filename) ".
VImage
VImage::new_from_file(const char *name, VOption *options)
{
char filename[VIPS_PATH_MAX];
char option_string[VIPS_PATH_MAX];
const char *operation_name;
VImage out;
vips__filename_split8(name, filename, option_string);
if (!(operation_name = vips_foreign_find_load(filename))) {
delete options;
throw VError();
}
call_option_string(operation_name, option_string,
(options ? options : VImage::option())
->set("filename", filename)
->set("out", &out));
return out;
}
Hello @zjian361,
You need to call vips_init()
. Did you see the examples?
https://github.com/libvips/libvips/blob/master/cplusplus/examples/resize.cpp
First of all, The VIPS library needs to be initialized before using any of its functions. This is usually done with VIPS_INIT(argv[0]);. Without this initialization, the library may not function correctly.
Also, the variable VipsImage in; is declared but not used. This is unnecessary and can be removed.
Also, the commented-out functions like vips_image_get_n_pages, vips_image_get_width, and vips_image_get_height are part of the older VIPS C API. Since you're using the C++ API (VImage), you should use the corresponding methods available in the VImage class.
This is more better:
#include <vips/vips8>
#include <iostream>
int main(int argc, char *argv[]) {
if (VIPS_INIT(argv[0])) {
vips_error_exit(nullptr);
return 1;
}
try {
// Load the image using VImage class
vips::VImage image = vips::VImage::new_from_file("E:\\merge.ome.tif");
// Print image properties
std::cout << "Image width: " << image.width() << std::endl;
std::cout << "Image height: " << image.height() << std::endl;
// If it's a multi-page image (like a TIFF), print the number of pages
if (image.hasalpha()) {
std::cout << "Number of pages: " << image.get_typeof(VIPS_META_N_PAGES) << std::endl;
}
} catch (const vips::VError& e) {
std::cerr << "Failed to process the image: " << e.what() << std::endl;
vips_shutdown();
return 1;
}
vips_shutdown();
return 0;
}
Hello @zjian361,
You need to call
vips_init()
. Did you see the examples?https://github.com/libvips/libvips/blob/master/cplusplus/examples/resize.cpp
Thank you!
First of all, The VIPS library needs to be initialized before using any of its functions. This is usually done with VIPS_INIT(argv[0]);. Without this initialization, the library may not function correctly.
Also, the variable VipsImage in; is declared but not used. This is unnecessary and can be removed.
Also, the commented-out functions like vips_image_get_n_pages, vips_image_get_width, and vips_image_get_height are part of the older VIPS C API. Since you're using the C++ API (VImage), you should use the corresponding methods available in the VImage class.
This is more better:
#include <vips/vips8> #include <iostream> int main(int argc, char *argv[]) { if (VIPS_INIT(argv[0])) { vips_error_exit(nullptr); return 1; } try { // Load the image using VImage class vips::VImage image = vips::VImage::new_from_file("E:\\merge.ome.tif"); // Print image properties std::cout << "Image width: " << image.width() << std::endl; std::cout << "Image height: " << image.height() << std::endl; // If it's a multi-page image (like a TIFF), print the number of pages if (image.hasalpha()) { std::cout << "Number of pages: " << image.get_typeof(VIPS_META_N_PAGES) << std::endl; } } catch (const vips::VError& e) { std::cerr << "Failed to process the image: " << e.what() << std::endl; vips_shutdown(); return 1; } vips_shutdown(); return 0; }
Thank you!I have already resolved this problem. Now I want to merge three page images into one three channel color image. First of all,I try to use “bandjoin” to achieve,but with no success,so I used OpenCV to achieve it.Can you provide an example to me?
I Rebuild libvips-cpp.dll and libvips.lib.