One possibility is to use cancel. (EDIT: Replaced \textcolor by color, big thanks to Werner!)
\documentclass{article}
\usepackage{cancel,xcolor}
\newcommand{\Cancel}[2][black]{{\color{#1}\cancel{\color{black}#2}}}
\begin{document}
\[x~=~\Cancel[blue]{2}+\Cancel[red]{1}-
\Cancel[blue]{2}-\Cancel[red]{1}\]
\end{document}

Note, however, that an ambient color will be without effect, i.e. instead of {\color{green}\Cancel[blue]{2}+\Cancel[red]{1}} you'd need to do \Cancel[blue]{\color{green} 2}+\Cancel[red]{\color{green} 1} unfortunately. I guess that there will be better ways and am looking forward to learn new tricks.
EDIT: Just for fun: a TikZ version. The option X will do an \xcancel sort of cross out.
\documentclass{article}
\usepackage{tikz}
\newif\ifCancelX
\tikzset{X/.code={\CancelXtrue}}
\newcommand{\Cancel}[2][]{\relax
\ifmmode%
\tikz[baseline=(X.base),inner sep=0pt] {\node (X) {$#2$};
\tikzset{#1}
\draw[#1,overlay,shorten >=-2pt,shorten <=-2pt] (X.south west) -- (X.north east);
\ifCancelX
\draw[#1,overlay,shorten >=-2pt,shorten <=-2pt] (X.north west) -- (X.south east);
\fi}
\else
\tikz[baseline=(X.base),inner sep=0pt] {\node (X) {#2};
\tikzset{#1}
\draw[#1,overlay,shorten >=-2pt,shorten <=-2pt] (X.south west) -- (X.north east);
\ifCancelX
\draw[#1,overlay,shorten >=-2pt,shorten <=-2pt] (X.north west) -- (X.south east);
\fi}%
\fi}
\begin{document}
\[x~=~\Cancel[blue,X]{2}+\Cancel[red]{\frac{1}{2}}-
\Cancel[blue]{2}-\Cancel[red, line width=1pt]{\frac{1}{2}}\]
\end{document}

c... ;-) (Note that of course an ambient color will be without effect, i.e. instead of\textcolor{green}{\Cancel[blue]{2}+\Cancel[red]{1}you'd need to do\Cancel[blue]{\textcolor{green}{2}}+\Cancel[red]{\textcolor{green}{1}}unfortunately. ) – Aug 13 '18 at 22:20\textcolor{<color>}{<stuff>}, rather use{\color{<color}<stuff>}. This translates your implementation to work within math and text mode, rather than currently just in text mode. Try with\Cancel[blue]{\frac{1}{2}}... – Werner Aug 13 '18 at 22:25Xin the options. I don't know to do it otherwise in one command. Of course, your suggestion works and is much more minimal than loading TikZ. – Aug 14 '18 at 04:10