Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to save image to photo album? #39

Open
waci11 opened this issue Jan 9, 2023 · 1 comment
Open

Is it possible to save image to photo album? #39

waci11 opened this issue Jan 9, 2023 · 1 comment

Comments

@waci11
Copy link

waci11 commented Jan 9, 2023

sorry , this is not a bug . but I really need to save image to photo album . it is a very important function for my app .

@mingganglee
Copy link

mingganglee commented Oct 17, 2023

Env

  • Godot 3.5.2

Reference

Description

Here's the code I took a screenshot of and saved it to an album, hope it helps!

Note: The get_viewport().get_texture().get_data() code interferes with the main process, so it's a good idea to add a new thread to handle this part.

gdscript

var image: Image = get_viewport().get_texture().get_data()
image.flip_y()
var img_base64 = Marshalls.raw_to_base64(image.save_png_to_buffer())
screen_tools.screenshot(img_base64)
Toast.toast("screenshot success", 1, Toast.pos.top)

objective-c

void ScreenTools::screenshot(const String &img_base64) {
	NSString *base64String = [NSString stringWithUTF8String:img_base64.utf8().ptr()];
	NSData *data = [[NSData alloc] initWithBase64EncodedString:base64String options:0];
	UIImage *image = [UIImage imageWithData:data];
	UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
	AudioServicesPlaySystemSound(1108);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants