Solved

convert tif to png

Posted on 2013-01-30
3
414 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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now