LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2006, 08:17 AM   #1
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Rep: Reputation: 35
How to byte-get an image?


Well, I need to create a format for test app which must contain questions, answers, variansts and IMAGES.
How should I read an image? And where to save it? In char*?

Thanks.
 
Old 04-22-2006, 08:43 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I'd just use one of the avialable libs for handling images. These typically provide you with some struct or object, so you don't really have to care about the internal representation of the images.

If you really want to do it yourself, yes, an array of (unsigned) char's may be a good start.
 
Old 04-22-2006, 10:24 AM   #3
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
How should I read an image
IF you want to do this yourself then you need to understand the structure. http://www.wotsit.org/
 
Old 04-22-2006, 01:07 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
kornerr - as dmail points out, the answer might depend on what kind of images you need, how you're planning on using them, or what language you're programming in.

But if you're programming in a language like C/C++, Perl or Python, libraries like GTK+ 2.0 have built-in support for most standard file types - you just say "read_file()" (for example, something like "gdk_pixbuf_new_from_file()").

If you're programming in Java or C#, the standard libraries have built-in support for reading, displaying and manipulating standard graphics file formats.

So please consider Hko's suggestion and see if your programming language has a library that supports your file format.
 
Old 04-22-2006, 04:57 PM   #5
daihard
Member
 
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915

Rep: Reputation: 34
I'm not the OP, but the question got me curious.

If you're using C and can only use the standard libraries, are you limited to reading image files as binary streams using, say, fopen() and fread()?
 
Old 04-22-2006, 10:14 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I'm not sure I understand your question. I think you're asking:

Q: Does the standard C library (libC) provide an API for parsing and displaying image files?

A: No: the standard library provides APIs for file access (read (), fread (), getc(), etc), but you would either have to use an additional library (libpng or GTK+, for example) or write your own parser.

Once you've parsed the file, then you'd then have to use yet another library (SDL, Xlib, GTK+, Qt, etc) to actually display it.

Does that help?
 
Old 04-23-2006, 12:03 AM   #7
daihard
Member
 
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915

Rep: Reputation: 34
Quote:
Originally Posted by paulsm4
Q: Does the standard C library (libC) provide an API for parsing and displaying image files?

A: No: the standard library provides APIs for file access (read (), fread (), getc(), etc), but you would either have to use an additional library (libpng or GTK+, for example) or write your own parser.

Once you've parsed the file, then you'd then have to use yet another library (SDL, Xlib, GTK+, Qt, etc) to actually display it.
Yes, that's exactly my question. Your answer helps a lot. Thanks.
 
Old 04-24-2006, 10:34 AM   #8
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by daihard
If you're using C and can only use the standard libraries, are you limited to reading image files as binary streams using, say, fopen() and fread()?
Yes, though I'd rather use the syscalls open(2) and read(2) for binary data. Note that fopen(3) and fread(3) actually call open(2) and read(2) behind the scenes.
 
Old 04-24-2006, 06:41 PM   #9
daihard
Member
 
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915

Rep: Reputation: 34
Quote:
Originally Posted by Hko
Yes, though I'd rather use the syscalls open(2) and read(2) for binary data.
Is there any reason for that? Looks to me that dealing with file pointers (FILE *) is easier than file descriptors.
 
Old 04-24-2006, 07:25 PM   #10
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
You're right - stdio *is* easier. And more efficient (in terms of functionality, and overall system throughput).

"Stdio" ("fopen()", "fprintf()" and friends) is an abstraction on top of the underlying OS I/O capabilities. The biggest advantage it brings to the table is "buffered I/O", but there are also many other benefits to using stdio instead of the low-level read/write file interface.

If you look forward into the "Standard I/O" section of this PDF, it's got some interesting discussion of the subject:
http://www.google.com/url?sa=U&start...es/class24.ppt
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SIB byte question Berhanie Programming 3 11-17-2004 04:11 PM
Byte Benchmarks kiwi_bloke Linux - Software 1 08-17-2004 12:07 AM
0 byte logs dsieme01 Linux - Security 5 07-22-2004 10:13 AM
C++ byte type exodist Programming 3 05-11-2004 05:02 PM
backup byte-for-byte axion0917 Linux - Software 2 12-11-2003 05:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration