473,621 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

squeeze few image files into one binary file

Hi,

I need to take few files (images in my case) and create one file out of
them, this file should be accessed so i can grab a single image from it
if necessary,

i thought of taking all the images and put them in one binary file, but
couldn't figure out a way to do that, anyone has an idea?

thanks
S.Creek

Nov 17 '05 #1
2 2038
Funny you should ask this, I just did it the other day. In my case, I'm
storing a bunch of thumbnails in one file and then their offsets in an index
file. So if the file with the images has 20 images, the index file will have
20 offsets.

For writing the files, I create a MemoryStream. Then I write the image to
the memory stream. For example:

MemoryStream ms = new MemoryStream()
image.Save(ms, ImageFormat.Jpe g)

Then get the buffer, and in my case, I append it to the end of a file. I
also write out the image size before I write the image itself. I did that as
follows. The "offset" variable has the location in the file where the image
is stored. I then placed this in a separate index file.:

byte[] buffer = ms.GetBuffer();
long offset = outfile.Seek(0, SeekOrigin.End) ;
BinaryWriter writer = new BinaryWriter(ou tfile);
// Write the length of the image data.
writer.Write((i nt)ms.Length)
// Write the image data
writer.Writer(b uffer, 0, (int) ms.Length)
outfile.Flush() ;

You need to use ms.Length as the buffer will probably be larger than the
actual data. The buffer is grown in chunks, and only regrown as it gets
full.

For reading the file back, you basically do the opposite. Offset is the
location we retrieved as offset above:

infile.Seek(off set, SeekOrigin.Begi n);
BinaryReader reader = new BinaryReader(in file);
// Get the size of the image in bytes
imageDataSize = reader.ReadInt3 2();
// Read in the buffer
byte[] buffer = reader.ReadByte s(imageDataSize );
// Make a memory stream
MemoryStream ms = new MemoryStream(bu ffer)
// Create image from stream
Image img = Image.FromStrea m(ms)

It's all quite simple.

Pete
"S.Creek" <od****@gmail.c om> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...
Hi,

I need to take few files (images in my case) and create one file out of
them, this file should be accessed so i can grab a single image from it
if necessary,

i thought of taking all the images and put them in one binary file, but
couldn't figure out a way to do that, anyone has an idea?

thanks
S.Creek

Nov 17 '05 #2


Thanks Pete,
i will try that.
S.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11753
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
7
1744
by: Tom | last post by:
hello friends I want to specify a field to save icons I want to give this field a maximum of 120kb for each icon to be stored in the db. what datatype should I assign to this field and how do I specify the size ? Thanks Tom
9
9711
by: Maurizio Penna | last post by:
I, guys. I've embeded an image into a xml file, something like that: <display type="picture" mime="image/png" name = "mosaico6.png"> <!]> </display> Now, I want to display it with a XSL Transformation, but my code don't work: <display>
13
2344
by: Neo Geshel | last post by:
I have examined about 80+ different upload scripts on the 'net, both in VB and C#, and none seem to do what I need them to do. Perhaps someone here can point me somewhere that Google hasn't reached yet (I have gone all the way to page 50 on Google's results!!). Here are my requirements: • I have a DataGrid. Everything will be done from here. Everything. No exceptions. Everything will also be done in VB, without any code-behind to...
0
8213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8653
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8306
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7127
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6101
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4065
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2587
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1460
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.