www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Easiest way to display images

reply Murilo <murilomiranda92 hotmail.com> writes:
What would be the easiest way to simply display a jpg or png 
image on the screen for a few seconds in Windows?
Feb 05
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 5 February 2019 at 21:11:52 UTC, Murilo wrote:
 What would be the easiest way to simply display a jpg or png 
 image on the screen for a few seconds in Windows?
That's a little more complex than playing a sound, there's no one function to do it. You can in... oh about 50 lines, but I can't write them off the top of my head. However, I do have a library that can do it in 5 lines. --- import arsd.simpledisplay; import arsd.image; void main() { displayImage(Image.fromMemoryImage(loadImageFromFile("filename here"))); } --- I realize that line is a bit silly looking, it loads a file, converts it to a displayable format, then pops up a window to display it. Any key pressed in the window will close it. You might need something more complex, and the lib can do it. You might also want something less complex (that `arsd.image` actually loads 7 different modules for various image formats), but it isn't super hard to use anyway: Download the code here: https://github.com/adamdruppe/arsd You can put all those files in an `arsd` folder next to your program, and `dmd -i yourfile.d` to compile it all at once. Or if you want to load the files yourself, you can list them all. If you just need png and/or jpeg specifically, you can jus get jpeg.d and/or png.d, together with simpledisplay.d and color.d from the repo and call these functions: http://dpldocs.info/experimental-docs/arsd.jpeg.readJpeg.html http://dpldocs.info/experimental-docs/arsd.png.readPng.html So the code looks like: --- import arsd.simpledisplay; import arsd.png; void main() { displayImage(Image.fromMemoryImage(loadPng("filename here"))); } --- or of course changing png to jpeg if you want that. (You can put that on an if based on the image filename - that's what the arsd.image library actually does). Then compile: dmd yourfile.d color.d simpledisplay.d png.d jpeg.d But the first option with dmd -i is prolly the easiest. If you need mroe control over the window, let me know, I will type that up too. also take a look at the docs http://dpldocs.info/experimental-docs/arsd.simpledisplay.html BTW I didn't mention this in your other thread because PlaySound is easier to use anyway, but I also have an audio module: http://dpldocs.info/experimental-docs/arsd.simpleaudio.html I'm just not 100% happy with it so I don't talk about it much.
Feb 05
next sibling parent Murilo <murilomiranda92 hotmail.com> writes:
On Tuesday, 5 February 2019 at 21:25:54 UTC, Adam D. Ruppe wrote:
 On Tuesday, 5 February 2019 at 21:11:52 UTC, Murilo wrote:
 What would be the easiest way to simply display a jpg or png 
 image on the screen for a few seconds in Windows?
That's a little more complex than playing a sound, there's no one function to do it. You can in... oh about 50 lines, but I can't write them off the top of my head. However, I do have a library that can do it in 5 lines. --- import arsd.simpledisplay; import arsd.image; void main() { displayImage(Image.fromMemoryImage(loadImageFromFile("filename here"))); }
Thank you so but so much. I tested it here and it works.
Feb 05
prev sibling parent reply Murilo <murilomiranda92 hotmail.com> writes:
On Tuesday, 5 February 2019 at 21:25:54 UTC, Adam D. Ruppe wrote:
 On Tuesday, 5 February 2019 at 21:11:52 UTC, Murilo wrote:
 What would be the easiest way to simply display a jpg or png 
 image on the screen for a few seconds in Windows?
That's a little more complex than playing a sound, there's no one function to do it. You can in... oh about 50 lines, but I can't write them off the top of my head.
You should later joing the facebook group Programming in D. There you could show your library, lots of people would like to use it. https://www.facebook.com/groups/662119670846705/
Feb 05
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 6 February 2019 at 01:04:43 UTC, Murilo wrote:
 You should later joing the facebook group Programming in D.
Eh, I don't really like facebook groups. With my libraries too, I don't really care if anyone uses them. I make them for myself and put them online because it is easy for me. I don't count downloads or anything; it just means nothing to me.
Feb 05
parent reply Murilo <murilomiranda92 hotmail.com> writes:
On Wednesday, 6 February 2019 at 03:35:03 UTC, Adam D. Ruppe 
wrote:
 On Wednesday, 6 February 2019 at 01:04:43 UTC, Murilo wrote:
 You should later joing the facebook group Programming in D.
Eh, I don't really like facebook groups. With my libraries too, I don't really care if anyone uses them. I make them for myself and put them online because it is easy for me. I don't count downloads or anything; it just means nothing to me.
Adam, is there a place where we can chat? I don't like chatting via this forum. I would like to talk to you about your modules and about the D lang.
Feb 10
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 10 February 2019 at 18:42:59 UTC, Murilo wrote:
 Adam, is there a place where we can chat? I don't like chatting 
 via this forum. I would like to talk to you about your modules 
 and about the D lang.
get on the freenode irc, i am in #d like all the time (and will see messages when i am back on my computer) or you can dm me adam_d_ruppe there if i am online
Feb 10
next sibling parent Murilo <murilomiranda92 hotmail.com> writes:
On Sunday, 10 February 2019 at 21:26:56 UTC, Adam D. Ruppe wrote:
 On Sunday, 10 February 2019 at 18:42:59 UTC, Murilo wrote:
 Adam, is there a place where we can chat? I don't like 
 chatting via this forum. I would like to talk to you about 
 your modules and about the D lang.
get on the freenode irc, i am in #d like all the time (and will see messages when i am back on my computer) or you can dm me adam_d_ruppe there if i am online
okay, I will try that, but do you have a facebook account? I usually chat with people on facebook.
Feb 10
prev sibling parent reply Murilo <murilomiranda92 hotmail.com> writes:
On Sunday, 10 February 2019 at 21:26:56 UTC, Adam D. Ruppe wrote:
 On Sunday, 10 February 2019 at 18:42:59 UTC, Murilo wrote:
 Adam, is there a place where we can chat? I don't like 
 chatting via this forum. I would like to talk to you about 
 your modules and about the D lang.
get on the freenode irc, i am in #d like all the time (and will see messages when i am back on my computer) or you can dm me adam_d_ruppe there if i am online
Hi Adam. I have been using your arsd library and I have noticed that compiling with -m64 causes this error: Error: cannot mix core.std.stdlib.alloca() and exception handling in _D4arsd4jpeg27detect_jpeg_image_from_fileFAxaJiJiJiZb() May I know why that happens? How can I bypass it?
Feb 11
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 12 February 2019 at 01:16:21 UTC, Murilo wrote:
 Hi Adam. I have been using your arsd library and I have noticed 
 that compiling with -m64 causes this error:
huh, only on 64 bit windows. well, pushed a fix up, try the new version
Feb 11
next sibling parent Murilo <murilomiranda92 hotmail.com> writes:
On Tuesday, 12 February 2019 at 01:31:48 UTC, Adam D. Ruppe wrote:
 On Tuesday, 12 February 2019 at 01:16:21 UTC, Murilo wrote:
 Hi Adam. I have been using your arsd library and I have 
 noticed that compiling with -m64 causes this error:
huh, only on 64 bit windows. well, pushed a fix up, try the new version
Hi, unfortunately the problem persists. I have sent you an e-mail on your destructionator gmail.com account. I would prefer to talk there rather than here. I would just like to understand what is causing the problem so I can figure out a bypass.
Feb 11
prev sibling parent Murilo <murilomiranda92 hotmail.com> writes:
On Tuesday, 12 February 2019 at 01:31:48 UTC, Adam D. Ruppe wrote:
 On Tuesday, 12 February 2019 at 01:16:21 UTC, Murilo wrote:
 Hi Adam. I have been using your arsd library and I have 
 noticed that compiling with -m64 causes this error:
huh, only on 64 bit windows. well, pushed a fix up, try the new version
Forget about it, I just fixed it myself. :) I am so happy, I did not think I would be able to do it on my own, I guess all those years of studying were worth the effort, I read the error message and figured it was something wrong in the module jpeg.d so I opened it, read the code(in a very fast manner) and discovered that the calls to core.stdc.stdlib.alloca() were causing the problem apart from being unnecessary so I just commented all of them out(just like you did with the very first instance) and then there was a problem with the buffer variable which was only defined by you in the first instance so I just defined it in the other instances following the same method you used and it all worked in the end. I will submit a pull request on your GitHub page. Cheers.
Feb 11
prev sibling parent reply DanielG <simpletangent gmail.com> writes:
On Wednesday, 6 February 2019 at 01:04:43 UTC, Murilo wrote:
 You should later joing the facebook group Programming in D.
The D community is small enough that it's unlikely anybody in that Facebook group, isn't already using the newsgroups / IRC / etc to discuss D. Even the official subreddit barely gets any traffic. What I'm trying to say is, you're not going to have much luck getting that Facebook group off the ground. FB adds nothing to the existing options, and worse it's just an elaborate scheme to harvest personal information which one can safely assume the vast majority of D programmers are privacy-savvy enough to avoid.
Feb 05
parent reply Murilo <murilomiranda92 hotmail.com> writes:
On Wednesday, 6 February 2019 at 04:36:12 UTC, DanielG wrote:
 On Wednesday, 6 February 2019 at 01:04:43 UTC, Murilo wrote:
 You should later joing the facebook group Programming in D.
The D community is small enough that it's unlikely anybody in that Facebook group, isn't already using the newsgroups / IRC / etc to discuss D. Even the official subreddit barely gets any traffic. What I'm trying to say is, you're not going to have much luck getting that Facebook group off the ground. FB adds nothing to the existing options, and worse it's just an elaborate scheme to harvest personal information which one can safely assume the vast majority of D programmers are privacy-savvy enough to avoid.
The facebook group already has 82 members, some of which are experienced users of D. There has been some reasonable amount of discussions going on there in the last weeks. And you don't need to worry about the "information harvesting" if you don't post personal stuff. It is a group to talk about a language and not about your life.
Feb 06
parent DanielG <simpletangent gmail.com> writes:
On Thursday, 7 February 2019 at 00:10:50 UTC, Murilo wrote:
 "information harvesting"
I mean Facebook as a whole, not your group specifically. FB is in the business of selling to advertisers, and the users are the product.
Feb 06