# Saving GL data to file

**URL:** <https://forums.fusetools.com/t/saving-gl-data-to-file/6907>\
**Category:** How-to Discussions\
**Created:** [February 21, 2017, 11:49pm UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907 "2017-02-21T23:49:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bjorn-Olav\_Strand](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/bjorn-olav_strand/32/583_2.png) [@Bjorn-Olav\_Strand](https://forums.fusetools.com/u/Bjorn-Olav_Strand)\
**Post date:** [February 21, 2017, 11:49pm UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907/1 "2017-02-21T23:49:16Z")

</div>

Hi,

I’m trying to save GL data to an image file.

I have this:

```auto
	public void SaveUno() {
		int size = (int) ActualSize[0] * (int) ActualSize[1] * 4;
		var data = new byte[size];
		int w = (int) ActualSize[0];
		int h = (int) ActualSize[1];
		OpenGL.GL.ReadPixels(0,0, w, h, GLPixelFormat.Rgba, GLPixelType.UnsignedByte, data);
		SaveImage(data, size, w, h, "/Users/bolav/Image.png");
	}

	public void SaveImage(byte[] data, int size, int w, int h, string fn)
	@{
		uBase::Buffer *buf = uBase::Buffer::CopyFrom(data, size);

		uImage::Bitmap *bmp = new uImage::Bitmap(w, h, uImage::FormatRGBA_8_8_8_8_Int, buf, 0, 0);
		uBase::String tfn = "/Users/bolav/Image.png";
		uImage::Png::Save(tfn, bmp);
	@}

```

But I have some issues.

The `data` array does not seem to get the actual data, so I’m doing something wrong there.

How can I convert from `uString` to `uBase::String`?

The Png save crashes, so I’m certain that there are some errors with creating the bitmap or something around there.

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [February 22, 2017, 12:14pm UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907/2 "2017-02-22T12:14:09Z")

</div>

`ActualSize` is in points, not pixels… that could be the issue?

---

<div class="post-metadata">

**Author:** ![Bjorn-Olav\_Strand](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/bjorn-olav_strand/32/583_2.png) [@Bjorn-Olav\_Strand](https://forums.fusetools.com/u/Bjorn-Olav_Strand)\
**Post date:** [February 22, 2017, 12:29pm UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907/3 "2017-02-22T12:29:42Z")

</div>

`Open.GL.ReadPixels` returns 255 for all bytes, so I think I have to attach it or something to get actual data. Also `uImage::Png::Save` just crashes.

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [February 22, 2017, 12:32pm UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907/4 "2017-02-22T12:32:37Z")

</div>

What element are you trying to read data from?

MapViews are known to not work, becuase of a DRM mechanism in the OS.

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [February 22, 2017, 12:34pm UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907/5 "2017-02-22T12:34:26Z")

</div>

Also, what framebuffer have you attached?

`Png::Save` will crash with your above code because you are interpreting points as pixels (i.e. your buffer is too small)

---

<div class="post-metadata">

**Author:** ![kusma](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kusma/32/595_2.png) [@kusma](https://forums.fusetools.com/u/kusma)\
**Post date:** [February 22, 2017, 12:48pm UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907/6 "2017-02-22T12:48:55Z")

</div>

You might also want to do `GL.PixelStore(GLPixelStoreParameter.PackAlignment, 1);` to avoid OpenGL computing padding at the end of each scanline.

---

<div class="post-metadata">

**Author:** ![Bjorn-Olav\_Strand](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/bjorn-olav_strand/32/583_2.png) [@Bjorn-Olav\_Strand](https://forums.fusetools.com/u/Bjorn-Olav_Strand)\
**Post date:** [February 22, 2017, 4:38pm UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907/7 "2017-02-22T16:38:23Z")

</div>

I’ve created a Control that you can draw on. I’m trying to dump it to an image. I’ve not connected any framebuffer, the whole save code is what you see. I understand that this is the reason it’s not working, and was hoping for a full example.

On CMake the error from Png::Save is `Unsupported PNG Format: FormatRGBA_8_8_8_8_Int`. It might be the same error on the other platforms.

---

<div class="post-metadata">

**Author:** ![robert.luisi](https://avatars.discourse-cdn.com/v4/letter/r/c57346/32.png) [@robert.luisi](https://forums.fusetools.com/u/robert.luisi)\
**Post date:** [March 10, 2017, 9:34pm UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907/8 "2017-03-10T21:34:56Z")

</div>

Hello!

I’ve been trying to save two pictures that get imported from camera roll as one PNG. So i have a canvas (DockPanel) with two movable pictures in it. These need to be saved together as one PNG.

So, how can i use the framebuffer class to generate a PNG file for me? Have you figured this out yet Bjørn-Olav?

Thanks so much!

---

<div class="post-metadata">

**Author:** ![kusma](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kusma/32/595_2.png) [@kusma](https://forums.fusetools.com/u/kusma)\
**Post date:** [March 29, 2017, 2:27pm UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907/9 "2017-03-29T14:27:28Z")

</div>

@bolav: The Png::Save issue is because we require `FormatRGBA_8_8_8_8_UInt_Normalize` instead of `FormatRGBA_8_8_8_8_Int` in the png-saver.

---

<div class="post-metadata">

**Author:** ![Bjorn-Olav\_Strand](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/bjorn-olav_strand/32/583_2.png) [@Bjorn-Olav\_Strand](https://forums.fusetools.com/u/Bjorn-Olav_Strand)\
**Post date:** [April 17, 2017, 10:35am UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907/10 "2017-04-17T10:35:59Z")

</div>

Erik helped me solve this, and created these great components!

> **[bolav/fuse-signature](https://github.com/bolav/fuse-signature)**
>
> fuse-signature - Signature pad for Fuse (also includes a Panel that saves to PNG)

---

<div class="post-metadata">

**Author:** ![jesusmartinoza](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/jesusmartinoza/32/659_2.png) [@jesusmartinoza](https://forums.fusetools.com/u/jesusmartinoza)\
**Post date:** [April 17, 2017, 4:41pm UTC](https://forums.fusetools.com/t/saving-gl-data-to-file/6907/11 "2017-04-17T16:41:51Z")

</div>

Great components!! I’m impressed by that Uno level.  
A month ago we had to go native because Fuse did not have a component like this
