Taking a photo of your completed ballot paper is, it seems, illegal in 44 of the 50 U. S. states. NPR reported on developments in New Hampshire, in which several voters who shared digital images of their completed ballots online are currently under investigation by the New Hampshire attorney-general's office. The offense of "taking a digital image or photograph of [your] ballot and distributing or sharing the image via social media or by any other means" carries with it a fine of up to $1000.
Laws prohibiting voters from copying or revealing the contents of their ballot hark back to the 1890s and the adoption of the Australian ballot. As part of the Australian ballot, voting became secret. Secrecy, long fought for in states like Massachusetts and California, was intended to prevent the bribing of voters (often with liquor). If no one could know how you voted, no one would want to bribe you to vote for them. After all, they might provide you copious amounts of free whisky, only to have you retreat to the secrecy of the ballot booth and vote for a different candidate.
The secrecy of the ballot could only be guaranteed if the state printed and provided the ballot AND voters were prevented from taking their ballot papers (or proof of how they voted) out of the polling place. It is for this reason that, in the age before voting machines, any vote in which the voter identified himself (or, after 1920, herself) was invalid.
Of course, no one in the 1890s could have foreseen the current trend of voters proudly sharing images of themselves with their ballots... and without any expectation of free whisky.