Were Batman Begins or The Dark Knight based on any particular comic(s) or was were they completely created from scratch?
Batman Begins is a combination of stories from the Batman mythos, as well as an original story. According to Wikipedia, the starting point for Batman Begins was a story called "The Man Who Falls"; Jim Gordon was based on the character from the story "Batman: Year One". Neither of these stories featured Ra's Al Ghul, who is a significantly different character than the one featured in the comic (both Ra's are leaders of a large group of assassins, and both have a large respect for Batman, but the Ra's in the comics is depicted as being hundreds of years old, regenerating himself in a pool of liquid called "The Lazarus Pit". It remains to be seen if the Ra's in the movie makes a similar comeback or not).
The film The Dark Knight uses elements from the story The Long Halloween, though again the story is mainly an original story. It was also related that Heath Ledger, who played The Joker, locked himself in his hotel room for weeks to try and get to the core of the character of The Joker, even writing a journal of The Joker's 'thoughts'.