Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

convert tif to png

Posted on 2013-01-30
3
Medium Priority
?
434 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:
Meir Rivkin earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project

877 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