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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-22-2006, 08:17 AM
|
#1
|
Member
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893
Rep:
|
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.
|
|
|
04-22-2006, 08:43 AM
|
#2
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
Rep:
|
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.
|
|
|
04-22-2006, 10:24 AM
|
#3
|
Member
Registered: Oct 2005
Posts: 970
Rep:
|
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/
|
|
|
04-22-2006, 01:07 PM
|
#4
|
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Rep:
|
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.
|
|
|
04-22-2006, 04:57 PM
|
#5
|
Member
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915
Rep:
|
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()?
|
|
|
04-22-2006, 10:14 PM
|
#6
|
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Rep:
|
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?
|
|
|
04-23-2006, 12:03 AM
|
#7
|
Member
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915
Rep:
|
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.
|
|
|
04-24-2006, 10:34 AM
|
#8
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
Rep:
|
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.
|
|
|
04-24-2006, 06:41 PM
|
#9
|
Member
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915
Rep:
|
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.
|
|
|
04-24-2006, 07:25 PM
|
#10
|
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Rep:
|
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
|
|
|
All times are GMT -5. The time now is 07:52 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|