Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 09-18-2008, 03:38 PM   #1
thetim
Registered User
 
Join Date: Sep 2008
Posts: 3
Default Inaccurate pixel values using getPixel

Hello,

I'm writing an applicaton which acts based on different colour values of pixels in a png image created in Microsoft paint. However, when I load the image into a BitmapData object, and then parse through the pixels reading their values using getPixel() or getPixel32() (I've tried both) I seem to be getting values which are slightly inaccurate compared to what was saved. For example a pure white pixel which should be read as 0xFFFFFFFF often comes out as 0xFFFFFFFE. The behaviour of the program is dependent on the exact value of the pixel so these errors usually break it.

Does anyone know why this is? Sometimes the problem is intermittent so seems fixed but actually isn't. Is it to do with the PNG format? I thouht png was lossless so should deliver accurate pixel values at all times?

Any help would be much appreciated.

Thanks
thetim is offline   Reply With Quote
Old 09-18-2008, 03:44 PM   #2
xxneon
Super Moderator
 
xxneon's Avatar
 
Join Date: Dec 2006
Location: Amish Country, PA
Posts: 8,570
Send a message via ICQ to xxneon Send a message via AIM to xxneon Send a message via MSN to xxneon Send a message via Skype™ to xxneon
Default

The only thing I can think that might cause the inconsistancy is if you capture the pixel for a object that has children not positioned at whole pixels themselves.. like if its coordinates are x:2.5 y:10.3, just a thought..
__________________
Always optimizing...
xxneon is offline   Reply With Quote
Old 09-18-2008, 03:44 PM   #3
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

are you loading the png from a file during runtime? Or did you import it into your library in Flash and then create an instance from the library?

If from the library, that would explain the differences. Flash, much to my chagrin, imports all images as JPG then converts them to be either JPG or PNG when compiling the SWF. For Flash, "lossless" actually means "lossless after we've already converted your image into a lossy format".

If from a file at runtime, it might possibly be from the PNG, but I wouldn't think so. You could try reloading the PNG into an image editor and check the pixels there again. I don't think Flash should be reporting invalid values for the colors if the image truely had different values.
__________________
(6)
senocular is offline   Reply With Quote
Old 09-18-2008, 04:51 PM   #4
thetim
Registered User
 
Join Date: Sep 2008
Posts: 3
Default

Thanks very much for your help. The pngs are being loaded from external files. However it seems someone else has been having the same problems:

http://www.actionscript.org/forums/s....php3?t=169621

I can only assume that Flash is applying some kind of compression within the bitmapdata class - to save on memory perhaps? Or perhaps it's doing some kind of weird anti-aliasing that we don't know about, which is altering the values.

Either way it looks like I'll have to find some alternative data storage...
thetim is offline   Reply With Quote
Old 09-18-2008, 05:06 PM   #5
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

PNG is lossles, but, the editing tool may use palette with the fixed colors to generate a PNG. Almost always PNGs do not use the palette, but, still there's an option for it, I can imagine, that if you'll have a file with only few different colors, than the editing tool may automaticaly switch to use the palette (you'll have to check the input in another, more advanced editor to make sure the PNG was saved exactly as you wanted).
Also, if you transformed the image and used BitmapData.draw() on the transformed one, than there may be difference.
Oh, and by thee wee %) Have you saved your PNG as 8 bits per channel or 16 bits per channel?
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it

Last edited by wvxvw; 09-18-2008 at 05:16 PM.
wvxvw is offline   Reply With Quote
Old 03-23-2012, 08:31 AM   #6
jmim
Registered User
 
Join Date: Mar 2012
Posts: 1
Default Window Ms Paint Error

I had this problem.
Turns out that when making a bitmap with MSPaint,
it only uses 0-254 for the pixel values.
I don't care what it's color sampler says, it lies.

I made a level editor that stored it's information in a PNG
and it also relied on exact colors. I ran into this problem
and it drove me crazy.
jmim is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
major glitch with getPixel()? infernosnow ActionScript 3.0 2 05-05-2008 05:07 AM
Loading values from XML - how to deal with empty values, from a display perspective repenttokyo ActionScript 2.0 4 03-07-2006 03:10 AM
Pixel - I Love Pixel !!! jumikan ActionScript 1.0 (and below) 8 08-17-2005 06:29 PM


All times are GMT. The time now is 02:08 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.