How can I include an image that cannot be changed in my application? [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this questionI have used many images in my application with the resource file.
The question is here that other users of my app, can they change my bitmaps to their own bitma开发者_如何学Pythonps by replacing and renaming them?!
For example My Logo with 250x120 dimension will appeared on splash screen.
Is it necessary to put logo.png
near my exe file?
if yes, can users replace a another file as name as logo.png
near to my exe file for showing their own file?
What is the way to avoid this bad thing?
If the file has been compiled into a resource, it will be embedded in your executable. Someone else placing a file of the same name near your executable will not have any effect, because it has already been compiled.
A hacker can still edit the resource within your executable if they're really intent on replacing your logo, but it won't happen accidentally.
You should keep any graphics in a resource file, not as separate files w/ your application.
This link may help.
Per the response there:
There are many ways to do this
Imagelist control : Add your icons/images to imagelist and you can access them at runtime
Managed Resources : Right click your project name, and select properties from menu, on properties, select resources tab and add your images or icons as existing item.Now you can access the icon or image from resources as Dim img as Bitmap = My.Resources.YourResourcesNameWithoutExtension Dim Ic as Icon = My.Resources.YourResourcesNameWithoutExtension
Embedded Resources : To add any file as an embedded resource in a windows forms application, add the file to the project with Project | Add Existing Item or right click your project name in solution explorer and click Add Existing item. Then select the file in the Solution Explorer, go to the Properties Window, and set its Build Action property to Embedded Resource. The file will be embedded within your compiled executable, when you build the project.
I wouldn't call it "hacking" to simply replace an obvious file. Anyway, you can do it several ways, but the hardest to change is an embedded resource. See #3 on this site: http://www.progware.org/Blog/post/Image-Resources-in-WinForms-and-WPF.aspx. Note that you are currently doing #2.
精彩评论