libvips / libvips

A fast image processing library with low memory needs.
https://libvips.github.io/libvips/
GNU Lesser General Public License v2.1
9.53k stars 662 forks source link

libvips-42.dll throw exception #4091

Open zjian361 opened 3 weeks ago

zjian361 commented 3 weeks ago

I Rebuild libvips-cpp.dll and libvips.lib.

#include <stdio.h>
#include<vips/vips8>
using namespace vips;
int main()
{
    VipsImage *in;
    //double mean;
    //VipsImage *out;

    VImage ins = VImage::new_from_file("E:\\merge.ome.tif", NULL);
    //(in = vips_image_new_from_file("E:\\merge.ome.tif", NULL));
    //printf("image width = %d\n", vips_image_get_n_pages(in));
    //printf("image width = %d\n", vips_image_get_width(in));
    //printf("image width = %d\n", vips_image_get_height(in));
    //printf("image width = %d\n", vips_image_get_n_pages(in));

    //for (int i = 0; i < vips_image_get_n_pages(in); i++)
    //{
    //  in.
    //}
    return 0;
}

image

zjian361 commented 3 weeks ago

I check the breakpoint,Abnormalities occur in 'vips_foreign_find_load(filename) ". image

zjian361 commented 3 weeks ago
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;
}
jcupitt commented 3 weeks ago

Hello @zjian361,

You need to call vips_init(). Did you see the examples?

https://github.com/libvips/libvips/blob/master/cplusplus/examples/resize.cpp

dayoonasanya commented 3 weeks ago

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;
}
zjian361 commented 3 weeks ago

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!

zjian361 commented 3 weeks ago

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?