PPI calculation

Have the screen resolution (width and height) in pixels and the diagonal length in inches, and want to calculate the PPI? Pretty simple really. Let’s use a concrete example. The iPad 4 has a screen resolution of 2048 by 1536 pixels, and a diagonal length of 9.7 inches. Thus we calculate its PPI as


The calculation above was performed using the wonderful MyScript Calculator, and the result captured by taking a screenshot.

Here’s the same formula using WordPress’ \LaTeX renderer, in a more generalized form: \sqrt{w^2 + h^2} \over L, where w is the screen width in pixels, h is the screen height in pixels, and L is the diagonal length of the screen in inches.


Survey of book reading apps for the iPad

Check the table below for a comparison of reading apps based on features they support.

Reading apps on iOS

Last updated on July 21, 2013

Some observations

Adobe Reader supports the most features. If it had EPUB format support it would be unbeatable.

Documents by Readdle has the best cloud integration. It is an indispensable app to have if you store your books in the cloud. Its reading features lack polish. Night view is low contrast, making reading very difficult. EPUB support is buggy. It does support other media formats besides books.

Readdle is another competent reading app. It is very polished and has one feature that no other app has so far. It tracks your reading time, and tells you how much time you have left to finish the book. The only significant feature missing is search.


If you have an Android device and want cross-platform support, Adobe Reader seems to be the best option, but PDF books are unwieldy on small screens.

Kindle is my favorite for reading on small screens. I read most novels on a smartphone. I wish the app had better PDF support – search, copy text to clipboard, highlights and notes, and night view.

At the end of the day, I wish all books were DRM-free and I could read them in the best app du jour.

Implement a color picker using ComboBox

This post shows how you can custom draw items of a ComboBox to implement a color picker. The implementation is mostly inspired by a CodeProject article, but I had to adapt the code for the color bands to show adequately.

Register for DrawItem event

Here’s how you can register for DrawItem. The event handler is called for each item that the ComboBox requires painting. The first line enables custom drawing.

combobox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
combobox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.eventhandler);

Event handler implementation

Here’s one simple implementation for the event handler:

private void eventhandler(object sender, DrawItemEventArgs e)
    if (e.Index < 0) return;

    Graphics g = e.Graphics;
    Rectangle rect = e.Bounds;
    string n = ((ComboBox)sender).Items[e.Index].ToString();
    Font f = new Font("Arial", 9, FontStyle.Regular);
    Color c = Color.FromArgb((int)colors[e.Index]);
    Brush b = new SolidBrush(c);
    g.FillRectangle(Brushes.White, rect);
    g.DrawString(n, f, Brushes.Black, rect.X, rect.Top);
    g.FillRectangle(b, rect.X + 110, rect.Y + 3,
                    rect.Width - 113, rect.Height - 6);

Here's one example of the colors and colorNames arrays used above:

uint[] colors =
0xFFCD853F, 0xFFDEB887, 0xFFF08080, 0xFFFF0000,
0xFF969696, 0xFF00FF7F, 0xFF90EE90, 0xFF00FFFF,
0xFF48D1CC, 0xFFBA55D3, 0xFFF0E68C, 0xFFFFD700
string[] colorNames =
"Peru", "Burlywood", "Light coral", "Red",
"Lime", "Spring green", "Light green", "Cyan",
"Medium turquoise", "Medium orchid", "Khaki", "Gold"

You can pick colors of your own choice.

Locating a color and setting its index

Here’s one way to locate the index of a color by its ARGB value, and set the SelectedIndex property of the ComboBox:

    for (int i = 0; i < colors.Length; i++)
        if (colors[i] == (uint)color.ToArgb())
            combobox.SelectedIndex = i;

Here, color is an instance of the Color structure.