We develop a method to estimate photometric metallicities by simultaneously fitting the dereddened colors u - g , g - r , r - i and i - z from the SDSS with those predicted by the metallicity-dependent stellar loci . The method is tested with a spectroscopic sample of main-sequence stars in Stripe 82 selected from the SDSS DR9 and three open clusters . With 1 per cent photometry , the method is capable of delivering photometric metallicities precise to about 0.05 , 0.12 , and 0.18 dex at metallicities of 0.0 , - 1.0 , and -2.0 , respectively , comparable to the precision achievable with low-resolution spectroscopy at a signal-to-noise ratio of 10 . We apply this method to the re-calibrated Stripe 82 catalog and derive metallicities for about 0.5 million stars of colors 0.3 < g - i < 1.6 mag and distances between 0.3 – 18 kpc . Potential systematics in the metallicities thus derived , due to the contamination of giants and binaries , are investigated . Photometric distances are also calculated . About 91 , 72 , and 53 per cent of the sample stars are brighter than r = 20.5 , 19.5 , and 18.5 mag , respectively . The median metallicity errors are around 0.19 , 0.16 , 0.11 , and 0.085 dex for the whole sample , and for stars brighter than r = 20.5 , 19.5 , and 18.5 mag , respectively . The median distance errors are 8.8 , 8.4 , 7.7 , and 7.3 per cent for the aforementioned four groups of stars , respectively . The data are publicly available . Potential applications of the data in studies of the distribution , ( sub ) structure , and chemistry of the Galactic stellar populations , are briefly discussed . The results will be presented in future papers .