Solved

png resources

Posted on 2007-11-18
10
2,693 Views
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
0
Comment
Question by:A. Cristian Csiki
  • 6
  • 4
10 Comments
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
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 http://pngdelphi.sourceforge.net/
- 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.
0
 
LVL 11

Author Comment

by:A. Cristian Csiki
Comment Utility
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>
png.pngimage.loadfromresourcename(hinstance,'data.res');
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
0
 
LVL 28

Accepted Solution

by:
ciuly earned 500 total points
Comment Utility
you're not doing it right :)

I just woke up, the day is long so I've made a quick small demo: http://www.ciuly.com/delphi/multimedia/pngFromResource/index.html

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.
0
 
LVL 11

Author Comment

by:A. Cristian Csiki
Comment Utility
very good.
The example works very well. Thanks mite.

Have a nice day.
0
 
LVL 11

Author Closing Comment

by:A. Cristian Csiki
Comment Utility
The sollution was the best I could get
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 11

Author Comment

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

Expert Comment

by:ciuly
Comment Utility
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
0
 
LVL 11

Author Comment

by:A. Cristian Csiki
Comment Utility
well,
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:
http://www.thany.org/article/32/PngComponents

Thanks for help.
Regards ciuly
0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
>> 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.
0
 
LVL 11

Author Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now