BitmapMetadata

  • Thread starter Thread starter Roger
  • Start date Start date
R

Roger

Hi all

I have managed read metadata from an image file using BitmapMetaData, and
that works fine,

but I am having trouble finding out how to write the information back to the
Image

can anyone help with this please

Thanks in advance

Roger
 
Thanks for the link.

I have looked there and tried a few examples that i have found oround the
net.

It seems that its all a little sketchy, and i have yet to find any one who
have got this to work.

I have found a c# libray which i am looking into now but it seems that the
EXIF standard and MS standard are different.

If you change the tags in Vista they do not seem to match the EXIF format.

I have spent the weekend looking into this and am able to read tags with no
problem at all.

Writing to the tags seems a whole different ball game.

I will keep trying.

Anymore suggestions would be welcome.

If I find away to make this work i will post the soloution.

Great New group by the way I will try and participate

Thanks again for the suggestions

Roger
 
Hi Roger,
Can you post the code piece so that i will have more clarity on as to what
are you trying to do and hence will be more accomplished to give my inputs
for the same.

regards,
Joy
 
Code I have used so far

This is the class i have for reding the data which works fine
<snip>
using System.Windows.Media.Imaging;
using System.IO;
<snip>

/// <summary>
/// Returns Image MetaData Preformated in a table
/// using System.Windows.Media.Imaging (ref)
/// dot.net 3.5 standard
///
/// </summary>

public static string returnMetaData(string imgFile)
{
string MetaData = null;




BitmapSource img = BitmapFrame.Create(new Uri(imgFile));
BitmapMetadata meta = (BitmapMetadata)img.Metadata;
// MetaData
MetaData += "Title: " + meta.Title + Environment.NewLine;
MetaData += "Subject: " + meta.Subject + Environment.NewLine;
MetaData += "Comment: " + meta.Comment + Environment.NewLine;
MetaData += "Date taken: " + meta.DateTaken +
Environment.NewLine;
MetaData += "Authors: " + meta.Author + Environment.NewLine;

/* Image data */
double mpixel = (img.PixelHeight * img.PixelWidth) /
(double)1000000;
MetaData +="Image Width: "+ img.PixelWidth + "px"+
Environment.NewLine;
MetaData +="Image Height: "+ img.PixelHeight + "px"+
Environment.NewLine;
MetaData +="Megapixels: " + mpixel + Environment.NewLine;
MetaData += "DPI: " + img.DpiX + img.DpiY +Environment.NewLine;

// More Metadata
MetaData += "Camera Maker: " + meta.CameraManufacturer +
Environment.NewLine;
MetaData += "Camera Model: " + meta.CameraModel +
Environment.NewLine;
MetaData += "Edited in: " + meta.ApplicationName +
Environment.NewLine;
MetaData += "Copyright: " + meta.Copyright +
Environment.NewLine;

// remove unsafe characters for ajax postback

MetaData = MetaData.Replace ("<","");
MetaData = MetaData.Replace (">","");
return MetaData ;

}



This is the code i have been trying to write the data with out sucess

imageFile = "c://users//roger//documents//test.jpg";
bool done = true;
Stream jpgStream = new System.IO.FileStream(imageFile,
FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
JpegBitmapDecoder jpgDecoder = new JpegBitmapDecoder(jpgStream,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame jpgFrame = jpgDecoder.Frames[0];
InPlaceBitmapMetadataWriter jpgInplace =
jpgFrame.CreateInPlaceBitmapMetadataWriter();
if (jpgInplace.TrySave() == true)
{

jpgInplace.SetQuery("/Text/Title", "Have a nice day");
}
jpgStream.Close();
 
Hi Roger,
Please let me know which version of the .NET Framework have you been using
and also visit the following Url and let me know if it makes some sense to
you:

http://www.vsj.co.uk/dotnet/display.asp?id=649

Please also let me know what specific error/exception have you been getting?

regards,
Joy

Roger said:
Code I have used so far

This is the class i have for reding the data which works fine
<snip>
using System.Windows.Media.Imaging;
using System.IO;
<snip>

/// <summary>
/// Returns Image MetaData Preformated in a table
/// using System.Windows.Media.Imaging (ref)
/// dot.net 3.5 standard
///
/// </summary>

public static string returnMetaData(string imgFile)
{
string MetaData = null;




BitmapSource img = BitmapFrame.Create(new Uri(imgFile));
BitmapMetadata meta = (BitmapMetadata)img.Metadata;
// MetaData
MetaData += "Title: " + meta.Title + Environment.NewLine;
MetaData += "Subject: " + meta.Subject + Environment.NewLine;
MetaData += "Comment: " + meta.Comment + Environment.NewLine;
MetaData += "Date taken: " + meta.DateTaken +
Environment.NewLine;
MetaData += "Authors: " + meta.Author + Environment.NewLine;

/* Image data */
double mpixel = (img.PixelHeight * img.PixelWidth) /
(double)1000000;
MetaData +="Image Width: "+ img.PixelWidth + "px"+
Environment.NewLine;
MetaData +="Image Height: "+ img.PixelHeight + "px"+
Environment.NewLine;
MetaData +="Megapixels: " + mpixel + Environment.NewLine;
MetaData += "DPI: " + img.DpiX + img.DpiY +Environment.NewLine;

// More Metadata
MetaData += "Camera Maker: " + meta.CameraManufacturer +
Environment.NewLine;
MetaData += "Camera Model: " + meta.CameraModel +
Environment.NewLine;
MetaData += "Edited in: " + meta.ApplicationName +
Environment.NewLine;
MetaData += "Copyright: " + meta.Copyright +
Environment.NewLine;

// remove unsafe characters for ajax postback

MetaData = MetaData.Replace ("<","");
MetaData = MetaData.Replace (">","");
return MetaData ;

}



This is the code i have been trying to write the data with out sucess

imageFile = "c://users//roger//documents//test.jpg";
bool done = true;
Stream jpgStream = new System.IO.FileStream(imageFile,
FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
JpegBitmapDecoder jpgDecoder = new JpegBitmapDecoder(jpgStream,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame jpgFrame = jpgDecoder.Frames[0];
InPlaceBitmapMetadataWriter jpgInplace =
jpgFrame.CreateInPlaceBitmapMetadataWriter();
if (jpgInplace.TrySave() == true)
{

jpgInplace.SetQuery("/Text/Title", "Have a nice day");
}
jpgStream.Close();
--------------------------------------------------------------------------------------------------------


Joy said:
Hi Roger,
Can you post the code piece so that i will have more clarity on as to what
are you trying to do and hence will be more accomplished to give my inputs
for the same.

regards,
Joy
 
Hi Roger,
I tried the code given on MSDN on the following Url:

http://msdn.microsoft.com/en-us/library/aa970450.aspx

And it was running perfectly for me, so please let me know which version of
..NET are you using and also what is the specific error\exception that you
have been getting.

regards,
Joy

Roger said:
Code I have used so far

This is the class i have for reding the data which works fine
<snip>
using System.Windows.Media.Imaging;
using System.IO;
<snip>

/// <summary>
/// Returns Image MetaData Preformated in a table
/// using System.Windows.Media.Imaging (ref)
/// dot.net 3.5 standard
///
/// </summary>

public static string returnMetaData(string imgFile)
{
string MetaData = null;




BitmapSource img = BitmapFrame.Create(new Uri(imgFile));
BitmapMetadata meta = (BitmapMetadata)img.Metadata;
// MetaData
MetaData += "Title: " + meta.Title + Environment.NewLine;
MetaData += "Subject: " + meta.Subject + Environment.NewLine;
MetaData += "Comment: " + meta.Comment + Environment.NewLine;
MetaData += "Date taken: " + meta.DateTaken +
Environment.NewLine;
MetaData += "Authors: " + meta.Author + Environment.NewLine;

/* Image data */
double mpixel = (img.PixelHeight * img.PixelWidth) /
(double)1000000;
MetaData +="Image Width: "+ img.PixelWidth + "px"+
Environment.NewLine;
MetaData +="Image Height: "+ img.PixelHeight + "px"+
Environment.NewLine;
MetaData +="Megapixels: " + mpixel + Environment.NewLine;
MetaData += "DPI: " + img.DpiX + img.DpiY +Environment.NewLine;

// More Metadata
MetaData += "Camera Maker: " + meta.CameraManufacturer +
Environment.NewLine;
MetaData += "Camera Model: " + meta.CameraModel +
Environment.NewLine;
MetaData += "Edited in: " + meta.ApplicationName +
Environment.NewLine;
MetaData += "Copyright: " + meta.Copyright +
Environment.NewLine;

// remove unsafe characters for ajax postback

MetaData = MetaData.Replace ("<","");
MetaData = MetaData.Replace (">","");
return MetaData ;

}



This is the code i have been trying to write the data with out sucess

imageFile = "c://users//roger//documents//test.jpg";
bool done = true;
Stream jpgStream = new System.IO.FileStream(imageFile,
FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
JpegBitmapDecoder jpgDecoder = new JpegBitmapDecoder(jpgStream,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame jpgFrame = jpgDecoder.Frames[0];
InPlaceBitmapMetadataWriter jpgInplace =
jpgFrame.CreateInPlaceBitmapMetadataWriter();
if (jpgInplace.TrySave() == true)
{

jpgInplace.SetQuery("/Text/Title", "Have a nice day");
}
jpgStream.Close();
--------------------------------------------------------------------------------------------------------


Joy said:
Hi Roger,
Can you post the code piece so that i will have more clarity on as to what
are you trying to do and hence will be more accomplished to give my inputs
for the same.

regards,
Joy
 
Sorry I Have been away.

Anyway .net 3.5 and the code you suggested is what i have used except i have
change it from tiff to jpeg

I have read the skimpy examples the msdn provides.

Did you try it with a jpeg?

Thanks


Roger

Joy said:
Hi Roger,
I tried the code given on MSDN on the following Url:

http://msdn.microsoft.com/en-us/library/aa970450.aspx

And it was running perfectly for me, so please let me know which version
of
.NET are you using and also what is the specific error\exception that you
have been getting.

regards,
Joy

Roger said:
Code I have used so far

This is the class i have for reding the data which works fine
<snip>
using System.Windows.Media.Imaging;
using System.IO;
<snip>

/// <summary>
/// Returns Image MetaData Preformated in a table
/// using System.Windows.Media.Imaging (ref)
/// dot.net 3.5 standard
///
/// </summary>

public static string returnMetaData(string imgFile)
{
string MetaData = null;




BitmapSource img = BitmapFrame.Create(new Uri(imgFile));
BitmapMetadata meta = (BitmapMetadata)img.Metadata;
// MetaData
MetaData += "Title: " + meta.Title + Environment.NewLine;
MetaData += "Subject: " + meta.Subject + Environment.NewLine;
MetaData += "Comment: " + meta.Comment + Environment.NewLine;
MetaData += "Date taken: " + meta.DateTaken +
Environment.NewLine;
MetaData += "Authors: " + meta.Author + Environment.NewLine;

/* Image data */
double mpixel = (img.PixelHeight * img.PixelWidth) /
(double)1000000;
MetaData +="Image Width: "+ img.PixelWidth + "px"+
Environment.NewLine;
MetaData +="Image Height: "+ img.PixelHeight + "px"+
Environment.NewLine;
MetaData +="Megapixels: " + mpixel + Environment.NewLine;
MetaData += "DPI: " + img.DpiX + img.DpiY
+Environment.NewLine;

// More Metadata
MetaData += "Camera Maker: " + meta.CameraManufacturer +
Environment.NewLine;
MetaData += "Camera Model: " + meta.CameraModel +
Environment.NewLine;
MetaData += "Edited in: " + meta.ApplicationName +
Environment.NewLine;
MetaData += "Copyright: " + meta.Copyright +
Environment.NewLine;

// remove unsafe characters for ajax postback

MetaData = MetaData.Replace ("<","");
MetaData = MetaData.Replace (">","");
return MetaData ;

}



This is the code i have been trying to write the data with out sucess

imageFile = "c://users//roger//documents//test.jpg";
bool done = true;
Stream jpgStream = new System.IO.FileStream(imageFile,
FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
JpegBitmapDecoder jpgDecoder = new
JpegBitmapDecoder(jpgStream,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame jpgFrame = jpgDecoder.Frames[0];
InPlaceBitmapMetadataWriter jpgInplace =
jpgFrame.CreateInPlaceBitmapMetadataWriter();
if (jpgInplace.TrySave() == true)
{

jpgInplace.SetQuery("/Text/Title", "Have a nice day");
}
jpgStream.Close();
--------------------------------------------------------------------------------------------------------


Joy said:
Hi Roger,
Can you post the code piece so that i will have more clarity on as to
what
are you trying to do and hence will be more accomplished to give my
inputs
for the same.

regards,
Joy

:

Thanks for the link.

I have looked there and tried a few examples that i have found oround
the
net.

It seems that its all a little sketchy, and i have yet to find any one
who
have got this to work.

I have found a c# libray which i am looking into now but it seems that
the
EXIF standard and MS standard are different.

If you change the tags in Vista they do not seem to match the EXIF
format.

I have spent the weekend looking into this and am able to read tags
with
no
problem at all.

Writing to the tags seems a whole different ball game.

I will keep trying.

Anymore suggestions would be welcome.

If I find away to make this work i will post the soloution.

Great New group by the way I will try and participate

Thanks again for the suggestions

Roger

Hi Roger,
Let me know if the following link was of any help to you:

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapmetadata.aspx

regards,
Joy

:

Hi all

I have managed read metadata from an image file using
BitmapMetaData,
and
that works fine,

but I am having trouble finding out how to write the information
back
to
the
Image

can anyone help with this please

Thanks in advance

Roger
 
Hi Roger,
Perhaps i have figured out why is it not working for you when you are
dealing with JPEG file, as in my case it works perfectly even for JPG file. :)

Please do the following:
1. Open the solution explorer.
2. Make sure that the JPG file gets copied to the Bin folder of the
application. This is how you can make sure that: right click the JPG file in
the solution explorer and click on Properties and then set the following
properties:
a) Build Action - Content
b) Copy to Output Directory - Copy always

Please note here that i have also tried the same code with reading the file
from a location other than the application directory e.g. c:\\smiley.jpg and
it worked perfectly in that case as well.

Please let me know if it worked for you.

regards,
Joy

Roger said:
Sorry I Have been away.

Anyway .net 3.5 and the code you suggested is what i have used except i have
change it from tiff to jpeg

I have read the skimpy examples the msdn provides.

Did you try it with a jpeg?

Thanks


Roger

Joy said:
Hi Roger,
I tried the code given on MSDN on the following Url:

http://msdn.microsoft.com/en-us/library/aa970450.aspx

And it was running perfectly for me, so please let me know which version
of
.NET are you using and also what is the specific error\exception that you
have been getting.

regards,
Joy

Roger said:
Code I have used so far

This is the class i have for reding the data which works fine
<snip>
using System.Windows.Media.Imaging;
using System.IO;
<snip>

/// <summary>
/// Returns Image MetaData Preformated in a table
/// using System.Windows.Media.Imaging (ref)
/// dot.net 3.5 standard
///
/// </summary>

public static string returnMetaData(string imgFile)
{
string MetaData = null;




BitmapSource img = BitmapFrame.Create(new Uri(imgFile));
BitmapMetadata meta = (BitmapMetadata)img.Metadata;
// MetaData
MetaData += "Title: " + meta.Title + Environment.NewLine;
MetaData += "Subject: " + meta.Subject + Environment.NewLine;
MetaData += "Comment: " + meta.Comment + Environment.NewLine;
MetaData += "Date taken: " + meta.DateTaken +
Environment.NewLine;
MetaData += "Authors: " + meta.Author + Environment.NewLine;

/* Image data */
double mpixel = (img.PixelHeight * img.PixelWidth) /
(double)1000000;
MetaData +="Image Width: "+ img.PixelWidth + "px"+
Environment.NewLine;
MetaData +="Image Height: "+ img.PixelHeight + "px"+
Environment.NewLine;
MetaData +="Megapixels: " + mpixel + Environment.NewLine;
MetaData += "DPI: " + img.DpiX + img.DpiY
+Environment.NewLine;

// More Metadata
MetaData += "Camera Maker: " + meta.CameraManufacturer +
Environment.NewLine;
MetaData += "Camera Model: " + meta.CameraModel +
Environment.NewLine;
MetaData += "Edited in: " + meta.ApplicationName +
Environment.NewLine;
MetaData += "Copyright: " + meta.Copyright +
Environment.NewLine;

// remove unsafe characters for ajax postback

MetaData = MetaData.Replace ("<","");
MetaData = MetaData.Replace (">","");
return MetaData ;

}



This is the code i have been trying to write the data with out sucess

imageFile = "c://users//roger//documents//test.jpg";
bool done = true;
Stream jpgStream = new System.IO.FileStream(imageFile,
FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
JpegBitmapDecoder jpgDecoder = new
JpegBitmapDecoder(jpgStream,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame jpgFrame = jpgDecoder.Frames[0];
InPlaceBitmapMetadataWriter jpgInplace =
jpgFrame.CreateInPlaceBitmapMetadataWriter();
if (jpgInplace.TrySave() == true)
{

jpgInplace.SetQuery("/Text/Title", "Have a nice day");
}
jpgStream.Close();
--------------------------------------------------------------------------------------------------------


Hi Roger,
Can you post the code piece so that i will have more clarity on as to
what
are you trying to do and hence will be more accomplished to give my
inputs
for the same.

regards,
Joy

:

Thanks for the link.

I have looked there and tried a few examples that i have found oround
the
net.

It seems that its all a little sketchy, and i have yet to find any one
who
have got this to work.

I have found a c# libray which i am looking into now but it seems that
the
EXIF standard and MS standard are different.

If you change the tags in Vista they do not seem to match the EXIF
format.

I have spent the weekend looking into this and am able to read tags
with
no
problem at all.

Writing to the tags seems a whole different ball game.

I will keep trying.

Anymore suggestions would be welcome.

If I find away to make this work i will post the soloution.

Great New group by the way I will try and participate

Thanks again for the suggestions

Roger

Hi Roger,
Let me know if the following link was of any help to you:

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapmetadata.aspx

regards,
Joy

:

Hi all

I have managed read metadata from an image file using
BitmapMetaData,
and
that works fine,

but I am having trouble finding out how to write the information
back
to
the
Image

can anyone help with this please

Thanks in advance

Roger
 
I will have another look,
I will have to read from a directory outside the applicaton as this is being
used as a web application and the image will be uploaded to the server.

Just for information

Also i have discovered that when you read the metadata using the example in
the msdn, that the code apprears to lock the file so you can not access it
to write any data, or delete the file.

I have used this instead

public static string getMetadata(string imageFile)
{

string msMetaData = null;


// get windows MetaData
FileStream fs = new FileStream(imageFile, FileMode.Open,
FileAccess.Read, FileShare.Read);
BitmapSource img = BitmapFrame.Create(fs);


BitmapMetadata meta = (BitmapMetadata)img.Metadata;
// MetaData
msMetaData += "Title: " + meta.Title + Environment.NewLine;
msMetaData += "Subject: " + meta.Subject + Environment.NewLine;
msMetaData += "Comment: " + meta.Comment + Environment.NewLine;
msMetaData += "Date taken: " + meta.DateTaken +
Environment.NewLine;
msMetaData += "Authors: " + meta.Author + Environment.NewLine;

/* Image data */
double mpixel = (img.PixelHeight * img.PixelWidth) /
(double)1000000;
msMetaData += "Image Width: " + img.PixelWidth + "px" +
Environment.NewLine;
msMetaData += "Image Height: " + img.PixelHeight + "px" +
Environment.NewLine;
msMetaData += "Megapixels: " + mpixel + Environment.NewLine;
msMetaData += "DPI: " + img.DpiX + img.DpiY +
Environment.NewLine;

// More Metadata
msMetaData += "Camera Maker: " + meta.CameraManufacturer +
Environment.NewLine;
msMetaData += "Camera Model: " + meta.CameraModel +
Environment.NewLine;
msMetaData += "Edited in: " + meta.ApplicationName +
Environment.NewLine;
msMetaData += "Copyright: " + meta.Copyright +
Environment.NewLine;

// remove unsafe characters for ajax postback

msMetaData = msMetaData.Replace("<", "");
msMetaData = msMetaData.Replace(">", "");

fs.Dispose();
return msMetaData;
}

I will let you know how I get on over the weekend.

Roger
Joy said:
Hi Roger,
Perhaps i have figured out why is it not working for you when you are
dealing with JPEG file, as in my case it works perfectly even for JPG
file. :)

Please do the following:
1. Open the solution explorer.
2. Make sure that the JPG file gets copied to the Bin folder of the
application. This is how you can make sure that: right click the JPG file
in
the solution explorer and click on Properties and then set the following
properties:
a) Build Action - Content
b) Copy to Output Directory - Copy always

Please note here that i have also tried the same code with reading the
file
from a location other than the application directory e.g. c:\\smiley.jpg
and
it worked perfectly in that case as well.

Please let me know if it worked for you.

regards,
Joy

Roger said:
Sorry I Have been away.

Anyway .net 3.5 and the code you suggested is what i have used except i
have
change it from tiff to jpeg

I have read the skimpy examples the msdn provides.

Did you try it with a jpeg?

Thanks


Roger

Joy said:
Hi Roger,
I tried the code given on MSDN on the following Url:

http://msdn.microsoft.com/en-us/library/aa970450.aspx

And it was running perfectly for me, so please let me know which
version
of
.NET are you using and also what is the specific error\exception that
you
have been getting.

regards,
Joy

:

Code I have used so far

This is the class i have for reding the data which works fine
<snip>
using System.Windows.Media.Imaging;
using System.IO;
<snip>

/// <summary>
/// Returns Image MetaData Preformated in a table
/// using System.Windows.Media.Imaging (ref)
/// dot.net 3.5 standard
///
/// </summary>

public static string returnMetaData(string imgFile)
{
string MetaData = null;




BitmapSource img = BitmapFrame.Create(new Uri(imgFile));
BitmapMetadata meta = (BitmapMetadata)img.Metadata;
// MetaData
MetaData += "Title: " + meta.Title + Environment.NewLine;
MetaData += "Subject: " + meta.Subject +
Environment.NewLine;
MetaData += "Comment: " + meta.Comment +
Environment.NewLine;
MetaData += "Date taken: " + meta.DateTaken +
Environment.NewLine;
MetaData += "Authors: " + meta.Author +
Environment.NewLine;

/* Image data */
double mpixel = (img.PixelHeight * img.PixelWidth) /
(double)1000000;
MetaData +="Image Width: "+ img.PixelWidth + "px"+
Environment.NewLine;
MetaData +="Image Height: "+ img.PixelHeight + "px"+
Environment.NewLine;
MetaData +="Megapixels: " + mpixel + Environment.NewLine;
MetaData += "DPI: " + img.DpiX + img.DpiY
+Environment.NewLine;

// More Metadata
MetaData += "Camera Maker: " + meta.CameraManufacturer +
Environment.NewLine;
MetaData += "Camera Model: " + meta.CameraModel +
Environment.NewLine;
MetaData += "Edited in: " + meta.ApplicationName +
Environment.NewLine;
MetaData += "Copyright: " + meta.Copyright +
Environment.NewLine;

// remove unsafe characters for ajax postback

MetaData = MetaData.Replace ("<","");
MetaData = MetaData.Replace (">","");
return MetaData ;

}



This is the code i have been trying to write the data with out sucess

imageFile = "c://users//roger//documents//test.jpg";
bool done = true;
Stream jpgStream = new System.IO.FileStream(imageFile,
FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
JpegBitmapDecoder jpgDecoder = new
JpegBitmapDecoder(jpgStream,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame jpgFrame = jpgDecoder.Frames[0];
InPlaceBitmapMetadataWriter jpgInplace =
jpgFrame.CreateInPlaceBitmapMetadataWriter();
if (jpgInplace.TrySave() == true)
{

jpgInplace.SetQuery("/Text/Title", "Have a nice day");
}
jpgStream.Close();
--------------------------------------------------------------------------------------------------------


Hi Roger,
Can you post the code piece so that i will have more clarity on as
to
what
are you trying to do and hence will be more accomplished to give my
inputs
for the same.

regards,
Joy

:

Thanks for the link.

I have looked there and tried a few examples that i have found
oround
the
net.

It seems that its all a little sketchy, and i have yet to find any
one
who
have got this to work.

I have found a c# libray which i am looking into now but it seems
that
the
EXIF standard and MS standard are different.

If you change the tags in Vista they do not seem to match the EXIF
format.

I have spent the weekend looking into this and am able to read tags
with
no
problem at all.

Writing to the tags seems a whole different ball game.

I will keep trying.

Anymore suggestions would be welcome.

If I find away to make this work i will post the soloution.

Great New group by the way I will try and participate

Thanks again for the suggestions

Roger

Hi Roger,
Let me know if the following link was of any help to you:

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapmetadata.aspx

regards,
Joy

:

Hi all

I have managed read metadata from an image file using
BitmapMetaData,
and
that works fine,

but I am having trouble finding out how to write the information
back
to
the
Image

can anyone help with this please

Thanks in advance

Roger
 
It may be worth reading this
http://forums.msdn.microsoft.com/en-US/wpf/thread/8f297b11-99ba-459c-b085-1ff3ae526487/

as it looks like this is all a little flawed and un reliable if there is not
enough space in the file, so looks like you have to copy the jpg and rewirte
the whole thing.

Anyway Jay has said it works, I have run it and it does not error but there
are no changes in the data :(


Roger

Roger said:
I will have another look,
I will have to read from a directory outside the applicaton as this is
being used as a web application and the image will be uploaded to the
server.

Just for information

Also i have discovered that when you read the metadata using the example
in the msdn, that the code apprears to lock the file so you can not access
it to write any data, or delete the file.

I have used this instead

public static string getMetadata(string imageFile)
{

string msMetaData = null;


// get windows MetaData
FileStream fs = new FileStream(imageFile, FileMode.Open,
FileAccess.Read, FileShare.Read);
BitmapSource img = BitmapFrame.Create(fs);


BitmapMetadata meta = (BitmapMetadata)img.Metadata;
// MetaData
msMetaData += "Title: " + meta.Title + Environment.NewLine;
msMetaData += "Subject: " + meta.Subject + Environment.NewLine;
msMetaData += "Comment: " + meta.Comment + Environment.NewLine;
msMetaData += "Date taken: " + meta.DateTaken +
Environment.NewLine;
msMetaData += "Authors: " + meta.Author + Environment.NewLine;

/* Image data */
double mpixel = (img.PixelHeight * img.PixelWidth) /
(double)1000000;
msMetaData += "Image Width: " + img.PixelWidth + "px" +
Environment.NewLine;
msMetaData += "Image Height: " + img.PixelHeight + "px" +
Environment.NewLine;
msMetaData += "Megapixels: " + mpixel + Environment.NewLine;
msMetaData += "DPI: " + img.DpiX + img.DpiY +
Environment.NewLine;

// More Metadata
msMetaData += "Camera Maker: " + meta.CameraManufacturer +
Environment.NewLine;
msMetaData += "Camera Model: " + meta.CameraModel +
Environment.NewLine;
msMetaData += "Edited in: " + meta.ApplicationName +
Environment.NewLine;
msMetaData += "Copyright: " + meta.Copyright +
Environment.NewLine;

// remove unsafe characters for ajax postback

msMetaData = msMetaData.Replace("<", "");
msMetaData = msMetaData.Replace(">", "");

fs.Dispose();
return msMetaData;
}

I will let you know how I get on over the weekend.

Roger
Joy said:
Hi Roger,
Perhaps i have figured out why is it not working for you when you are
dealing with JPEG file, as in my case it works perfectly even for JPG
file. :)

Please do the following:
1. Open the solution explorer.
2. Make sure that the JPG file gets copied to the Bin folder of the
application. This is how you can make sure that: right click the JPG file
in
the solution explorer and click on Properties and then set the following
properties:
a) Build Action - Content
b) Copy to Output Directory - Copy always

Please note here that i have also tried the same code with reading the
file
from a location other than the application directory e.g. c:\\smiley.jpg
and
it worked perfectly in that case as well.

Please let me know if it worked for you.

regards,
Joy

Roger said:
Sorry I Have been away.

Anyway .net 3.5 and the code you suggested is what i have used except i
have
change it from tiff to jpeg

I have read the skimpy examples the msdn provides.

Did you try it with a jpeg?

Thanks


Roger

Hi Roger,
I tried the code given on MSDN on the following Url:

http://msdn.microsoft.com/en-us/library/aa970450.aspx

And it was running perfectly for me, so please let me know which
version
of
.NET are you using and also what is the specific error\exception that
you
have been getting.

regards,
Joy

:

Code I have used so far

This is the class i have for reding the data which works fine
<snip>
using System.Windows.Media.Imaging;
using System.IO;
<snip>

/// <summary>
/// Returns Image MetaData Preformated in a table
/// using System.Windows.Media.Imaging (ref)
/// dot.net 3.5 standard
///
/// </summary>

public static string returnMetaData(string imgFile)
{
string MetaData = null;




BitmapSource img = BitmapFrame.Create(new Uri(imgFile));
BitmapMetadata meta = (BitmapMetadata)img.Metadata;
// MetaData
MetaData += "Title: " + meta.Title + Environment.NewLine;
MetaData += "Subject: " + meta.Subject +
Environment.NewLine;
MetaData += "Comment: " + meta.Comment +
Environment.NewLine;
MetaData += "Date taken: " + meta.DateTaken +
Environment.NewLine;
MetaData += "Authors: " + meta.Author +
Environment.NewLine;

/* Image data */
double mpixel = (img.PixelHeight * img.PixelWidth) /
(double)1000000;
MetaData +="Image Width: "+ img.PixelWidth + "px"+
Environment.NewLine;
MetaData +="Image Height: "+ img.PixelHeight + "px"+
Environment.NewLine;
MetaData +="Megapixels: " + mpixel +
Environment.NewLine;
MetaData += "DPI: " + img.DpiX + img.DpiY
+Environment.NewLine;

// More Metadata
MetaData += "Camera Maker: " + meta.CameraManufacturer +
Environment.NewLine;
MetaData += "Camera Model: " + meta.CameraModel +
Environment.NewLine;
MetaData += "Edited in: " + meta.ApplicationName +
Environment.NewLine;
MetaData += "Copyright: " + meta.Copyright +
Environment.NewLine;

// remove unsafe characters for ajax postback

MetaData = MetaData.Replace ("<","");
MetaData = MetaData.Replace (">","");
return MetaData ;

}



This is the code i have been trying to write the data with out sucess

imageFile = "c://users//roger//documents//test.jpg";
bool done = true;
Stream jpgStream = new System.IO.FileStream(imageFile,
FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
JpegBitmapDecoder jpgDecoder = new
JpegBitmapDecoder(jpgStream,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame jpgFrame = jpgDecoder.Frames[0];
InPlaceBitmapMetadataWriter jpgInplace =
jpgFrame.CreateInPlaceBitmapMetadataWriter();
if (jpgInplace.TrySave() == true)
{

jpgInplace.SetQuery("/Text/Title", "Have a nice
day");
}
jpgStream.Close();
--------------------------------------------------------------------------------------------------------


Hi Roger,
Can you post the code piece so that i will have more clarity on as
to
what
are you trying to do and hence will be more accomplished to give my
inputs
for the same.

regards,
Joy

:

Thanks for the link.

I have looked there and tried a few examples that i have found
oround
the
net.

It seems that its all a little sketchy, and i have yet to find any
one
who
have got this to work.

I have found a c# libray which i am looking into now but it seems
that
the
EXIF standard and MS standard are different.

If you change the tags in Vista they do not seem to match the EXIF
format.

I have spent the weekend looking into this and am able to read
tags
with
no
problem at all.

Writing to the tags seems a whole different ball game.

I will keep trying.

Anymore suggestions would be welcome.

If I find away to make this work i will post the soloution.

Great New group by the way I will try and participate

Thanks again for the suggestions

Roger

Hi Roger,
Let me know if the following link was of any help to you:

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapmetadata.aspx

regards,
Joy

:

Hi all

I have managed read metadata from an image file using
BitmapMetaData,
and
that works fine,

but I am having trouble finding out how to write the
information
back
to
the
Image

can anyone help with this please

Thanks in advance

Roger
 
Back
Top