Like others have said, folks won't actually stop using the stuff. Keep it illegal and folks have a higher chance of getting bad stuff, not injecting cleanly or properly, and increases overdose deaths.
At least with legalization, you get some science based education before you even try it the first time. For most folks, this is way before they start to inject. You can more easily have physicians and/or pharmacists having frank talks with patients about signs of addiction and have science-based plans to help folks wean off of the prescription drugs. You can have injections done by a trained professional, who calculates your dosage. You can make sure it is the strength on the package. You can be referred to a clinic for addiction.
Maybe we can even use some of that money we saved on incarceration to let folks rest at home after injury/surgery without losing their house or their job so that we use less pain medication and reduce risk. We can offer medicine-based addiction services as well instead of AA and NA being the standard treatments.
And sure, it won't stop everyone, just like cigarettes. But no one currently starts cigarettes thinking they are completely safe - I surely didn't and I started 20 years ago, though I'm down to 3-4 a day now. We can also not use as many of the scare tactics we use today and be honest about the positive effects folks get from this stuff along with the bad. For some, we might have better alternatives (different ways for coping with boredom and stress might help with things like boredom, which is what actually got me to start around 18).
And just to state things: I don't know how it is with heroin addiction, but not all addicts for other drugs are alike. Not everyone is an addict for life. Some folks can be alcoholics but then be completely able to drink casually like everyone else, without re-developing a problem. Others cannot, and I think we do a great disservice to people when we lump them together like this.