In this paper, an improved lossless intracoding algorithm based on H.264/AVC framework is proposed. In the proposed algorithm, two contributions have been made. One is that samples in a macroblock (MB)/block are hierarchically predicted instead of using block-based prediction as a whole. More specifically, four groups are extracted from the samples in an macroblock/block. Samples in the first group are first predicted based on directional intraprediction method, and then the samples in other groups are predicted using the samples in the first group as the references. As a result, the information left in the residual block can be reduced since the samples can be accurately predicted by using nearer references. The other contribution is that two coding modes are designed to efficiently encode the resulting residual block. A better coding mode can be selected based on the rate optimization. Experimental results show that compared with other methods in the literature the proposed algorithm gives a much better compression performance.