Skip to content

rendertexture's savetoFile problem #16113

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

Closed
reasonMix opened this issue Jul 13, 2016 · 15 comments
Closed

rendertexture's savetoFile problem #16113

reasonMix opened this issue Jul 13, 2016 · 15 comments
Assignees

Comments

@reasonMix
Copy link

when draw a label to the render texture and call the savetoFile to create the png file.the png file have white border on ios platform. because the label use ALPHA_NON_PREMULTIPLIED blend mode. and on ios platform the image-ios.mm savetoFile only use the kCGImageAlphaPremultipliedLast flag

@ricardoquesada
Copy link
Contributor

thanks. could you post the code to reproduce it? thanks.

@reasonMix
Copy link
Author

@ricardoquesada
local text = cc.Label:createWithTTF('hello world','font/yours.ttf',40)

local target = cc.RenderTexture:create(winSize.width, winSize.height, 2)
target:beginWithClear(0,0,0,0)
text:setPosition(winSize.width / 2,winSize.height/2)
text:visit()
target:endToLua()
target:saveToFile('aaa.png',1)

@ricardoquesada ricardoquesada self-assigned this Jul 15, 2016
@ricardoquesada
Copy link
Contributor

ricardoquesada commented Jul 21, 2016

Thanks. But I couldn't reproduce it. The image that I got on an iPhone is the following, and it seems to be Ok. is that right? I'm using C++ code instead of Lua though.

UPDATE: Image had the letters in white... generating a new one in red (see below)

@reasonMix
Copy link
Author

@ricardoquesada where is the png file,i can't seen it

ricardoquesada added a commit to ricardoquesada/cocos2d-x that referenced this issue Jul 21, 2016
@ricardoquesada
Copy link
Contributor

ricardoquesada commented Jul 21, 2016

@reasonMix Uploading it again... In case it doesn't work, this is the test case that I created:
#16180

issue16113

I couldn't find any white border in this image.

ricardoquesada added a commit to ricardoquesada/cocos2d-x that referenced this issue Jul 21, 2016
@reasonMix
Copy link
Author

@ricardoquesada please paste your code,do you create the label with ttf?

@ricardoquesada
Copy link
Contributor

ricardoquesada commented Jul 21, 2016

@reasonMix: the code is here, in this Pull Request: #16180

@reasonMix
Copy link
Author

@ricardoquesada i am wrong,in mac platform,the png file will have a black border

ricardoquesada added a commit that referenced this issue Jul 21, 2016
@ricardoquesada
Copy link
Contributor

@reasonMix this is the image from the Mac:
issue16113

@reasonMix
Copy link
Author

@ricardoquesada use the white color,will see the black border
issue16113

@ricardoquesada
Copy link
Contributor

@reasonMix thanks. I was able to reproduce it.
I think this is happening because the RenderTexture's texture is using premultiplied alpha internally, but when we save the PNG, we save it the data (premultiplied) as if it were unpremultiplied. So, you open the PNG... the editor thinks it is pure RGBA, but it is RGBA-premultiplied.

This does not happen on iOS because iOS is using its own function to save to PNG, and it is passing the parameter kCGImageAlphaPremultipliedLast to the bitmap info.

I think I have to unpremultiplied it manually before saving it.

@reasonMix
Copy link
Author

@ricardoquesada yes,but if use a sprite to render to target,the PNG file is fine no border,so maybe this is not easy solve this problem

@ricardoquesada
Copy link
Contributor

@reasonMix makes sense what you are saying... I've been trying to fix this bug doing different stuff and I couldn't fix it. I tried to unpremultiplied alpha and other stuff and didn't work.
perhaps I should take a look at how the ttfs are being created.

I'll take a look at this again this monday with fresh eyes.

@drelaptop
Copy link
Contributor

#9393 looks like a workaround to fix this alpha issues.

so the defect is we treat the data (premultiplied) as if it were unpremultiplied.

as I confirmed one way to fix it is force set the internal texture of RenderTexture premultiplied value to true in this situation.

@rh101
Copy link
Contributor

rh101 commented Jul 22, 2019

@minggo This issue can probably be closed given that #19782 was merged in to allow saving non-premultiplied images.

@minggo minggo closed this as completed Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants