1. An image encoding apparatus for encoding image data, comprising: an input unit which inputs multi-valued image data to be encoded and attribute data of respective pixels constituting the multi-valued image data; a determination unit which determines an area including a character/line drawing in the multi-valued image data, as a foreground image area, based on the input multi-valued image data; a foreground image generation unit which generates foreground image data in binary representation, having character/line drawing pixels constituting the character/line drawing and non-character/line drawing pixels other than the character/line drawing pixels, from the multi-valued image data in the foreground image area determined by said determination unit; a first encoding unit which lossless-encodes the foreground image data generated by said foreground image generation unit; a background image generation unit which generates multi-valued background image data by replacing a value of a multi-valued pixel, in a position of said character/line drawing pixel in said multi-valued image data inputted by said input unit, with a replacement value calculated by referring to a value of a multi-valued pixel in a position of said non-character/line drawing pixel, based on the foreground image data generated by said foreground image generation unit; a second encoding unit which lossy-encodes the background image data generated by said background image generation unit by performing frequency transformation and quantization; a mask unit which masks attribute data for a pixel within said foreground image area obtained by said determination unit with a predetermined value, while maintaining attribute data for a pixel without said foreground image area; and a third encoding unit which lossless-encodes attribute data after masking processing by said mask unit.