Wirelessly posted (Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7)
You can take it apart if you think you can take out the logic board, it's easy to me but I have repair experience. You can look on YouTube for iPhone 3GS disassembly videos. The camera is attached to the logic board.
Once you know how it takes like a 5 mins. Basically you unscrew the bottom screws then suction cup the screen to take it off then disconnect a few connectors and unscrew more screws inside and the logic board will come right out with the camera and you can clean it.
If it doesn't fix the problem take it to the genius bar.