Calling a picture file in C?

This is a discussion on Calling a picture file in C? within the C Programming forums, part of the General Programming Boards category; Hey guys! I was just wondering... If, in File I/O we can read, write and append text files... Same in ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    10

    Calling a picture file in C?

    Hey guys! I was just wondering... If, in File I/O we can read, write and append text files... Same in Binary I/O... Can we open a different file extension, like a .jpg file so that it opens in another window (Maybe the photoviewer)? Is that possible? And if it is, then what should I use in order for that to happen?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    You mean like this?
    Cprogramming.com FAQ > Run a program from within a program

    Of course, if you want to do more work yourself, there's nothing to stop you from decoding a jpg file yourself, creating a graphics window yourself, and plotting a lot of pixels (yourself).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    10
    Quote Originally Posted by Salem View Post
    You mean like this?
    Cprogramming.com FAQ > Run a program from within a program

    Of course, if you want to do more work yourself, there's nothing to stop you from decoding a jpg file yourself, creating a graphics window yourself, and plotting a lot of pixels (yourself).
    Uhm... It's not actually running a program within a program. It's more of like opening a .jpg file in windows photo viewer or something like that from the C program itself. Is that possible?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    Of course "it's possible", what do you think the existing photo viewer is doing?

    It isn't magic, it's just application of programming knowledge, that's all.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,464
    Quote Originally Posted by hexarthrius View Post
    Uhm... It's not actually running a program within a program. It's more of like opening a .jpg file in windows photo viewer or something like that from the C program itself. Is that possible?
    Yes, and that is "running a program within a program". Windows photo viewer is a program. Your program will be the one running it. Note that you don't need to do any file I/O yourself for this. Read the link Salem posted.

    Quote Originally Posted by hexarthrius View Post
    Hey guys! I was just wondering... If, in File I/O we can read, write and append text files... Same in Binary I/O... Can we open a different file extension, like a .jpg file so that it opens in another window (Maybe the photoviewer)? Is that possible? And if it is, then what should I use in order for that to happen?
    You can open a file of any extension in C. C doesn't care about extensions, extensions are only there as a convenience for the user and OS, so they know what type of data is inside. Every file is either a binary file or a text file, even .jpg files.

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    10
    Quote Originally Posted by Salem View Post
    Of course "it's possible", what do you think the existing photo viewer is doing?

    It isn't magic, it's just application of programming knowledge, that's all.
    So, correct me if I'm wrong.... When I run the main program, I should call the windows photo viewer program? If it's so, then how will I navigate to the file? For example, I have a 1.jpg, 2.jpg and 3.jpg. How will I task the photo viewer to read only 1.jpg, for example?

    Quote Originally Posted by anduril462 View Post
    Yes, and that is "running a program within a program". Windows photo viewer is a program. Your program will be the one running it. Note that you don't need to do any file I/O yourself for this. Read the link Salem posted.



    You can open a file of any extension in C. C doesn't care about extensions, extensions are only there as a convenience for the user and OS, so they know what type of data is inside. Every file is either a binary file or a text file, even .jpg files.
    Refer to the question I asked Salem. How can I tell the other program (Photo viewer) to view 1.jpg?
    Last edited by hexarthrius; 03-12-2011 at 11:05 AM.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    I think you need to post some code showing what you're trying to do.

    If your photo viewer comes with a directory brower "built in", then I doubt you could invoke it just to view a single file and then return to your program.

    Simple code to be sure, but you kind of have to accept what you're given.

    But if you want to write a fair amount of code, and link with libjpg and some UI toolkit, then you can create a picture viewer all of your own that can do whatever you can think of making it do.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,464
    Quote Originally Posted by hexarthrius View Post
    So, correct me if I'm wrong.... When I run the main program, I should call the windows photo viewer program? If it's so, then how will I navigate to the file? For example, I have a 1.jpg, 2.jpg and 3.jpg. How will I task the photo viewer to read only 1.jpg, for example?



    Refer to the question I asked Salem. How can I tell the other program (Photo viewer) to view 1.jpg?
    This isn't really even a C question. It's a "how do I use photo viewer from the command line" question. The link Salem provided gives you good info on several ways to do that, but you must know what command line parameters you need to pass it. You would have to look at the photo viewer documentation to know what, if any, command line parameters you can pass to it to get it to open a file. It could be as simple as system("C:\\Program Files\\Photo Viewer\\photoviewer.exe 1.jpg"), but I don't know much about photo viewer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you help me about tolower() in file
    By nctar in forum C Programming
    Replies: 7
    Last Post: 05-12-2010, 10:04 AM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21