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. 3 7340
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
"ne**@OxfordEye.co.uk" 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.
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" <Ma*********@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com... 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 "ne**@OxfordEye.co.uk" 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.
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
"ne**@OxfordEye.co.uk" <ne**@oxfordeye.co.uk> wrote in message
news:dg**********@newsg4.svr.pol.co.uk... 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" <Ma*********@discussions.microsoft.com> wrote in message news:F3**********************************@microsof t.com... 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 "ne**@OxfordEye.co.uk" 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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: M. Clift |
last post by:
Hi All,
Could someone help me out with this?
items = ('a', 'b', 'c', 'd')
items + 1 = ( 'b', 'c', 'd', 'a')
items + 2 = ( 'c', 'd', 'a', 'b')
items + 3 = ( 'd', 'a', 'b', 'c')
trans = 1
|
by: active |
last post by:
I find Bitmap.Save works for WMF files but Bitmap.FromFile does not.
If I use FromFile on a WMF file that came with VS I get an exception.
If I use it on a WMF file created with Bitmap.Save I...
|
by: Russell Warren |
last post by:
Does anyone have an easier/faster/better way of popping from the middle
of a deque than this?
class mydeque(deque):
def popmiddle(self, pos):
self.rotate(-pos)
ret = self.popleft()...
|
by: Hamed |
last post by:
Have I posted the message to wrong newsgroup?
Or
Does the question is so much strage?
Would someone please kindly direct me to a true newsgroup or resource?
Best Regards
Hamed
|
by: eliss.carmine |
last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first
time using C# at all so I don't know if this is the "right" way to do
it. I've already found out several times the way I was...
|
by: Joergen Bech |
last post by:
Suppose I have
Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed)
I cannot use
Dim g As Graphics = Graphics.FromImage(bmdest)
Dim hdc As IntPtr = g.GetHdc()
as the...
|
by: \Frank\ |
last post by:
I trying to learn what a Bitmap is. Not a Managed Bitmap Object but one
that, for example, comes from the clipboard with CF_BITMAP.
I'm guessing that a CompatableBitmap is an array of indices...
|
by: Ramtin Kazemi |
last post by:
Hi
How can i perform bitwise rotation in C#?
|
by: ShadowLocke |
last post by:
Alright..the idea im trying to create is this:
The user would click to set an initial point which would start drawing an image at said point. From this point the user would drag the mouse in...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |