:: AForge.NET Framework :: Articles :: Forums ::

Rotate Image Function

The forum is to discuss topics related to different areas of image processing and computer vision.

Rotate Image Function

Postby hardywang » Wed Mar 11, 2009 12:48 am

I am trying your framework to rotate an image, my code sample is:

FilterRotate rotate = new RotateNearestNeighbor(30);
// rotate.FillColor = Color.FromArgb(0, 255, 255, 255);

//define a Brush which is semi transparent black (Alpha set to 153)
SolidBrush semiTransparentBrushBlack = new SolidBrush(Color.FromArgb(153, 0, 0, 0));

//define a Brush which is semi transparent white (Alpha set to 153)
SolidBrush semiTransparentBrushWhite = new SolidBrush(Color.FromArgb(153, 255, 255, 255));

//Define the text layout by setting the text alignment to centered
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;

int imageWidth = 1;
int imageHeight = 1;

Bitmap bmp = new Bitmap(imageWidth, imageHeight);
Graphics graphic = Graphics.FromImage(bmp);
//Set the rendering quality for this Graphics object
graphic.SmoothingMode = SmoothingMode.AntiAlias;

Font font = new Font(new FontFamily("Verdana"), 16);
SizeF fontSize = new SizeF();
fontSize = graphic.MeasureString(watermarkText, font);

Bitmap textBitmap = new Bitmap((int)fontSize.Width + 1, (int)fontSize.Height + 1);
Graphics textGraphics = Graphics.FromImage(textBitmap);
textGraphics.SmoothingMode = SmoothingMode.AntiAlias;
//Draw the copyright string
textGraphics.DrawString("Hello World", font, semiTransparentBrushBlack,
new PointF(fontSize.Width / 2 + 1, 1),

//Draw the text a second time to create a shadow effect
//Make sure to move this text 1 pixel to the right and 1 pixel down
textGraphics.DrawString("Hello World", font, semiTransparentBrushWhite, new PointF(fontSize.Width / 2, 0),
Bitmap rotatedBitmap = rotate.Apply(textBitmap);

Before and after rotation, I saved both versions of images. The original one (before rotation) I can see it has transparent background, while after rotation I see it is filled with black background. It does not care about FillColor property I set.

Any idea how can I keep the background as it after rotation?

I tried another solution from ... artID=7226 and it keeps original background.
Posts: 4
Joined: Tue Mar 10, 2009 3:21 pm

Re: Rotate Image Function

Postby andrew.kirillov » Wed Mar 11, 2009 6:43 am


If you are using 1.7.0 version (the latest available), then I need to note that it does not support 32-bit image.

The 2.0 will have support, but not for all image processing routines. If you take a look at the new on-line docs, then you fill there a note for each routine, which specifies supported formats.
With best regards,

Interested in supporting AForge.NET Framework?
User avatar
Site Admin, AForge.NET Developer
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Return to Image Processing and Computer Vision