I want to prove that if a morphism of schemes $f:X\to Y$ is a closed immersion, then $f$ is affine.
Here's where I'm at.
If $Y=\bigcup_iV_i$ is an affine open cover, then $f(X)\cap V_i$ is an affine scheme, since it is a closed subset of the affine scheme $V_i$. Furthermore, the homeomorphism $X\stackrel{\sim}{\to} f(X)$ induces the homeomorphism $f^{-1}(V_i)\stackrel{\sim}{\to}f(X)\cap V_i$.
That still doesn't prove that $f^{-1}(V_i)$ is isomorphic to $f(X)\cap V_i$ as schemes, and I'm not sure how to prove it formally.
If $I(V):=\ker(f_V^\#)$, then $f$ being a closed immersion implies $\mathcal{O}_Y/I\simeq f_*\mathcal{O}_X$, where $\mathcal{O}_Y/I$ is the sheafification of $V\mapsto \mathcal{O}_Y(V)/I(V)$.
In particular $(\mathcal{O}_Y/I)\big|_{V_i}\simeq f_*\mathcal{O}_X\big|_{V_i}$, which looks like I'm almost there. But I don't know relate the structural sheaf $\mathcal{O}_{f(X)\cap V_i}=\mathcal{O}_Y\big|_{f(X)\cap V_i}$ of the affine $f(X)\cap V_i$ with the sheaf $(\mathcal{O}_Y/I)\big|_{V_i}$.
How do I do that?