Win32 C Function for High-Quality Bitmap Shrinking

Therefore, I wrote my own function (ShrinkBitmap) to give me the ability to shink and expand images in my own application, yet do so with the same quality I would expect from a graphics package. Take a look at the following table of images and you'll see first a large image (the original) and then a comparison of images that have been shrunk using the StretchBlt function, my ShrinkBitmap function and the an Adobe Photoshop conversion. As you can see, ShrinkBitmap gives you Adobo Photoshop bitmap shrinking capabilities from within your own application.

This is me in original size and I'm going to shrink myself

Resolution StretchBlt My function Adobe Photoshop
105 × 150
35 × 50

Source Code

Place these macros into the beginning of your program:
#define Alloc(p,t) (t *)malloc((p)*sizeof(t))
#define For(i,n) for ((i)=0;(i)<(n);(i)++)
#define iFor(n) For (i,n)
#define jFor(n) For (j,n)
And also this type-definition:
typedef struct {
 WORD x,y;  // dimensions
 WORD l;    // bytes per scan-line (32-bit allignment)
 BYTE *b;   // bits of bitmap,3 bytes/pixel, BGR
} tWorkBMP;  // 24-bit working bitmap
The functions also require the header file for memory allocation, or you can rewrite them to use keywords new and delete.
#include <malloc.h>
Here's the actual ShrinkBitmap function
HBITMAP ShrinkBitmap (HBITMAP a,WORD bx,WORD by)
// creates and returns new bitmap with dimensions of 
// [bx,by] by shrinking bitmap a both [bx,by] must be less or equal 
// than the dims of a, unless the result is nonsense
 tWorkBMP in,out;
 HBITMAP b=CreateEmptyBitmap(bx,by);
 OpenBitmapForWork (a,&in);
 ShrinkWorkingBitmap (&in,&out,bx,by);
 free (in.b);
 SaveWorkingBitmap (&out,b);
 free (out.b);
 return (b);
The following functions are just supporting and I recommend treating them in "black box" fashion. But you have to place them in front of the ShrinkBitmap function or forward declare them.
void CreateWorkingBitmap (WORD dx,WORD dy,tWorkBMP *w)

HBITMAP CreateEmptyBitmap (WORD dx,WORD dy)
 HBITMAP b=CreateCompatibleBitmap(h,dx,dy);
 ReleaseDC (NULL,h);
 return (b);

void SetBMIHeader (BITMAPINFO *b,short dx,short dy)

void SaveWorkingBitmap (tWorkBMP *w,HBITMAP b)
 SetBMIHeader (&s,w->x,w->y);
 SetDIBits (h,b,0,w->y,w->b,&s,DIB_RGB_COLORS);
 ReleaseDC (NULL,h);

void ShrinkWorkingBitmap (tWorkBMP *a,tWorkBMP *b,WORD bx,WORD by)
 BYTE *uy=a->b,*ux,i;
 WORD x,y,nx,ny=0;
 DWORD df=3*bx,nf=df*by,j;
 float k,qx[2],qy[2],q[4],*f=Alloc(nf,float);

 CreateWorkingBitmap (bx,by,b);

 jFor (nf) f[j]=0;

 For (y,a->y) {

  if (ny>a->y) {


   For (x,a->x) {


    if (nx>a->x) {

     iFor (4) q[i]=qx[i&1]*qy[i>>1];

     iFor (3) {
    else iFor (3) {
    if (nx>=a->x) nx-=a->x;
     if (!nx) j+=3;
  else {
   For (x,a->x) {
    if (nx>a->x) {
     iFor (3) {
    else iFor (3) f[j+i]+=*(ux++);
    if (nx>=a->x) nx-=a->x;
     if (!nx) j+=3;
   if (ny<a->y) j-=df;
  if (ny>=a->y) ny-=a->y;
 For (y,by) {
  jFor (df) uy[j]=f[nf++]*k+.5;

 free (f);


  • hvorfor vi skal vælge kvaliteten af Dr. Dre

    Posted by wanzixiao on 06/04/2013 03:00am

    [url=]monster beats danmark[/url] On classical tracks, like John Adams’ “The Chairman Dances,” high-register strings, brass, and percussion take center stage. At times, the Zoro can sound perhaps too bright, but it’s never overly harsh or unpleasant. The lower-register strings and percussion receive less embellishment than they do with many modern pairs (like the Beats) that tend to overemphasize the bass. Here, there is more overall balance, a bass presence that sits nicely in the mix, and a focus on the mids and highs. [url=]beats by dre danmark[/url] at undlade lyd i høretelefonerne for en stund, hvis der skulle dukke noget uventet op i din tilværelse.Kassen indeholder naturligvis Beats by Dr. Dre Studiosamt et etui, hvor disse Beats kan ligge i (sammenfoldet, som på den baggrund også er en vældig smart og utrolig nyttig funktion ved høretelefonerne) og sidst men ikke mindst indeholder det også den traditionelle ledning som kan tilsluttes høretelefonerne i den ene ende og en computer eller lignende i den anden ende. Ligeledes medfølger også en ledning med mikrofon, som gør det muligt at tilslutte høretelefonerne til sin iPhone og skulle man have brug for det medfølger der også HiEnd Jackstik, men det er blot en ekstra feature. [url=]Beats by dre billig pris[/url] Butland afsløret i en besked til en anden GB fodboldspiller, Karen Carney, at en Beats repræsentant besøgte holdet hotel på mandag, twitte: “. De er omkring, er jeg sikker på de vil støde ind i jer snart”Beats hovedtelefoner har været new æsten allestedsnærværende i Aquatics Centre med svømmere, herunder Michael Phelps bruger dem til at blokere baggrundsstøj før løbene.Det stunt er usandsynligt, at gå godt med advokater på LOCOG eller IOC, som har strenge regler for at beskytte officielle sponsorer, som har betalt millioner af pounds for eneretten til at udnytte deres tilknytning til begivenheden.Endvidere oplyste vejledning udstedt før De Olympiske Lege af IOC, at atleter ikke var tilladt at fremme enhver brand, produkt eller service inden for en blog eller tweet eller på anden måde på eventuelle sociale medieplatforme eller på nogen hjemmesider.

  • Ningún pecado del mal ghd plancha de pelo, Progreso primavera-verano no se puede perder el peinado

    Posted by hanmeihm on 05/30/2013 12:57pm

    [url=]plancha pelo ghd[/url] Lo que significa que, qu¦ es exactamente segundo para conseguir un buen da del pelo Bien es publicitado que buenos das del pelo son en realidad llevar a cabo otra de pelo styler nica forma en que probablemente ser¢n un hervidero este buen da del pelo no es comn. Los buenos das del pelo no planos de hierro comn se vienen en una parada de color marrn brillante va a metal precioso no recibir sol cer¢mica placas de matrcula. Esto ayudar¢ a que este enfoque plancha nica destacan dentro del lugar para llevar. [url=]ghd Styler[/url] Estas planchas rojas tienen un significado doble voltaje se puede obtener un rendimiento uniforme en todo el mundo ideal para cuando vas en sus viajes. Tambin con un sistema incorporado en el modo de suspensin tus alisadores poco a poco se empiezan a cerrar despus de 30 minutos de haber sido utilizado C que le ahorra la preocupacin de si est¢ o no les apag! [url=]Comprar por Ghd[/url] Es evidente que la ma es rizado, muy rizado clasificacin. Detiene a 4 o C, pero creo que la mina debe ser un 4Z o quiz¢s un cinco.

  • The largest picking of Distinct With Jordans, including the latest Retros and Trafficking Jordan Shoes.

    Posted by carpitiqs on 04/16/2013 08:06am

    Conclusively, no overview of clothing hazards would be finished without [url=]hollister[/url] acknowledging the corset. Recompense hundreds of years, the corset has been worn to bearing or accentuate the noticeable curves of a woman's [url=]abercrombie paris[/url], or lock up's, body. With whalebone or metal boning and tight-lacing, the body-binders prompted medical professionals, principally in the 1800s, to sample to make noticeable an end to their ingest, explaining that they [url=]air jordan[/url] hindered muscle advance, mobility and, incredibly, the skill to breathe. The doctors were on to something, but, as was the report with compelled feet, innumerable women weren't on the lip of to yield up the body-shaper because, they, or beau monde, preferred the [url=]abercrombie france[/url] corseted perimeter greater than their logical one. The accoutrements in today’s collection was one that I wore on Saturday [url=]jordan[/url] night benefit of a victuals not at conversant with in town. The coloured clothing is a tangible leading that I include had in my attire for the sake of years. These days I sense much happier wearing [url=]hollister[/url] it with leggings as it is so hollow but I identify it works equally bracing pilgrimage of daytime and continually time. As much as I current prints and effulgent colours, I will comprise to brook [url=]abercrombie uk[/url] that you virtuous can’t earth a black decorate profit of versatility and it is oner principles seeking those days when I don’t have ages to farrago 'orb-shaped deciding what to wear [url=]moncler[/url]. But in November, we each had a worth to domination a bustle rebound from and look [url=]air jordan pas cher[/url] at things from a unlike perspective. We had been in so occult, plugging away, racing on to the next gismo that we hadn’t charmed the measure to look up [url=]michael kors[/url] and ask ourselves what we surely wanted.We’ve dedicated two and a half years to creating a marque and a hand in that exceeded our (wildest) expectations. We’ve skilled more than we continually soup噊n [url=]hollister france[/url] possible. We’ve met ridiculous people and made irredeemable connections. We’ve discovered a passion looking object of something we didn’t reward we had.But with all of this advancement, we’ve recently realized that revolvement attire [url=]louboutin pas cher[/url] is no longer something we want, or sensation we stress, to assignment for what we were meant to do.

  • wholesale hats

    Posted by xxds6wb on 04/01/2013 05:58am

    [url=]fitted hats wholesale[/url] fitted hats wholesale x wpgw [url=]snapback wholesale[/url] snapback wholesale y mpyh[url=]cheap snapbacks free shipping[/url] cheap snapbacks free shipping p vfoz[url=]snapbacks wholesale[/url] snapbacks wholesale y ftoc[url=]cheap snapbacks[/url] cheap snapbacks k fzoe[url=]cheap snapbacks[/url] cheap snapbacks j prhk [url=]fitted hats wholesale[/url] fitted hats wholesale n qxdm [url=]snapback hats wholesale[/url] snapback hats wholesale d sndx[url=]wholesale snapbacks[/url] wholesale snapbacks m yftw[url=]fitted hats wholesale[/url] fitted hats wholesale m cyvq[url=]cheap snapback hats[/url] cheap snapback hats e zvgq[url=]snapbacks for cheap[/url] snapbacks for cheap f jmkt [url=]snapback hats wholesale[/url] snapback hats wholesale x lfjp [url=]cheap hats[/url] cheap hats o uhki[url=]fitted hats wholesale[/url] fitted hats wholesale m lnuk[url=]cheap hats[/url] cheap hats j ahos[url=]hats wholesale[/url] hats wholesale e esat[url=]wholesale beanies[/url] wholesale beanies z xndg

  • sexy stockings

    Posted by Fishnetkf1019 on 03/29/2013 09:59am - Sexy Lingerie Shoplingerie?has been derived from the French word We know these are universal feelings - cop costumeInvite your co-workers, family and friends to join you It may be a bit disappointing but never mind, as what’s matter in the end, is the sincerity to give a gift - womens sexy clothesDreamgirl lingerie retailers are ably available in the net, each of them offering wide variety of products from the dreamgirl line What color does he likes? It’s good if you know that but what if you don’t? Imagine a great gift with a wrong color - Sexy Lingerie storeThis company grew for 35 years and had continuously offered a wide array of products such as sexy costumes, fetish wear, plus size costumes, sexy lingerie and even men Hence, a brief understanding on color will help you in your decision making - pink lace lingeries most popular costume storeBabydoll chemises come in a wide variety of steamy materials, such as silk and nylon

  • snapback hats wholesale

    Posted by xxds7tx on 03/29/2013 02:11am

    [url=]wholesale fitted hats[/url] wholesale fitted hats a wkog [url=]wholesale fitted hats[/url] wholesale fitted hats x bsdu[url=]hats wholesale[/url] hats wholesale q vvdp[url=]fitted hats wholesale[/url] fitted hats wholesale e tcem[url=]snapbacks for cheap[/url] snapbacks for cheap k vovo[url=]snapback wholesale[/url] snapback wholesale s bdnp [url=]cheap snapback hats[/url] cheap snapback hats v phwm [url=]snapback hats cheap[/url] snapback hats cheap y tcom[url=]snapbacks wholesale[/url] snapbacks wholesale t prwg[url=]cheap hats[/url] cheap hats o ygsr[url=]cheap hats[/url] cheap hats p qqin[url=]snapbacks for cheap[/url] snapbacks for cheap y frjp [url=]cheap snapbacks free shipping[/url] cheap snapbacks free shipping v yatb [url=]cheap snapback hats[/url] cheap snapback hats n bznw[url=]wholesale fitted hats[/url] wholesale fitted hats n bjwh[url=]cheap hats[/url] cheap hats d brhh[url=]cheap snapbacks free shipping[/url] cheap snapbacks free shipping c pnbx[url=]snapbacks wholesale[/url] snapbacks wholesale z qqco

  • wholesale fitted hats

    Posted by xxds5wn on 03/29/2013 01:07am

    [url=]snapback wholesale[/url] snapback wholesale h nagl [url=]wholesale baseball caps[/url] wholesale baseball caps l plvx[url=]snapback wholesale[/url] snapback wholesale w ytme[url=]cheap snapbacks online[/url] cheap snapbacks online m bjij[url=]snapback wholesale[/url] snapback wholesale q xtbj[url=]snapback wholesale[/url] snapback wholesale n ltvw [url=]snapback hats wholesale[/url] snapback hats wholesale j zora [url=]cheap snapbacks online[/url] cheap snapbacks online v inud[url=]snapback wholesale[/url] snapback wholesale r vegf[url=]cheap hats[/url] cheap hats o qclp[url=]snapback hats cheap[/url] snapback hats cheap f qnrt[url=]wholesale beanies[/url] wholesale beanies n zjzx [url=]cheap snapbacks free shipping[/url] cheap snapbacks free shipping p fyjv [url=]cheap snapbacks online[/url] cheap snapbacks online f tkoj[url=]snapbacks for cheap[/url] snapbacks for cheap h miwa[url=]cheap snapbacks free shipping[/url] cheap snapbacks free shipping p cycf[url=]cheap snapback hats[/url] cheap snapback hats t urjv[url=]snapbacks wholesale[/url] snapbacks wholesale l xqrf

  • oakley sunglasses cheap

    Posted by tgliliImpumpnab on 03/28/2013 09:09pm - cheap ray ban wayfarer cheap oakleys for sale - fake ray ban sunglasses wholesale oakley sunglasses - fake ray ban sunglasses discount oakley sunglasses,,,,,o - discount sunglasses cheap ray ban sunglasses - discount sunglasses cheap sunglasses

  • sadrqh

    Posted by Suttonbnd on 03/28/2013 02:17pm

    ghd hair straightener,Because the price tag is too high the Tan Yankai out of the cruiser to the design requirements.ghd hair straightener, And taking into account the self-made cruiser is against Japan, has not arrogant to the point of a direct blow to Southeast Asia set sail from Tianjin.ghd, Relying on the Chinese coastal ports, six hundred tons of coal reserves which seemed warships endurance is very weak, but to meet the needs of the Chinese coastal defense, but saved tonnage can be added more armor to improve the defense capabilities and speed.ghd straightener, Japan since the Sino-Japanese War after not idle to sleep, but the Sino-Japanese war to bring too many changes in Japan, together with the strategic decision-making, but also gave birth to the great changes - northern Korea almost countries powers carved up while in the southern region also requires the Army sits.ghd sale, Unfortunately, in the Sino-Japanese war in the Japanese Army out of color, but still is played with * remnant of a division.

  • DBFlEb Xt uQ KUG PhIs UZ

    Posted by eYxBNMsdGx on 03/19/2013 07:27am

    order tramadol tramadol seizures - buy tramadol online legal

  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date