This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

MediaUnsupportedException error

HI all i am using Graphics Mill to set a image in the psd file but i am getting error
when i reach this following code

Aurigma.GraphicsMill.Bitmap photo = new Aurigma.GraphicsMill.Bitmap(stream);




i am using the code

if (fpUplaodLogo.HasFile)
{
using (BinaryReader reader = new BinaryReader
(fpUplaodLogo.PostedFile.InputStream))
{
image = (byte[])(reader.ReadBytes
(fpUplaodLogo.PostedFile.ContentLength));
// SaveImage(image);
}
}

//byte[] data = (byte[])(["Photo"]);
System.IO.MemoryStream stream = new System.IO.MemoryStream();


int offset = 78;
stream.Write(image, offset, image.Length - offset);


try
{
Aurigma.GraphicsMill.Bitmap photo = new Aurigma.GraphicsMill.Bitmap(stream);

updatedLayers.Add("image", photo);
updatedLayers.Add("title1", txtComNm.Text);
updatedLayers.Add("title2", txtCompDesc.Text);
updatedLayers.Add("heading ", txtComNm.Text);

imgFastTrackPsd.Visible = true;
BitmapViewer1.Bitmap = RasterizePsd(Server.MapPath("/psdimage/Add2.psd"), updatedLayers);
}
catch (Aurigma.GraphicsMill.Codecs.MediaUnsupportedException)
{
updatedLayers.Add("title1", txtComNm.Text);
updatedLayers.Add("title2", txtCompDesc.Text);
updatedLayers.Add("heading ", txtComNm.Text);
updatedLayers.Add("subheading", txtCompDesc.Text);
updatedLayers.Add("salary-details", txtAbtUs.Text);
updatedLayers.Add("locations-details", txtLoc.Text);
// updatedLayers.Add("aboutus", txtAbtUs.Text);

updatedLayers.Add("keyrequirements-details", txtKeyRequirement.Text);
updatedLayers.Add("whyshouldyouapply-details", txtYApply.Text);
updatedLayers.Add("numberofpositions-details", txtNoPos.Text);

updatedLayers.Add("other-details", txtOthers.Text);
updatedLayers.Add("joborderdetails-details", txtJODet.Text);
imgFastTrackPsd.Visible = true;
BitmapViewer1.Bitmap = RasterizePsd(Server.MapPath("/psdimage/Spotlighter-Add2.psd"), updatedLayers);
}


my problem is that when i upload a jpg image i am getting MediaUnsupportedException error . any help most appreciated can u pls any one tell where i am worng

thanks and regards,
sunil T
Hello,

It is hard to debug code on the forum, but I will try 🙂 I need some additional information, so could you answer the following questions:

1) On which line of the posted code exception is thrown? Here?
Aurigma.GraphicsMill.Bitmap photo = 
       new Aurigma.GraphicsMill.Bitmap(stream);


2) Why do you cut off the first 78 bytes of the input stream?

image = (byte[])reader.ReadBytes(
       fpUplaodLogo.PostedFile.ContentLength);
...
System.IO.MemoryStream stream = new System.IO.MemoryStream();

int offset = 78;
stream.Write(image, offset, image.Length - offset);
...
Aurigma.GraphicsMill.Bitmap photo = 
       new Aurigma.GraphicsMill.Bitmap(stream);


And I think that there should be MemoryStream.Seek() method call to move stream position to the begin of source data before Aurigma.GraphicsMill.Bitmap constructor call.