Sparse coding ensures to express the data in terms of a few nonzero dictionary elements. Since the data size is large for hyperspectral imagery, it is reasonable to use sparse coding for compression of hyperspectral images. In this paper, a hyperspectral image compression method is proposed using a discriminative online learning-based sparse coding algorithm. Compression and anomaly detection tests are performed on hyperspectral images from the AVIRIS dataset. Comparative rate-distortion analyses indicate that the proposed method is superior to the state-of-the-art hyperspectral compression techniques.