Hello all,
I need to prepare some figures for a publication that requires 600 dpi jpeg images. Does anyone know how I can specify a specific dpi setting when saving a jpeg file of the canvas?
Thanks,
Curtis
Hello all,
I need to prepare some figures for a publication that requires 600 dpi jpeg images. Does anyone know how I can specify a specific dpi setting when saving a jpeg file of the canvas?
Thanks,
Curtis
Hi,
it is not possible to specify dpi of saved jpeg image (I might be wrong).
The default resolution of saved jpeg image is 72 dpi.
ROOT canvas graphics is in pixel units.
To create 600 dpi jpeg (take, as an example, hsimple.C from tutorials)
with the same print size as original 72 dpi image:
// Create a new canvas.
c1 = new TCanvas("c1","Dynamic Filling Example",200,(UInt_t)700*8.33,(UInt_t)500*8.33);
root -b
root[1].x tutorials/hsimple.C
root[2]c1->Print("600dpi.jpg");
HTH. Valeriy
++
I hope we will revisit this problem on the road of the development of TImage/TASImage classes.
Hi Valeriy,
I will try the different methods you mentioned.
Thanks,
Curtis
Hi Curtis,
you can change the DPI setting of existing jpeg file (without using Gimp or PhotoShop)
with the following macro:
#include <stdio>
void chdpi(const char *name, int set = 600)
{
// set dpi resolution to jpeg image file
char buf[20];
FILE *fp = fopen(name, "rb+");
fread(buf, 1, 20, fp);
char dpi1 = (set & 0xffff) >> 8;
char dpi2 = set & 0xff;
int i = 0;
int dpi = 0; // start of dpi data
for (i = 0; i < 20; i++) {
if ((buf[i] == 0x4a) && (buf[i+1] == 0x46) && (buf[i+2] == 0x49) &&
(buf[i+3] == 0x46) && (buf[i+4] == 0x00) ) {
dpi = i + 7;
break;
}
}
if (i == 20) { // not found
fclose(fp);
printf("file %s : wrong JPEG format\n", name);
return;
}
buf[dpi] = 1; // format is dots per inch
// set x density in dpi units
buf[dpi + 1] = dpi1;
buf[dpi + 2] = dpi2;
// set y density in dpi units
buf[dpi + 3] = dpi1;
buf[dpi + 4] = dpi2;
rewind(fp);
fwrite(buf, 1, 20, fp);
fclose(fp);
}
An example of usage:
root[].L chdpi.C
root[]chdpi("myfile.jpg", 600)
I added an auxilary static method to TASImage class
Bool_t TASImage::SetJpegDpi(const char *name, UInt_t dpi = 72)
Must be in CVS asap.
Regards. Valeriy