Converting image formats to 8bit or 16bit grayscale

Hi,


I am also wondering if Aspose can convert image formats such as .gif, .bmp, .tif, .jpg, .png files into grayscale 8bit or 16 bit formats? I have seen that the library just does a conversion but not to grayscale.

I am wondering if Aspose can convert text files into .pdf format, just like it converts the word files into .pdf format. I need the images to be in grayscale 8 or 16 bit.

Thanks,
I need the info asap!

Hi,

Please use the following code for conversion to grayscale images.

// Create an instance of Image and load an existing file
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(filepath))
{
    // Create an instance of PsdSaveOptions and set its advanced properties
    Aspose.Imaging.SaveOptions.PsdSaveOptions saveOptions = new Aspose.Imaging.SaveOptions.PsdSaveOptions();
    saveOptions.ColorMode = ColorModes.Grayscale;
    saveOptions.CompressionMethod = CompressionMethod.Raw;

    //Save the Image to PSD format
    image.Save("c:\\Output.psd", saveOptions);
}

Best Regards,

I see that this format works for all the image formats, but is there a way to make the image size even smaller, some of the grayscale files are larger than the real files.


thanks

Hi,

Sorry, this feature is not available at the moment but a request for this feature has been logged into our issue tracking system as IMAGING-31990. We will keep you updated on this issue in this thread.

Please feel free to contact us in case you have further comments or questions.

Best Regards,

I am also wondering if there is a way to combine multiple png files. Like, when I convert word document into png, I will get a png file for each page. If I have a word document with 10 pages, I will get about 10 png files. I want to attach all those png files into one png file. I know I can do that with with other formats, but the requirement is that it needs to stay as a png file.


Thanks

Also, is there anyway to specify the resolution of the outputted PNG file when images are converted? I am currently looking at multiple tools for a web service that I am developing. Aspose meets all my requirements but it is converting some of the images into bigger files than the original files, even after converting them to grayscale. I need the grayscale image files to be much smaller. Some of the images have a black border around them, which might be increasing the file size.

Here are the results I have gotten from the conversion:

File Format Original File Size(kb) Converted File Size(kb)
bmp 467 155
gif 386 157
png 62 351
jpg 581 3250
tif 198 300

I know you said that it is not possible to make them smaller before, but I am wondering if the resolution can be tweaked, just like Aspose.Words images to make them smaller. I need the information as soon as possible, so I can inform the management about what tool to buy for our development.

Hi,

You can use the following C# code to combine multiple images in one PNG image. Check Output.png for results.

License lic = new License();
lic.SetLicense(@"Aspose.Total.Product.Family.lic");

string file1Path = "c:\\Sample1.jpg";
string file2Path = "c:\\Sample2.jpg";
string file3Path = "c:\\Sample3.jpg";

//Create an instance of Image and load an existing file
using (Aspose.Imaging.Image image1 = Aspose.Imaging.Image.Load(file1Path))
{
    //Create a new image with smaller size
    Aspose.Imaging.CreateOptions.PngCreateOptions createOptions = new Aspose.Imaging.CreateOptions.PngCreateOptions();
    createOptions.Height = 1200;
    createOptions.Width = 600;
    createOptions.Source = new Aspose.Imaging.Sources.FileCreateSource("C:\\Temp\\Temp.png", true);

    Aspose.Imaging.Image newImage = Aspose.Imaging.Image.Create(createOptions);

    //Draw existing sample image on the new image
    Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(newImage);
    graphics.Clear(Aspose.Imaging.Color.White);
    graphics.DrawImage(image1, new RectangleF(0, 0, 600, 400));

    using (Aspose.Imaging.Image image2 = Aspose.Imaging.Image.Load(file2Path))
    {
        graphics.DrawImage(image2, new RectangleF(0, 400, 600, 400));
    }

    using (Aspose.Imaging.Image image3 = Aspose.Imaging.Image.Load(file3Path))
    {
        graphics.DrawImage(image3, new RectangleF(0, 800, 600, 400));
    }

    newImage.Save("c:\\Output.png", new Aspose.Imaging.SaveOptions.PngSaveOptions());
}

You can use the following C# code to save bigger images as smaller grayscale images.

License lic = new License();
lic.SetLicense(@"Aspose.Total.Product.Family.lic");

string filePath = "c:\\Sample1.jpg";

//Create an instance of Image and load an existing file
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(filePath))
{
    //Create a new image with smaller size
    Aspose.Imaging.CreateOptions.PngCreateOptions createOptions = new Aspose.Imaging.CreateOptions.PngCreateOptions();
    createOptions.Height = 400;
    createOptions.Width = 600;
    createOptions.Source = new Aspose.Imaging.Sources.FileCreateSource("C:\\Temp\\Temp.png", true);

    Aspose.Imaging.Image newImage = Aspose.Imaging.Image.Create(createOptions);

    //Draw existing sample image on the new image
    Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(newImage);
    graphics.Clear(Aspose.Imaging.Color.White);
    graphics.DrawImage(image, newImage.Bounds);

    //Create an instance of PsdSaveOptions and set its advanced properties
    Aspose.Imaging.SaveOptions.PsdSaveOptions saveOptions = new Aspose.Imaging.SaveOptions.PsdSaveOptions();
    saveOptions.ColorMode = ColorModes.Grayscale;
    saveOptions.CompressionMethod = CompressionMethod.Raw;

    newImage.Save("c:\\Output.psd", saveOptions);
}

Please feel free to contact us in case you have further comments or questions.

Best Regards

Attaching the png files worked. Thanks

The converted picture files are still large when converted from .jpg to png.

I am also getting "Cannot find license 'Aspose.Total.Product.Family.lic'." when I don't comment out the licence part.

Also my requirement is to convert the images to "8 or 16 bit grayscale PNG" format. The first code sample that you have provided be converts it to 24 bit and just removes color in the image grayscale.

Is there a way to specify the bit amount in aspose.imaging? aspose.words seems to have it.

Thanks

Hi,

1. PNG always has the larger size as compared to JPG because it provides better quality. You need to change the resolution if you want to change the size of the output PNG.

2. You need to provide a valid license file to SetLicense method. Please change the path to a valid license file. If you do not have a license file, you need to either comment the license part or apply for a temporary license by following these guidelines

Please feel free to contact us in case you have further comments or questions.

Best Regards,

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.

@stycool24
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): IMAGINGNET-1888

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.