png resources

Posted on 2007-11-18
Last Modified: 2012-06-27
Hi all.
It's me again.
I'm wondering if there is possible to add .png files to .res and use them from that resource file. I will aspect an example for each ideea. Thanks
Question by:A. Cristian Csiki
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
LVL 28

Expert Comment

ID: 20309277
I will be below your expectations as I don't have time to give eberybody a complete solution with full examples.

I myself expect askers to collaborate in the idea that I provide the expertise and they provide their time. In my opinion this benefits everybody: you get a fast solution, spend a little time implementing, and I'll help out with whatever smal issues come around. and you're done. on the other hand, if I'll have to spend time for everybody, that goes out from my free time or not free time. so my alternative would be either not to help you (you meaning you askers) or help just a few of you. but from my experience here, people preffer that I give them whatever expertiese I have since they can get the job done faster thn waiting for somebody to spend time on making demos ;)

too much talk, so, solution:
- you need something that can deal with png. for example
- you then save the png to the resource as you would do any other data (create a rc file and compile it to res then include it in the unit)
- for loading, you create a resourcestream and load the png with the component using loadfromstream

OR you can use LoadFromResourceName or LoadFromResourceID of the png component. which ever method you preffer.

for any other questions or problems, I'm here, so do ask ;)
if you have problems with the code, post your code and error so that I can assist on your problem directly.
LVL 11

Author Comment

by:A. Cristian Csiki
ID: 20310842
Hi ciuly.
The thing u told about ex. is fair. The 2nd thing: i tried adding the pngs in rc file and compile with the brcc32. It works fine. Still i'm in doubt which ext should i add in rc file for pngs (ex: webcam png webcam.png or webcam rcdata webcam.png) The first ex works. So i think that must be.

Second. I'm using pngs in Timage and Tpngspeedbutton from the delphi component mentioned by u above. The thing I'm stuck is the instance. Must be something very small.

png <pngspeedbutn>
data.res must be my resource file....but the hinstance is wrong.

after that I read I can assign the picture to a Timage.

Thanks for help
Cheers ciuly
LVL 28

Accepted Solution

2266180 earned 500 total points
ID: 20311047
you're not doing it right :)

I just woke up, the day is long so I've made a quick small demo:

you will have there a rc declaration (correct one) and a few lines of code on how to load it.

now, I don't install components/libraries I don't use (it just bloats my delphi installation plus it can make it unstable if teh component/.library conflicts with something), so what I did was to creat a png directory and as said by the readme from it, you will need to copy the conents of the delphipng inthere. the project has been modified to have the searchpath include that directory so it compiles fine. if you have already installed delphipng somewhere and set delphis search path than you don't need to copy those files to the png directory.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 11

Author Comment

by:A. Cristian Csiki
ID: 20311086
very good.
The example works very well. Thanks mite.

Have a nice day.
LVL 11

Author Closing Comment

by:A. Cristian Csiki
ID: 31409826
The sollution was the best I could get
LVL 11

Author Comment

by:A. Cristian Csiki
ID: 20314355
one more thing, if is not too late.
If I already got a pngobject on my 2nd form i got a pngspeedbutton. Can I use the pngs from resource too?
LVL 28

Expert Comment

ID: 20314851
I don't understand your question.
jsut to cover some basics:
- you can load the same resource as many times as you want in as many objects as you want
- you can use the same object do display the same png in many places
- you can even use the same object to display different pngs in many places, but you'll have to take care of the "when" part (when you load the png, when you display it, etc).

I see that you leep referring to a pngspeedbutton. I never heard of it. google has some resources. Can you give me a pointer link to it so that I know what you are talking about? ;) a
and also, if you still have that question, explain it a little more explicitly
LVL 11

Author Comment

by:A. Cristian Csiki
ID: 20315449
the png assigned to form1.image1 works fine.
if i add to assign png to form2.image1 i get:
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 00471d38 in module 'Project1.exe'. Read of address 00000318

Same with a png component:

Thanks for help.
Regards ciuly
LVL 28

Expert Comment

ID: 20315469
>> if i add to assign png to form2.image1 i get:

when? in form1.create? if so, that is a bad place since form2 is not yet created ;)

instead, in form2.create use the form1.image to assign to whatever you want to assign it to.
LVL 11

Author Comment

by:A. Cristian Csiki
ID: 20315568
like ussual u're wright =D>
Fix: in form2.create assign the png.
Thanks for many many times mate ;)

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 63
Run video youtube webbrowse 10 73
tidtcpserver connection lost handle 2 110
When i run adoquery my application freezes 26 190
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question