Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » How to set the dpi (dots per inch) of an image
Re: How to set the dpi (dots per inch) of an image [message #28754 is a reply to message #28747] Wed, 15 September 2010 13:38 Go to previous messageGo to previous message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello Mirek

Now there is dpi support for all main image formats. Here it is a demo to test file write and read.

The demo output is:

Image DPI are 0/0
New DPI values will be 1200/1200
Saved .png image DPI are 1200/1200
Saved .jpg image DPI are 1200/1200
Saved .tif image DPI are 1200/1200
Saved .bmp image DPI are 1200/1200
Saved .gif image DPI are 72/72
Done

(GIF is only 72x72)

The demo code is:

#include <Core/Core.h>
#include <plugin/png/png.h>
#include <plugin/jpg/jpg.h>
#include <plugin/tif/tif.h>
#include <plugin/bmp/bmp.h>
#include <plugin/gif/gif.h>

using namespace Upp;

void PrintDPI(String fileName, String format) {
	Image img = StreamRaster::LoadFileAny(fileName + format);
	Size dpi = img.GetDPI();
	puts(Format("Saved " + format + " image DPI are %d/%d", dpi.cx, dpi.cy));	
}

CONSOLE_APP_MAIN
{
	Image img = StreamRaster::LoadFileAny(AppendFileName(GetDesktopFolder(), "demo.png"));
	if (!img) 
		puts("No image");
	else {
		ImageBuffer image(img);
		
		Size dpi = image.GetDPI();
		puts(Format("Image DPI are %d/%d", dpi.cx, dpi.cy));
		image.SetDPI(Size(1200, 1200));
		puts("New DPI values will be 1200/1200");
		
		img = image;
		String fileName = AppendFileName(GetDesktopFolder(), "demo2");
		
		PNGEncoder png;
		png.SaveFile(fileName + ".png", img);	
		PrintDPI(fileName, ".png");
		
		JPGEncoder jpeg;
		jpeg.SaveFile(fileName + ".jpg", img);	
		PrintDPI(fileName, ".jpg");
		
		TIFEncoder tiff;
		tiff.SaveFile(fileName + ".tif", img);	
		PrintDPI(fileName, ".tif");

		BMPEncoder bmp;
		bmp.SaveFile(fileName + ".bmp", img);			
		PrintDPI(fileName, ".bmp");
				
		GIFEncoder gif;
		gif.SaveFile(fileName + ".gif", img);			
		PrintDPI(fileName, ".gif");
		
		puts("Done");
	}
	getchar();
}


In few hours I will include additional changed files.


Best regards
IƱaki
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Icon at right side of the menuBar
Next Topic: GetExifThumbnail doc
Goto Forum:
  


Current Time: Fri Apr 19 14:38:11 CEST 2024

Total time taken to generate the page: 0.81233 seconds