Problems saving png file with cinder compiled with vs2022

Hello,

I am very new to Cinder. I decided to try it after reading the very good documentation available here. I downloaded the repo and compiled the solution with vs2022 using the vs2019 project.I just needed to add a const for operator== of CRect

The first test i made is a small project that generates a surface, fills it with a perlin noise and the writes the image as png. My problems start in the writeImage command.
if i create the output path using

getDocumentsDirectory() / “output.png"

everything works fine.

if the path is constructed without using that function, non matter the path ( I tried many existing path in my computer, and the same given by getDocumentsDirectory) the error Could not create target for image with extension: png appears.

Can you tell me what i am doing wrong?

sorry for my english

thank you

Can you try the SaveImage sample and see if it works?

  • Gabor

Hello Gabor,

After trying the sample project you suggest I was able to reproduce the error.
The image is successfully saved only if getHomeDirectory is called.

This is my test code the run function:

void run() {
  const int width = 512;
  const int height = 512;
  Surface8u surface(width, height, false);

  Perlin perlin;perlin.setSeed(123);       
  perlin.setOctaves(4); 
  Surface8u::Iter iter = surface.getIter();

  while (iter.line()) {
   while (iter.pixel()) {
       float x = iter.x() / (float)width;
       float y = iter.y() / (float)height;
       float noiseValue = perlin.fBm(x * 5.0f, y * 5.0f);

       uint8_t color = (uint8_t)(math<float>::clamp((noiseValue + 1.0f) * 0.5f *255.0f, 0.0f, 255.0f));

       iter.r() = color;
       iter.g() = color;
       iter.b() = color;
    }

  }

  try {

     //THIS LINE IS NEEDED!!!!!!!
     getHomeDirectory();

      std::filesystem::path home(L"C:\\Personal\\");
      writeImage(home / "cinder" / "output.png", surface);



       std::cout << "Image successfully saved" << std::endl;

   } 
   catch (const std::exception& e) {
      std::cout << "Error on saving image: " << e.what()<< std::endl;
   }
} 

if the call getHomeDirectory() is commented, the error is raised.

Can you tell me why? What happens inside the getHomeDirectory function? Do I need to initialize something?

thank you

Ivan

Where are you calling ::run from? getHomeDirectory()calls into Platform::get, which on windows, initialises WIC which is used for writing and reading image file formats, so uninitialised WIC would account for the error you’re seeing. However, as long as you’re calling your run function from anywhere within a derived cinder app class, PlatformMsw should always be correctly initialised. Is your project/app set up similarly to how cinder expects, or are you just trying to use cinder functions from your own main or something?

Sorry for the delay in the response. I use the functions from my own main function.

Yep, that makes sense. I would suggest making a regular cinder app and calling these functions from your overridden ::setup and everything should be fine from there.