Link to home
Start Free TrialLog in
Avatar of r3nder
r3nderFlag for United States of America

asked on

convert tif to png

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

ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abmalokar
abmalokar

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();
Avatar of r3nder

ASKER

Thanks Sedgwick Worked great!