Look at the following sentences:

#1. In criticizing the painting, I knew I would offend her.
#2. By criticizing the painting, I knew I would offend her.

Do they both have the exact same meaning? If not, what's the difference between sentence #1 and 2?