PC Review


Reply
Thread Tools Rate Thread

bitmap rotation question.

 
 
news@OxfordEye.co.uk
Guest
Posts: n/a
 
      17th Sep 2005
Hi Guys,

Sorry if this is an obvious question but Im trying to rotate a bitmap and
then save it. So far Ive only found how to rotates a Graphic but I can't
find how to save it. I also want to crop the image and resize it, but I
assume thats straight foward and for the code below Ive set the resize to
0.5 the original size and left the crop out.

This is what Ive got so far :-

float imageRotationAngle = 30.0f;
System.Drawing.Graphics myGraphic;

myGraphic = Graphics.FromImage(bitmapOriginal);

Matrix myMatrix = new Matrix();

PointF point = new PointF(bitmapOriginal.Width * 0.5f, bitmapOriginal.Height
* 0.5f);

myMatrix.RotateAt(imageRotationAngle, point, MatrixOrder.Append);

myGraphic.Transform = myMatrix;

myGraphic.ScaleTransform(0.5f * size.Width, 0.5f * size.Height);

myGraphic.DrawImage(bitmapOriginal, destRect, cropRect, GraphicsUnit.Pixel);




So, how do I save this rotated image as a jpg or tiff ?



Thanks in advance,

Todd.


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFyayBSLiBEYXdzb24=?=
Guest
Posts: n/a
 
      18th Sep 2005
Hi,
the Bitmap class has a save method which allows you to specify various
file formats while saving.

Mark R Dawson
http://www.markdawson.org



"(E-Mail Removed)" wrote:

> Hi Guys,
>
> Sorry if this is an obvious question but Im trying to rotate a bitmap and
> then save it. So far Ive only found how to rotates a Graphic but I can't
> find how to save it. I also want to crop the image and resize it, but I
> assume thats straight foward and for the code below Ive set the resize to
> 0.5 the original size and left the crop out.
>
> This is what Ive got so far :-
>
> float imageRotationAngle = 30.0f;
> System.Drawing.Graphics myGraphic;
>
> myGraphic = Graphics.FromImage(bitmapOriginal);
>
> Matrix myMatrix = new Matrix();
>
> PointF point = new PointF(bitmapOriginal.Width * 0.5f, bitmapOriginal.Height
> * 0.5f);
>
> myMatrix.RotateAt(imageRotationAngle, point, MatrixOrder.Append);
>
> myGraphic.Transform = myMatrix;
>
> myGraphic.ScaleTransform(0.5f * size.Width, 0.5f * size.Height);
>
> myGraphic.DrawImage(bitmapOriginal, destRect, cropRect, GraphicsUnit.Pixel);
>
>
>
>
> So, how do I save this rotated image as a jpg or tiff ?
>
>
>
> Thanks in advance,
>
> Todd.
>
>
>

 
Reply With Quote
 
news@OxfordEye.co.uk
Guest
Posts: n/a
 
      18th Sep 2005
Hi Mark

Thanks for the reply. Yes, I know about the bitmap rotation save and am
using it, but the image is not saved with the transformation applied (or
does not appear to be). In the code snippet I supplied if I just put :-

bitMapOrigina.save (filename....);

the image saved will be identical to the original and not rotated by 30
degrees.

Perhaps I am approaching the problem the wrong way ? All Im trying to do is
allow the user to view an image on the screen and specify a rotation and a
crop region. Then I want to save the rotated&cropped image. So far I have
only found the Graphics.RotateAt method and am using that... but I can't
seem to save the rotated image.

Any further ideas now I've explained myself a bit more ?

Thanks,

Todd.

"Mark R. Dawson" <(E-Mail Removed)> wrote in message
news:F302680B-2AFA-421C-81C2-(E-Mail Removed)...
> Hi,
> the Bitmap class has a save method which allows you to specify various
> file formats while saving.
>
> Mark R Dawson
> http://www.markdawson.org
>
>
>
> "(E-Mail Removed)" wrote:
>
>> Hi Guys,
>>
>> Sorry if this is an obvious question but Im trying to rotate a bitmap and
>> then save it. So far Ive only found how to rotates a Graphic but I can't
>> find how to save it. I also want to crop the image and resize it, but I
>> assume thats straight foward and for the code below Ive set the resize to
>> 0.5 the original size and left the crop out.
>>
>> This is what Ive got so far :-
>>
>> float imageRotationAngle = 30.0f;
>> System.Drawing.Graphics myGraphic;
>>
>> myGraphic = Graphics.FromImage(bitmapOriginal);
>>
>> Matrix myMatrix = new Matrix();
>>
>> PointF point = new PointF(bitmapOriginal.Width * 0.5f,
>> bitmapOriginal.Height
>> * 0.5f);
>>
>> myMatrix.RotateAt(imageRotationAngle, point, MatrixOrder.Append);
>>
>> myGraphic.Transform = myMatrix;
>>
>> myGraphic.ScaleTransform(0.5f * size.Width, 0.5f * size.Height);
>>
>> myGraphic.DrawImage(bitmapOriginal, destRect, cropRect,
>> GraphicsUnit.Pixel);
>>
>>
>>
>>
>> So, how do I save this rotated image as a jpg or tiff ?
>>
>>
>>
>> Thanks in advance,
>>
>> Todd.
>>
>>
>>



 
Reply With Quote
 
news@OxfordEye.co.uk
Guest
Posts: n/a
 
      18th Sep 2005
Ive actually just sussed it out but Im not sure if its a valid way to do
it...

I doing this :-

Graphics first = Graphics.FromImage (sourceImage);
myMatrix = new Matrix ();

PointF point = new PointF(sourceImage.Width * 0.5f, sourceImage.Height *
0.5f);

myMatrix.RotateAt(myAngle, point, MatrixOrder.Append);

Bitmap target = new Bitmap (sourceImage.Width, sourceImage.Height);

Graphics second = Graphics.FromImage (target);

second.Transform = myMatrix;

second.DrawImage(sourceImage, destRect, cropRect, GraphicsUnit.Pixel);


target.Save(filename, myImageCodecInfo, myEncoderParameters);

dispose.first, ();

dispose.second ();

dispose.myMatrix ();

dispose.target ();



It this the best way ?

Thanks

Todd


"(E-Mail Removed)" <(E-Mail Removed)> wrote in message
news:dgjs9l$1d0$(E-Mail Removed)...
> Hi Mark
>
> Thanks for the reply. Yes, I know about the bitmap rotation save and am
> using it, but the image is not saved with the transformation applied (or
> does not appear to be). In the code snippet I supplied if I just put :-
>
> bitMapOrigina.save (filename....);
>
> the image saved will be identical to the original and not rotated by 30
> degrees.
>
> Perhaps I am approaching the problem the wrong way ? All Im trying to do
> is allow the user to view an image on the screen and specify a rotation
> and a crop region. Then I want to save the rotated&cropped image. So far I
> have only found the Graphics.RotateAt method and am using that... but I
> can't seem to save the rotated image.
>
> Any further ideas now I've explained myself a bit more ?
>
> Thanks,
>
> Todd.
>
> "Mark R. Dawson" <(E-Mail Removed)> wrote in message
> news:F302680B-2AFA-421C-81C2-(E-Mail Removed)...
>> Hi,
>> the Bitmap class has a save method which allows you to specify various
>> file formats while saving.
>>
>> Mark R Dawson
>> http://www.markdawson.org
>>
>>
>>
>> "(E-Mail Removed)" wrote:
>>
>>> Hi Guys,
>>>
>>> Sorry if this is an obvious question but Im trying to rotate a bitmap
>>> and
>>> then save it. So far Ive only found how to rotates a Graphic but I can't
>>> find how to save it. I also want to crop the image and resize it, but I
>>> assume thats straight foward and for the code below Ive set the resize
>>> to
>>> 0.5 the original size and left the crop out.
>>>
>>> This is what Ive got so far :-
>>>
>>> float imageRotationAngle = 30.0f;
>>> System.Drawing.Graphics myGraphic;
>>>
>>> myGraphic = Graphics.FromImage(bitmapOriginal);
>>>
>>> Matrix myMatrix = new Matrix();
>>>
>>> PointF point = new PointF(bitmapOriginal.Width * 0.5f,
>>> bitmapOriginal.Height
>>> * 0.5f);
>>>
>>> myMatrix.RotateAt(imageRotationAngle, point, MatrixOrder.Append);
>>>
>>> myGraphic.Transform = myMatrix;
>>>
>>> myGraphic.ScaleTransform(0.5f * size.Width, 0.5f * size.Height);
>>>
>>> myGraphic.DrawImage(bitmapOriginal, destRect, cropRect,
>>> GraphicsUnit.Pixel);
>>>
>>>
>>>
>>>
>>> So, how do I save this rotated image as a jpg or tiff ?
>>>
>>>
>>>
>>> Thanks in advance,
>>>
>>> Todd.
>>>
>>>
>>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bitmap rotation CF2.0 Fabien Microsoft Dot NET Compact Framework 2 19th Jul 2006 06:30 PM
Schedule Rotation Question Bob Microsoft Excel Worksheet Functions 4 24th Nov 2004 06:54 AM
Stoopid Question about rotation.... Villain ATI Video Cards 8 23rd Nov 2004 02:48 AM
Bitmap question? RawSteel Microsoft C# .NET 6 23rd Apr 2004 12:34 AM
Question on how to access bitmap: Public Function getBitmap() As Bitmap Michael Murphy Microsoft VB .NET 2 7th Oct 2003 01:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:16 AM.