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 |
|
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
|
|
|
|
|
How to set the dpi (dots per inch) of an image
By: koldo on Thu, 15 July 2010 11:07
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: mirek on Sat, 17 July 2010 09:58
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Mon, 19 July 2010 10:03
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: mirek on Fri, 23 July 2010 11:37
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Sat, 24 July 2010 11:08
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Mon, 26 July 2010 09:50
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: mirek on Fri, 13 August 2010 11:13
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Fri, 13 August 2010 13:46
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Sun, 22 August 2010 23:51
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: mirek on Wed, 08 September 2010 09:17
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Fri, 10 September 2010 11:41
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Fri, 10 September 2010 13:42
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: mirek on Mon, 13 September 2010 17:33
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Mon, 13 September 2010 21:56
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Tue, 14 September 2010 09:51
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Wed, 15 September 2010 09:17
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Wed, 15 September 2010 13:38
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Wed, 15 September 2010 15:02
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: mirek on Thu, 16 September 2010 23:49
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Fri, 17 September 2010 09:58
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Fri, 17 September 2010 10:39
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: mirek on Fri, 17 September 2010 20:17
|
|
|
Re: How to set the dpi (dots per inch) of an image
By: koldo on Fri, 17 September 2010 22:29
|
Goto Forum:
Current Time: Fri Apr 19 14:38:11 CEST 2024
Total time taken to generate the page: 0.81233 seconds
|