Solved

convert tif to png

Posted on 2013-01-30
3
411 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Sedgwick Worked great!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

744 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

9 Experts available now in Live!

Get 1:1 Help Now