Victor Charles
asked on
Help with changing file extension from TIFF to PNG using VB.NET
Hi,
How do I change all file extensions from TIFF to PNG in my images subfolder using VB.NET?
Thanks,
Victor
How do I change all file extensions from TIFF to PNG in my images subfolder using VB.NET?
Thanks,
Victor
try
My.Computer.FileSystem.Ren ameFile("C :\*.tiff", "*.png")
My.Computer.FileSystem.Ren
My code above actually changes the image of type "Tiff" to type "png". I think I may have misunderstood your question. Do you really just need to rename files?
if it does not support wildcard, something like this will do the job
Dim dir As String = "c:\test"
Dim path As String = "*.tiff"
Dim dirInfo As New DirectoryInfo(dir)
For Each fileInfo As FileInfo In dirInfo.GetFiles(path)
My.Computer.FileSystem.RenameFile(fileInfo.FullName, replace(fileInfo.FullName.toLowercase(),".tiff",".png"))
To follow up on David's excellent comment, you almost surely do not want to simply change the file extension from TIFF to PNG — unless you know that they are really PNG files that were mistakenly named as TIFF files. Otherwise, you need to convert the TIFF files to PNG files, as David correctly noted. The point is, TIFF and PNG are different file formats — you must convert from one to the other, not just rename them. Regards, Joe
if you want to mass resize/crop/convert etc, this is the excellent application and free
http://www.faststone.org/FSResizerDetail.htm
FastStone Photo Resizer is an image converter and renaming tool that intends to enable users to convert, rename, resize, crop, rotate, change color depth, add text and watermarks to images in a quick and easy batch mode. Drag and Drop mouse operation is well supported.
http://www.faststone.org/FSResizerDetail.htm
FastStone Photo Resizer is an image converter and renaming tool that intends to enable users to convert, rename, resize, crop, rotate, change color depth, add text and watermarks to images in a quick and easy batch mode. Drag and Drop mouse operation is well supported.
- Convert and Rename images in batch mode
- Support JPEG, BMP, GIF, PNG, TIFF and JPEG2000
- Resize, crop, change color depth, apply color effects, add text, watermark and border effects
- Rename images with sequential number
- Search and replace texts in the file names
- Preview conversion and renaming
- Support folder/non-folder structure
- Load and save settings
- And much more...
ASKER
Hi,
Thanks for all the comments. I need to convert to PNG.
Victor
Thanks for all the comments. I need to convert to PNG.
Victor
> if you want to mass resize/crop/convert etc, this is the excellent application and free
There are many excellent, free apps that can do mass converting, cropping, resizing, etc., such as GIMP, ImageMagick, IrfanView, and more. I published three articles here at EE about one of them — GraphicsMagick (a fork of ImageMagick):
Reduce the file size of many JPG files in many folders via an automated, mass, batch compression method
Create a PDF file with Contact Sheets (montage of thumbnails) for all JPG files in a folder and each of its subfolders using an automated, batch method
Create an image (BMP, GIF, JPG, PNG, TIF, etc.) from a multi-page PDF
And also published a video on GIMP:
How to divide/split a single image file into multiple image files
But keep in mind that Victor wants to use VB.Net, so I recommend using one of the imaging programs that can easily be called from the command line, such as ImageMagick and IrfanView (it is extremely easy to run the ImageMagick and IrfanView stand-alone executables with command line parameters from any language that can make command line calls). Regards, Joe
There are many excellent, free apps that can do mass converting, cropping, resizing, etc., such as GIMP, ImageMagick, IrfanView, and more. I published three articles here at EE about one of them — GraphicsMagick (a fork of ImageMagick):
Reduce the file size of many JPG files in many folders via an automated, mass, batch compression method
Create a PDF file with Contact Sheets (montage of thumbnails) for all JPG files in a folder and each of its subfolders using an automated, batch method
Create an image (BMP, GIF, JPG, PNG, TIF, etc.) from a multi-page PDF
And also published a video on GIMP:
How to divide/split a single image file into multiple image files
But keep in mind that Victor wants to use VB.Net, so I recommend using one of the imaging programs that can easily be called from the command line, such as ImageMagick and IrfanView (it is extremely easy to run the ImageMagick and IrfanView stand-alone executables with command line parameters from any language that can make command line calls). Regards, Joe
> I need to convert to PNG.
Why do you want to use VB.Net to do that? There are many excellent programs out there that will convert all files in a folder from TIFF to PNG (via a GUI or CLI), several of which have already been mentioned in this thread.
Why do you want to use VB.Net to do that? There are many excellent programs out there that will convert all files in a folder from TIFF to PNG (via a GUI or CLI), several of which have already been mentioned in this thread.
ASKER
I'm not allowed to download other programs on my work computer.
ASKER
Can code below be modified to convert all JPG in Images folder to type PNG?
Dim img As Image
Img.FromFile("some.png") 'full path here
Img.Save("a.tiff", ImageFormat.Tiff)
Dim img As Image
Img.FromFile("some.png") 'full path here
Img.Save("a.tiff", ImageFormat.Tiff)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
I removed tolowercase in code provided and copied .tif images to the tiff folder, than tried the code below, but no mages are saved in the png folder.
Dim pathSource As String = "c:\tiff\"
Dim pathTarget As String = "c:\png\"
Dim dirInfo As New DirectoryInfo(pathSource)
For Each fileInfo As FileInfo In dirInfo.GetFiles("*.tiff")
Dim newImage As Image = Image.FromFile(fileInfo.Fu llName)
Dim NewName = pathTarget & Replace(fileInfo.Name, ".tiff", ".png")
newImage.Save(NewName, System.Drawing.Imaging.Ima geFormat.P ng)
Next
Any ideas why it is not working?
Victor
I removed tolowercase in code provided and copied .tif images to the tiff folder, than tried the code below, but no mages are saved in the png folder.
Dim pathSource As String = "c:\tiff\"
Dim pathTarget As String = "c:\png\"
Dim dirInfo As New DirectoryInfo(pathSource)
For Each fileInfo As FileInfo In dirInfo.GetFiles("*.tiff")
Dim newImage As Image = Image.FromFile(fileInfo.Fu
Dim NewName = pathTarget & Replace(fileInfo.Name, ".tiff", ".png")
newImage.Save(NewName, System.Drawing.Imaging.Ima
Next
Any ideas why it is not working?
Victor
put a break point on line 8 (my code / dont remove tolowercase)
and see whats the value of
fileInfo.Name
NewName
and see whats the value of
fileInfo.Name
NewName
ASKER
It works, extension is .tif not tiff.
Thank you.
Thank you.
Open in new window