Eric Bergman-Terrell's Blog

The Photo Frame Program
September 17, 2007

I just uploaded The Photo Frame Program to the website. I use this program to copy digital photographs to my digital photo frame. The Photo Frame Program automatically scales the photos for my frame's native resolution.

By default, .NET scales Bitmaps quickly and less attractively. The Photo Frame Program performs high quality image scaling. Look at the SmoothingMode, PixelOffsetMode, CompositingQuality, and InterpolatingMode properties below:

using (Graphics gr = Graphics.FromImage(scaledBitmap))
using (Brush blackBrush = new SolidBrush(Color.Black))
{
  gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
  gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

  if (addMarginsCheckBox.Checked)
  {
    // Fill entire image with black.
    gr.FillRectangle(blackBrush, new Rectangle(new Point(0, 0), new Size(maxWidth, maxHeight)));
  }

  int xPos = 0;
  int yPos = 0;

  if (addMarginsCheckBox.Checked)
  {
    xPos = (maxWidth - scaleSize.Width) / 2;
    yPos = (maxHeight - scaleSize.Height) / 2;
  }

  // Draw scaled image into bitmap
  gr.DrawImage(originalBitmap, 
               new Rectangle(xPos, yPos, scaleSize.Width, scaleSize.Height), 
               new Rectangle(0, 0, originalBitmap.Width, originalBitmap.Height), GraphicsUnit.Pixel);
}

You can also browse this program's source code on-line.

Keywords: Digital Photo Frames, digital photography, graphics, bitmap manipulation, scaling, C#, source code

Reader Comments

Comment on this Blog Post

Recent Posts

TitleDate
Node.js + Express: How to Block Requests by User-Agent HeadersJanuary 7, 2026
Vault 3 is Now Available for Windows on ARM Machines!December 13, 2025
Vault 3: How to Include Outline Text in Exported PhotosOctober 26, 2025
.NET Public-Key (Asymmetric) Cryptography DemoJuly 20, 2025
Raspberry Pi 3B+ Photo FrameJune 17, 2025
EBTCalc (Android) Version 1.53 is now availableMay 19, 2024
Vault 3 Security EnhancementsOctober 24, 2023