Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2824
  • Last Modified:

png resources

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
A. Cristian Csiki
Asked:
A. Cristian Csiki
  • 6
  • 4
1 Solution
 
2266180Commented:
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
 
A. Cristian CsikiSenior System AdministratorAuthor Commented:
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
 
2266180Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
A. Cristian CsikiSenior System AdministratorAuthor Commented:
very good.
The example works very well. Thanks mite.

Have a nice day.
0
 
A. Cristian CsikiSenior System AdministratorAuthor Commented:
The sollution was the best I could get
0
 
A. Cristian CsikiSenior System AdministratorAuthor Commented:
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
 
2266180Commented:
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
 
A. Cristian CsikiSenior System AdministratorAuthor Commented:
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
 
2266180Commented:
>> 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
 
A. Cristian CsikiSenior System AdministratorAuthor Commented:
like ussual u're wright =D>
Fix: in form2.create assign the png.
Thanks for many many times mate ;)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now