# Problems saving png file with cinder compiled with vs2022

**URL:** <https://discourse.libcinder.org/t/problems-saving-png-file-with-cinder-compiled-with-vs2022/2137>\
**Category:** Using Cinder\
**Created:** [September 23, 2025, 9:50am UTC](https://discourse.libcinder.org/t/problems-saving-png-file-with-cinder-compiled-with-vs2022/2137 "2025-09-23T09:50:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discourse.libcinder.org/u/Ivan)\
**Post date:** [September 23, 2025, 9:50am UTC](https://discourse.libcinder.org/t/problems-saving-png-file-with-cinder-compiled-with-vs2022/2137/1 "2025-09-23T09:50:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)\
**Post date:** [September 27, 2025, 6:49am UTC](https://discourse.libcinder.org/t/problems-saving-png-file-with-cinder-compiled-with-vs2022/2137/2 "2025-09-27T06:49:13Z")

</div>

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

> **[Cinder/samples/SaveImage at master · cinder/Cinder](https://github.com/cinder/Cinder/tree/master/samples/SaveImage)**
>
> Cinder is a community-developed, free and open source library for professional-quality creative coding in C++. - cinder/Cinder

- Gabor

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discourse.libcinder.org/u/Ivan)\
**Post date:** [September 29, 2025, 12:41pm UTC](https://discourse.libcinder.org/t/problems-saving-png-file-with-cinder-compiled-with-vs2022/2137/3 "2025-09-29T12:41:28Z")

</div>

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:

```cpp
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

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [September 30, 2025, 12:25am UTC](https://discourse.libcinder.org/t/problems-saving-png-file-with-cinder-compiled-with-vs2022/2137/4 "2025-09-30T00:25:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discourse.libcinder.org/u/Ivan)\
**Post date:** [October 4, 2025, 4:09pm UTC](https://discourse.libcinder.org/t/problems-saving-png-file-with-cinder-compiled-with-vs2022/2137/5 "2025-10-04T16:09:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [October 4, 2025, 5:26pm UTC](https://discourse.libcinder.org/t/problems-saving-png-file-with-cinder-compiled-with-vs2022/2137/6 "2025-10-04T17:26:39Z")

</div>

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.
