Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I want to add extra content in image header.
i have fingerprint image of person.
I am taking image in byte[] by doing, file.readAllBytes(filename).
Now i want to add some extra content into the header of fingerprint image like person id and his name.
How can i do it?? any suggestion.

Thank u in advance..
god bless u all.
Posted

Hi,

Please have a look at the following blog: How to set custom attributes / file properties on a file in C# .Net[^] - so you could just add the additional properties to the file without making use of the byte[].

Kind regards,
 
Share this answer
 
Comments
MAU787 4-Dec-12 1:37am    
thank u for your help..
actually i want to add content in header of the image file..in byte format
Programm3r 4-Dec-12 2:14am    
So you want to alter the image and display a 'new' one?
MAU787 4-Dec-12 2:16am    
actually i am saving image in byte[] in database.. so while saving i want to add some extra parameters in image header..
Programm3r 4-Dec-12 2:26am    
"...Now I want to add some extra content into the header of fingerprint image like person id and his name..."

Just a quick question, why would you want to do this? Why not add the extra columns to you table and insert the data there?
MAU787 4-Dec-12 3:10am    
for security. if i m saving image in database as it is then anyone can update those images. so i want to add unique header to that image.
hi
string filepath = @"C:\temp\abc.bmp";
//read all bytes of image
Byte[] imageData = System.IO.File.ReadAllBytes(filepath);

System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
string name = "abc";
string  id = "IBPL123";

//take name in bytes
byte[] bytes1 = new byte[name.Length * sizeof(char)];
bytes1 = encoding.GetBytes(name);

//take id in bytes
byte[] bytes2 = new byte[id.Length * sizeof(char)];
bytes2 = encoding.GetBytes(id);

//assign length +extra 50 bytes
Byte[] bytes3 = new Byte[imageData.Length +50];

//assign all data into new byte
System.Buffer.BlockCopy(bytes1, 0, bytes3, 0, bytes1.Length);
System.Buffer.BlockCopy(bytes2, 0, bytes3, 25, bytes2.Length);
System.Buffer.BlockCopy(imageData, 0, bytes3, 50, imageData.Length);
 
Share this answer
 
Comments
Programm3r 4-Dec-12 8:37am    
Hi - so I assume you came right? If that is the case please mark one of the solutions as the answer (even if it is your own).
MAU787 4-Dec-12 23:14pm    
Thanks a lot for your help..:)
Programm3r 5-Dec-12 0:44am    
Only a pleasure!
Hi,

This is not the most elegant solution, but it will provide a general idea. You'll have to come up with a way of getting the person data from the byte[].

class Program
{
    static void Main(string[] args)
    {

        byte[] fileByteArray = File.ReadAllBytes(@"C:Pictures\image.jpg");
        byte[] finalByteArray = new byte[fileByteArray.Length + 50];

        Guid personID = Guid.NewGuid();
        string personSurname = "Gates";
        int cnt = 0;

        foreach (var item in personID.ToByteArray())
        {
            finalByteArray[cnt] = item;
            cnt++;
        }
        foreach (var item in Encoding.ASCII.GetBytes(personSurname))
        {
            finalByteArray[cnt] = item;
            cnt++;
        }

        int imgPositionCnt = 50;
        foreach (var imageByte in fileByteArray)
        {
            finalByteArray[imgPositionCnt] = imageByte;
            imgPositionCnt++;
        }

        GetImage(finalByteArray);
        GetPersonData(finalByteArray);

        Console.ReadLine();
    }

    private static byte[] GetImage(byte[] source)
    {
        byte[] image = new byte[source.Length - 50];
        int cnt = 0;
        for (int i = 50; i < source.Length; i++)
        {
            image[cnt] = source[i];
            cnt++;
        }

        FileStream stream = new FileStream(@"C:\test.jpg", FileMode.Create);
        stream.Write(image, 0, image.Length);
        stream.Close();

        return image;
    }

    private static byte[] GetPersonData(byte[] source)
    {
        byte[] personData = new byte[50];
        for (int i = 0; i < personData.Length; i++)
        {
            personData[i] = source[i];
        }

        return personData;
    }
}


Hope it helps!
Kind regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900