How to convert all image file into jpeg with specific dimension in asp.net using vb

Hi

we purchased Aspose.Total api,we need to convert image file to jpeg format,the following extension file convert to jpeg format and only first page if tiff file have more than one page.

If ((ext.ToLower = “ccitt”) Or (ext.ToLower = “gif”) Or (ext.ToLower = “jpeg”) Or (ext.ToLower = “jpg”) Or (ext.ToLower = “png”) Or (ext.ToLower = “tif”) Or (ext.ToLower = “tiff”) Or (ext.ToLower = “bmp”) Or (ext.ToLower = “emf”) Or (ext.ToLower = “exif”) Or (ext.ToLower = “icon”) Or (ext.ToLower = “wmf”)) Then

I mean if tiff have 5 pages,then only 1st page only convert to jpeg format and also need to pass widht and height of the jpeg file(150X150)

Below code we used for image to pdf format conversion
Dim inputfile As String = “D:\error\support.tiff”
Dim outputfile As String = “D:\error\support.pdf”

Dim imageLicense As Aspose.Imaging.License = New Aspose.Imaging.License()
imageLicense.SetLicense(ConfigurationManager.AppSettings(“AsposeLic”))

Dim pdfLicense As Aspose.Pdf.License = New Aspose.Pdf.License()
pdfLicense.SetLicense(ConfigurationManager.AppSettings(“AsposeLic”))

’ instantiate Document Object
Dim doc As Document = New Document()
’ add a page to pages collection of document
Dim page As Aspose.Pdf.Page = doc.Pages.Add()
’ load the source image file to Stream object
Dim fs As FileStream = New FileStream(inputfile, FileMode.Open, FileAccess.Read)
Dim tmpBytes(fs.Length) As Byte
fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length))

Dim mystream As MemoryStream = New MemoryStream(tmpBytes)
’ instantiate BitMap object with loaded image stream
Dim b As Bitmap = New Bitmap(mystream)

’ Set margins so image will fit, etc.
page.PageInfo.Margin.Bottom = 0
page.PageInfo.Margin.Top = 0
page.PageInfo.Margin.Left = 0
page.PageInfo.Margin.Right = 0
page.PageInfo.Height = b.Height
page.PageInfo.Width = b.Width

'page.PageInfo.Height = “21.59”
'page.PageInfo.Width = “27.94”



''page.CropBox = New Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height)
'Create an image object
Dim image1 As Aspose.Pdf.Image = New Aspose.Pdf.Image()
'Add the image into paragraphs collection of the section
page.Paragraphs.Add(image1)
’ set the image file stream
image1.ImageStream = mystream
’ save resultant PDF file
doc.Save(outputfile)

'close memoryStream object
fs.Close()
fs.Dispose()
mystream.Close()
mystream.Dispose()

But need to convert jpeg format only including jpeg file,bcz out put jpeg we specify dimension (150X150)

Regards
Aravind
Hi Aravind,

Thank you for your inquiry.

Please access the link Exporting Images to BMP, JPEG, PNG and TIFF Formats for information on how you can convert images to other image formats. Following is the sample code snippet for your reference. This code snippet demonstrates how you can convert a single TIFF frame to JPEG format.


Dim filePath As [String] = "C:\Input\Image2.tiff"
Dim extension As String = Path.GetExtension(filePath).ToLower()
If extension = ".tiff" Then
Dim objImage As TiffImage = DirectCast(Aspose.Imaging.Image.Load(filePath), TiffImage)
objImage.Frames(0).Save("C:\output.jpeg", New Aspose.Imaging.ImageOptions.JpegOptions())
End If
If extension = ".png" Then
Dim image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load(filePath)
image.Save("C:\output.jpeg", New Aspose.Imaging.ImageOptions.JpegOptions())
End If

Hi

I am try with ur code,only tiff and tif file conversion work file,i am change ur code like this
Dim inputfile As String = “D:\error\support.png”
Dim outputfile As String = “D:\error\support.jpeg”

Dim imageLicense As Aspose.Imaging.License = New Aspose.Imaging.License()
imageLicense.SetLicense(ConfigurationManager.AppSettings(“AsposeLic”))

Dim filePath As [String] = inputfile
Dim extension As String = Path.GetExtension(filePath).ToLower()

If extension = “.tiff” Or extension = “.tif” Then
Dim objImage As TiffImage = DirectCast(Aspose.Imaging.Image.Load(filePath), TiffImage)
objImage.Frames(0).Save(outputfile, New Aspose.Imaging.ImageOptions.JpegOptions())

Else
Dim image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load(filePath)
image.Save(outputfile, New Aspose.Imaging.ImageOptions.JpegOptions())
End If

Only tiff/tif execute if part,other than that file it execute else part,but other format file(bmp,png) conversion output file(jpeg) not same as orginal image here i attach output from bmp and png.

http:// prntscr.com/971o24
http:// prntscr.com/971miv

Need convert following format to jpeg ,even jpeg to jpeg,bcz need to specify output file dimension (150X150)
ccitt,gif,jpeg,jpg,png,tif,tiff,bmp,emf,exif,icon,wmf


Regards
Aravind

Hi Aravind,

Use the following lines of code to save the image as BMP and PNG.

'Export to BMP file format using the default options image.Save("C:\output.bmp", New Aspose.Imaging.ImageOptions.BmpOptions())

'Export to PNG file format using the default options
image.Save(“C:\output.png”, New Aspose.Imaging.ImageOptions.PngOptions())


Further, please go through the article Exporting Images to BMP, JPEG, PNG and TIFF Formats for more information on how you can convert images to other image formats.

Hi Aravind,

Please note that Aspose.Imaging for .NET supports following file formats.

  • DWG
  • DXF
  • PDF
  • PSD
  • DjVu
  • BMP
  • JPEG
  • GIF
  • TIFF
  • PNG

Following are the line of codes that you can use to load the file according to the file extension in the IF condition of your program.

'Load a DjVu image

Dim image As Aspose.Imaging.FileFormats.Djvu.DjvuImage = CType(Aspose.Imaging.Image.Load(sourceFilename), Aspose.Imaging.FileFormats.Djvu.DjvuImage)
'Load a PSD image
Dim image As Aspose.Imaging.FileFormats.Psd.PsdImage = CType(Aspose.Imaging.Image.Load(sourceFilename), Aspose.Imaging.FileFormats.Psd.PsdImage)
'Load a DXF image
Dim image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load("sample.dxf")
'Load a DWG image
Dim image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load("sample.dwg")
'Load BMP
Dim image As Aspose.Imaging.FileFormats.Bmp.BmpImage = CType(Aspose.Imaging.Image.Load(sourceFilename), Aspose.Imaging.FileFormats.Bmp.BmpImage)
'Load JPEG
Dim image As Aspose.Imaging.FileFormats.Jpeg.JpegImage = CType(Aspose.Imaging.Image.Load(sourceFilename), Aspose.Imaging.FileFormats.Jpeg.JpegImage)
'Load GIF
Dim image As Aspose.Imaging.FileFormats.Gif.GifImage = CType(Aspose.Imaging.Image.Load(sourceFilename), Aspose.Imaging.FileFormats.Gif.GifImage)
'Load TIFF
Dim image As Aspose.Imaging.FileFormats.Tiff.TiffImage = CType(Aspose.Imaging.Image.Load(sourceFilename), Aspose.Imaging.FileFormats.Tiff.TiffImage)
'Load PNG
'Dim image As Aspose.Imaging.FileFormats.Png.PngImage = CType(Aspose.Imaging.Image.Load(sourceFilename), Aspose.Imaging.FileFormats.Png.PngImage)

You can perform Resize operation on an image. Resize method for the Image class has been exposed that can be used to re-size the image. Please follow the link Resizing Images for more detail.

Further, we need the sample images that you are trying to convert at your end. This will help us to investigate the issue.

Hope the above information helps. Feel free to contact us in case of any query or comments.

Hi Aravind,

Please forward us the sample images that you are trying to convert at your end. We will try to reproduce the issue at our and will update you with our findings.

Hi

Here i attach that sample files.

Regards
Aravind
Hi Aravind,

Thank you for providing sample images.

Please note that we have evaluated the scenario by using images provided by you. It was found that the Aspose.Imaging is converting “bmp Apple.bmp” very well. It successfully creates the JPEG file. Sample output files have been attached for your reference.
However, we are able to observe the issues with images “icnagtsoftwared.png” and “panda.bmp”. The issues have been logged into our system with ID IMAGING-35071 and IMAGING-35072 respectively. Our product team will look into it. We will update you accordingly via this thread.

Hi Aravind,

Please find the attached output image files with this post. You can use Resize method of the Image class to specify width and height of the output image file. Please follow the link Resizing Images for more detail.

Hi

Thank you fro your reply,i use Resize method,but after resize,content not good to see,here i attach output file in New folder (2).zip
This is code i used for image file to jpeg.
E.g: jpg to jpeg with size

Dim inputfile As String = “D:\error\support.bmp”
Dim outputfile As String = “D:\error\support.jpeg”

Dim imageLicense As Aspose.Imaging.License = New Aspose.Imaging.License()
imageLicense.SetLicense(ConfigurationManager.AppSettings(“AsposeLic”))

Dim filePath As [String] = inputfile
Dim extension As String = Path.GetExtension(filePath).ToLower()

If extension = “.tiff” Or extension = “.tif” Then
Dim objImage As TiffImage = DirectCast(Aspose.Imaging.Image.Load(filePath), TiffImage)
objImage.Frames(0).Save(outputfile, New Aspose.Imaging.ImageOptions.JpegOptions())

Else
Dim image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load(filePath)
image.Save(outputfile, New Aspose.Imaging.ImageOptions.JpegOptions())
End If

Using image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load(outputfile)
image.Resize(300, 300)
image.Save()
End Using


Hi Aravind,

Please find the attached output image with this post and find the code snippet below for your reference.

'Load BMP
Dim objImage As Aspose.Imaging.FileFormats.Bmp.BmpImage = DirectCast(Aspose.Imaging.Image.Load("D:\imaging_files\support.bmp"), Aspose.Imaging.FileFormats.Bmp.BmpImage)
' Resize image
objImage.Resize(200, 200)
' Save BMP image as JPEG
objImage.Save("D:\imaging_files\support.jpeg", New Aspose.Imaging.ImageOptions.JpegOptions())

Hope the above information helps. Feel free to contact us in case you have any query or comments.

The issues you have found earlier (filed as IMAGING-35072;IMAGING-35071) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

The issues you have found earlier (filed as IMAGING-35071;IMAGING-35072) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

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