High quality image rotation (rotate by shear) | CodeGuru

High quality image rotation (rotate by shear)

Rotation sample: Unlike traditional rotation of images, where every n’th pixel is sampled and copied to the result image, this template provides much more accurate image rotation features (weighing the pixels). The template is instantiated with a specific pixel format and must be inherited to support pixel access functions for a specific bitmap implementation. This […]

Written By
CodeGuru Staff
CodeGuru Staff
May 1, 1999
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More


Rotation sample:

Unlike traditional rotation of images, where every n’th pixel is sampled and copied to the
result image, this template provides much more accurate image rotation features (weighing the pixels).

The template is instantiated with a specific pixel format and must be inherited to support pixel access functions
for a specific bitmap implementation. This provides abstaction of the rotation mechanism from the actual
bitmap representation.

Major features:

  • Provides professional quality image rotation.
  • Code is optimized for image quality, not speed.
  • Rotated image retains size and aspect ratio of source image (destination image size is usally bigger).
  • Supports double precision rotation angles (0..360).
  • Supports generic bitmap structures. Specific bitmap structure is defined by inheritance.
  • Template based – no need for libraries, DLLs etc. No linkage problems.

How to use the rotation template:

You must derive you own class from the rotation template.

For example:

class CRotateByShearRGB : public CRotateByShear<COLORREF>

will define a concrete class where each pixel is of COLORREF type.



Next, you must override 5 abstract functions which support creation, destruction of bitmap buffers and pixel level


access to the bitmap buffers.


Next, you instantiate your derived class and call the

AllocAndRotate(…)

function which


allocates a new destination bitmap buffer and rotates the input image into it.


That

s it.

For further instructions please view the attached sample command-line project (Rotate.cpp).
It is a simple command line utility which reads PPM (ASCII or binary) image file into a DIB structure, rotates it
and saves it to another PPM image file.

Download template – 4 KB

Download sample command line application – 21 KB

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.