I can save the file on Android without any problem. However, the problem is when I load the file and add it to the scene again.
I got the black glow like the image below.
And here is the image that I expected.
NOTE: This is only happen on Android devices. (I’ve tested (All Amazon Kindle, NOOK HD & HD+, HTC)
Thanks!
Jate
P.S. I also found that when I use the newCCImage() from CCRenderTexture.
The color from the background get added to the image’s pixel where the alpha value isn’t 0 or 1 even though the alpha value of the background already set to 0.
Basically, when using CCRenderTexture the background need to be created using “beginWithClear(0, 0, 0, 0)” or begin().
Then, the background will get premultiply with any image you applied in between begin() and end() even though you set the alpha to 0.
When you use newCCImage() to copy the pixel out and save to png file. The image data will also have the premultiply.
On the iOS works because the UIImage seems to divide the premultiply alpha for you.
ANSWER:
So, I just get the raw image data then divide the color of each pixel with the result alpha. I’ve created a class derive from CCRenderTexture and create
The new function to divide the color pixel by the alpha.
Here is the equation for getting the original color without premultiply alpha. result = ColorResult/(Alpha1 + (Alpha2 * (1 - Alpha1);
In the CCRenderTexture function newCCImage() - Added this code between this->end() and if ( flipImage )
// HACKED Divide the alpha from color pixel
for (int i = 0; i < nSavedBufferHeight; i)
{
for
{
GLfloat As = * 4 3])/255.0;
if
{
GLfloat Rs = * 4])/255.0;
GLfloat Gs = * 4 1])/255.0;
GLfloat Bs = (GLfloat)(pTempData[(i * nSavedBufferWidth + j) * 4 + 2])/255.0;
I believe this problem seems to happen on all android devices as I’ve searched through.
It seems like when you trying to save and load the transparent PNG using CCImage, the image always get premultiply.
So, those will solution will do the trick if you don’t want premultiply image.
However, I only have tested it on Kindle Fire, Kindle HD 7, Kindle HD 9, Nook HD, Nook HD+, HTC One, and Mortola Tablet.
Using the fix posted by creiser, it isn’t working properly when an image contains a transparent color with yellow- yellow gets rendered to blue, peach colors are getting rendered with cyan, and oranges are getting rendered green. It’s really weird. It might have something to do with the GPU, but I haven’t been able to test on anything else than this Arduno. Anyone else have any funny resutls?
Remove the folder containing the resource if any other than “Resources” or inside “Resources” folder. Now add the folder of assets again, wait, make sure to select right target in “option” menu on Bottom left of selection window before you go for “Add” menu.
What was the Problem…?? even though the folder was available in project but the same was not logically available in you currently working target.