You should not answer questions that do not meet our minimum standards for a question. These questions should be closed instead. To facilitate the closure of such questions, you should flag them: use the "needs improvement" reason, and then pick one of the appropriate sub-reasons. For the case where the question contains images of code instead of text, you should choose the sub-reason that speaks of it lacking a "minimal, reproducible example".
Jeanne Dark already linked you to the canonical FAQ on why images of code are not acceptable: Why should I not upload images of code/data/errors? You may want to post something like this in a comment to advise the asker, but it is not necessary (the flag is sufficient).
Regarding the downvotes: users are free to vote however they like on posts, whether up or down, as long as they are not engaging in vote fraud. So, I will not comment on the "appropriateness" of the downvotes in your case—or any other. There are many, many reasons why an answer might be downvoted. It might be wrong, or it might be unclear, or someone might think you should not have answered an inappropriate question, etc. You cannot know for certain exactly why someone has downvoted.
Therefore, the primary reason to avoid answering low-quality questions is not to avoid downvotes, but rather to spend your time in places where it will better contribute to our overall goal:
With your help, we're working together to build a library of detailed, high-quality answers to every question about programming.
There are many other practical reasons not to answer questions that should be closed, not the least of which is that any edit to the question to correct its issues might lead to invalidating your answer. That creates a mess for everyone. Another selfish reason is that the whole Q&A might get deleted if it is not edited to meet our minimum requirements, which would be effectively throwing away your efforts at writing an answer. Your efforts are better spent on better questions.