Solved

convert tif to png

Posted on 2013-01-30
3
416 Views
Last Modified: 2013-02-03
I have an image that I have saved in a widows form and when a user goes to use it it says you have to file association - even after I associated the file typew on there pc
I am trying to convert  till images to png now - the error I am geting isd connot implicitly convert type void to system.drawing.image - what am I doing wrong
        private void ShowImage(int ID)
        {
            try
            {
                int @id = ID;
                string conString = ConfigurationManager.ConnectionStrings["Manager"].ToString();
                SqlConnection conn = new SqlConnection(conString);
                SqlDataAdapter da = new SqlDataAdapter("spx_MsgUploadFiles_Pull", conn);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                da.SelectCommand.Parameters.AddWithValue("@id", id);
                DataSet ds = new DataSet("read");
                conn.Open();
                da.Fill(ds, "read");
                conn.Close();
                //storing the file in byte array 
                byte[] MyData = new byte[0];
                DataRow myRow;
                myRow = ds.Tables["read"].Rows[0];
                MyData = (byte[])myRow["Document_File"];
                string name = myRow["filename"].ToString();
                int ArraySize = new int();
                ArraySize = MyData.GetUpperBound(0);
                if (ArraySize > -1)
                {

                    string temp = ConfigurationManager.AppSettings["AppfileLogRootPath"];
                    string path = temp + name;
                    File.WriteAllBytes(path, MyData);
                    byte[] pdf = (byte[])myRow["Document_File"];
                    Image image;
                    using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open))

                        image = Image.FromStream(fs).Save(path, System.Drawing.Imaging.ImageFormat.Png); <-- error here/////////////////////////
                    
                    pbImage.Image = image;
                }
            }
            catch (Exception exShowImage)
            {
                MessageBox.Show(exShowImage.Message.ToString());
            }

Open in new window

0
Comment
Question by:r3nder
3 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38837346
Save doesn't return value so u cannot assign it to image, that should be separately:

  using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open)){
//save the image as png in path
                        Image.FromStream(fs).Save(path, System.Drawing.Imaging.ImageFormat.Png); 

}

pbImage.Image  = Image.FromFile(path);//the png image

Open in new window

0
 
LVL 1

Expert Comment

by:abmalokar
ID: 38838330
You can use System.Drawing.Bitmap

                        ImgOperations _ImgOperations = new ImgOperations();
                        MemoryStream ms = new MemoryStream(byteArrayIn);
                        System.Drawing.Bitmap _TestBitmap = new System.Drawing.Bitmap(ms);
                        _TestBitmap.SetResolution(72, 72);
                        _TestBitmap.Save(filename,ImageFormat.Png);
                        _TestBitmap.Dispose();
                        ms.Dispose();
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 38849214
Thanks Sedgwick Worked great!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

775 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question