Solved

png resources

Posted on 2007-11-18
10
2,754 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
[X]
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
10 Comments
 
LVL 28

Expert Comment

by:2266180
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 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
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>
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:
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: 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
Technology Partners: 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.
0
 
LVL 11

Author Closing Comment

by:A. Cristian Csiki
ID: 31409826
The sollution was the best I could get
0
 
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 project...in 2nd form i got a pngspeedbutton. Can I use the pngs from resource too?
0
 
LVL 28

Expert Comment

by:2266180
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
0
 
LVL 11

Author Comment

by:A. Cristian Csiki
ID: 20315449
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:2266180
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.
0
 
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 ;)
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 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