Hi

I have a problem which i cant seem to solve or font really know where to start im only starting learning c# so dont have a lot of experience.
Basically my problem is that i intend to loop through a directory of .tif images which contain BW and Colour pages, i do a check to identify the colour pages which i use a third party control to help do this, when i find a colour page i want to be able to split this page out to a .jpeg image but dont really know how to do it anyway this is as far as i have got.

// Get list of source files
string inFolder = String.Format("{0}{1}{2}",
sourcePath, Path.DirectorySeparatorChar, document);
      foreach (string srcFile in Directory.GetFiles(inFolder, "*.tif"))
      {
        // Open the source file
        ImagistikTK.TK tifImg = new TK();
        tifImg.OpenFile.FileName = srcFile; 
        tifImg.OpenFile.Licensecode = "";
        float result = tifImg.OpenFile_Execute();

        if (result == 0)
        {
          // Check are there any color pages?
          for(int i = 1; i<= tifImg.Info.Pages; i++)
          {
            ImagistikTK.TK page = new TK();
            page.OpenFile.Licensecode = "";
            page.OpenFile.FileName = srcFile;
            page.OpenFile.PageNumber = i;
            page.OpenFile_Execute(); 

            int pageNum = i;

            if(page.BMP_TK.PixelFormat == PixelFormat.Format24bppRgb)
            {
              string destFile = String.Format("{0:0000000}{1}", destFileNo, ".jpg");
              // Yes - split file

              FileStream inFile = new FileStream(srcFile, FileMode.Open, FileAccess.Read);

              FileStream outFile = new FileStream(i + ".jpeg", FileMode.Create, FileAccess.Write);

Any help appreciated.

I believe you can convert the image using the Image.Save method. So, instead of using FileStream:

Image img = Image.FromFile(srcFile); // load tiff
                img.Save(i + ".jpeg", ImageFormat.Jpeg); // save as jpeg

I think will work, but I'm not 100% sure.

I believe you can convert the image using the Image.Save method. So, instead of using FileStream:

Image img = Image.FromFile(srcFile); // load tiff
                img.Save(i + ".jpeg", ImageFormat.Jpeg); // save as jpeg

I think will work, but I'm not 100% sure.

Okay cheers, is there any way to handle the 'jpeg' conversion quality of the image?

JPEG is a lossy format. You can pick another image format to save the image. Or do you have something else in mind?

JPEG is a lossy format. You can pick another image format to save the image. Or do you have something else in mind?

Sorry i should have mentioned that i have to keep file size under 4mb, so if i split a colour page from a tif image i dont think it can be lossy or lossless as the size might be too big but i was thinking is there a way to save say at 75% or something?

Sorry i should have mentioned that i have to keep file size under 4mb, so if i split a colour page from a tif image i dont think it can be lossy or lossless as the size might be too big but i was thinking is there a way to save say at 75% or something?

An image is either lossy or lossless. It has to be one or the other. What are you wanting to save 75% of? You have resolution, color palette, different types of compression, etc. How large are these TIF images? Does the end result have to be a jpeg image?

At the min the test data that i have is a set of tif images some containing multiple colour pages and multiple BW pages, basically i have to check through the tif images and spilt out the colour pages to jpeg and leave the BW as multipage tif. At the min some of these tif files are upwards of 30mb. What i need to know/understand is if i split a colour page to jpeg and is over 4mb(which is my max allowed file size) is there a way to reduce the quality to 75% instead of being lossless?

If you go from 100% to 75% you are throwing away quality, ie lossy. This is starting to sound like pretty advanced image processing requirements. Does the ImagistikTK library provide you with advanced imaging routines? I have code for this but it uses the Atalasoft dotImage library so it wouldn't do you any good, unless you have that library.

I did a quick google and came up with this article:
http://www.geekpedia.com/tutorial232_Reducing-JPEG-Picture-Quality-using-Csharp.html

ImagistikTK only has limited advanced imaging methods and the documentation is really bad. That library you are using seems very good although a bit expensive for what i need. Anyway i have got sorted thanks to your link to geekpedia using EncoderParameters so thanks!

i Cant draw triangle using * in a console application by using for loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.