  Shear estimation bias from galaxy detection and blending identification is
now recognized as an issue for ongoing and future weak lensing surveys.
Currently, the empirical approach to correcting for this bias involves
numerically shearing every observed galaxy and rerunning the detection and
selection process. In this work, we provide an analytical correction for this
bias that is accurate to subpercent level and far simpler to use. With the
interpretation that smoothed image pixel values and galaxy properties are
projections of the image signal onto a set of basis functions, we analytically
derive the linear shear responses of both the pixel values and the galaxy
properties (i.e., magnitude, size and shape) using the shear responses of the
basis functions. With these derived shear responses, we correct for biases from
shear-dependent galaxy detection and galaxy sample selection. With the
analytical covariance matrix of measurement errors caused by image noise on
pixel values and galaxy properties, we correct for the noise biases in galaxy
shape measurement and the detection/selection process to the second-order in
noise. The code used for this paper can carry out the detection, selection, and
shear measurement for ~1000 galaxies per CPU second. The algorithm is tested
with realistic image simulations, and we find, after the analytical correction
(without relying on external image calibration) for the detection/selection
bias of about $-4\%$, the multiplicative shear bias is $-0.12 \pm 0.10\%$ for
isolated galaxies; and $-0.3 \pm 0.1\%$ for blended galaxies with Hyper
Suprime-Cam observational condition.
