The difference in image resolution (ppi) between C# and Photoshop - c#

For example, C # says that the selected image contains 96 ppi, while that same image in Photoshop contains 72 ppi.
Why is there a difference?
I’m inclined to trust Photoshop in this case, and how to test image resolution if C# returns false results?
We need to build some sort of validator control that rejects all images with ppi != 300.
Control should support the following formats: jpg, jpeg, gif, png, bmp.
Code is listed below:
Image i = Image.FromFile(FileName);
Console.Write(i.VerticalResolution);
Console.Write(i.HorizontalResolution);

DPI means dots (pixels) per inch. The physical size in inches is subjective, based on the current monitor's size and resolution. Unless you're relying on metadata (which gif and bmp don't contain) you cannot reliably calculate this.
Photoshop simply has a prescribed value for DPI, which it uses when translating images for print. This value is stored in the PSD file and may be copied to JPEG metadata, but if you save the image in a format without DPI metadata, the information is not stored.
Update:
The reason your code gets a different value is that C# fetches its VerticalResolution and HorizontalResolution values from the current DPI setting on the computer. Photoshop's DPI is for use with print, so it knows the physical dimensions if you want to send your image to a printer. It has a default value of 72dpi, but you can change this. The value has no meaning on a screen, though, since screens deal in pixels only.

DPI means dots per inch. A bitmap image does not have an inherent DPI, it merely has a size which is the number of pixels in the horizontal and the number of pixels in the vertical (width and height). An image only gains a resolution (in DPI) when you say how many pixels you want to squeeze into each inch.
So if I have an image that is 100 pixels wide and 100 pixels high (100px × 100px), it will be 100 DPI if I print it (or convert it into a format that dictates the print size) such that it fits exactly in a one square inch (1" × 1"). It will be 50 DPI if I print it to fit in a square that is two inches by two inches, &c.

Related

DPI of an image

I have a requirement where I have to check the DPI of a bunch of images stored in an oracle database as a blob and make sure they are above 300 dpi. I was planning on reading the field via a c# program and trying to determine their dpi, but i was unsure how to calculate this. Can anyone give me some guidance on how I can determine their DPI.
As the name says, DPI represents the number of pixels per inch. To calculate it you need the size of image in inchs and in pixels. The size in inchs is relative to the monitor screen dpi, best resolutions like printers use more points for inch.
So, if your image has 100px and 2in, your dpi is 100/2 = 50 dpi. Realize that the problem is how to determine the size in inchs of your image if basically you need to get an reference of inchs.
Then, would be easier to verify the dpi of image on upload and guarantee the required before the insertion.

Change resolution with Bit Miracle's LibTiff.Net

I use Bit Miracle's LibTiff.Net to convert scanned image to tiff file, but I want to save images with 200dpi even that scanned with 300 dpi I found this in the Bit Miracle site sample
tif.SetField(TiffTag.XRESOLUTION, img.HorizontalResolution);
tif.SetField(TiffTag.YRESOLUTION, img.VerticalResolution);
but I make this change to set resolution always 200dpi :
tif.SetField(TiffTag.XRESOLUTION, 200);
tif.SetField(TiffTag.YRESOLUTION, 200);
in the tif file property it say 200 dpi but the file size don't change 163 Ko before and after the change,
I make a search for all resolution used in the code, and I make it 200 but always the same file size.
if I change the value in the SetField I got it in the file property but not in the rezolution of the image (same size always for all resolution test)
How I can change the resolution of the destination tif ?
LibTiff.Net is a codec library. It's not designed to resample images.
Changing dpi value will only affect print size of the image, not the image data. You should resample data yourselves.

Windows DPI setting affects Graphics.DrawString

I have created a new Bitmap object and now want do draw some text to it using GDI+.
So I call Graphics.DrawString(...).
The problem is that the size of the string depends on Windows 7's DPI settings.
Is there any way to make my text drawing independent of the windows settings?
PS: The DPI settings seem to affect text only. A rect for example stys the same size when changing the DPI...
Just found the solution myself:
The key is to create the font with the parameter GraphicsUnit.Pixel. That way drawing strings gets independent from the system's DPI settings.
You are correct in that the DPI affects only drawable items that are measured in device-independent units. Fonts are typically measured in Points, where 1 point = 1/72 of an inch. Therefore a 10pt font will be the same size in INCHES on each and every screen resolution and will take up more or less pixels depending on the screen resolution and pixel density.
Everything measured in pixels (such as lines, shapes etc) will not be affected by DPI, but the actual physical size will vary depending on screen resolution and pixel density. Changing your code to measure fonts in pixels will indeed ensure that the text is the same pixel size on all screen DPI settings, but if you were to print to a printer you'll find that the text size will vary depending on printer resolution.

Image size considering (or not) h/v resolution

I have two images:
Name Type Width Height HRes VRes
img01 GIF 256 256 384 96
img02 TIFF 1728 1147 200 100
Windows internal viewer shows them using different patterns:
img01 is displayed as 256x256 image (square)
img02 is displayed as a vertical image (despite of width>height) and image format is correct
After seen img02 behaviour I thought that displayed size is given by:
Display_Width = max(HRes,VRes) * Width / HRes
Display_Height = max(HRes,VRes) * Height / VRes
But that's not good for img01, which is displayed as 256x256!!
If I use Image class to load those images, resolution is not taken in account, so img02 is shown horizontally and distorced respect correct format.
If Windows internal viewer shows them correctly, I think there should be some property to understand if resolution should be considered or not.
With Image class I have Flags and PropertyItems properties, but I really don't understand if they are the ones I have to look at.
Can you teach me the right method to display images (using Image class) without distortion?
Thanks
Aspect ratio in GIF files is very uncommon, since GIF is a format used to store graphics intended to be displayed on computer screens. In fact, GIF87a files do not have an aspect ratio at all, and GIF89a do not store the actual aspect ratio but an approximation.
On the other side, TIFF files for the most part are used by graphic designers, photographers and publishers, so the concept of pixel aspect ratio is core to the format as it allows these files to move between different display mediums.
My guess is that most GIF decoders ignore the aspect ratio from the GIF89a format. I think you should do the same.

DPI and PPI | DPI OR PPI

Is there any differ between DPI and PPI ? Is it true : Dot = Pixel ? And at Last what is DpiX and DpiY in C#.net ? How can we change them ?
DPI
Stands for Dot Per Inch and is used when pritning. It is also heavily misused with screen resolution. A colour ink printer don't mix the colors, instead each color has its own "slot". When a printer says 12000 dpi it is actually 12000 / 5 "pixels" for a 5 color based printer. Never the less, DPI only becomes interesting in the context of a printed result. Photoshop use the image's DPI information to be able to tell you the printed size of the image. Many people missinterpret DPI as a measurement of the pictures image quality or pixel density. For example, if you change the DPI for an image in Photoshop without resampling the image, you still have the exact same amount of pixels but now photoshop shows another "physical" dimension (inch or whatever you use).
Look at this Wiki article.
PPI
Stands for Pixels Per Inch (or pixel density) and should be used with screens and defined as one pixel equals the area of all the three base colors (Red, Green and Bue). Look at this Wiki article.

Categories

Resources