Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Bitmap.Save, Pen.Width

  • Loading branch information...
commit e7bda0fbe6cdd9c43ed26c0eb6b72b0ebfd684b9 1 parent 90ca0cf
@migueldeicaza migueldeicaza authored
View
45 System.Drawing/Bitmap.cs
@@ -41,6 +41,7 @@
using MonoTouch.CoreGraphics;
using MonoTouch.UIKit;
+using MonoTouch.Foundation;
namespace System.Drawing {
@@ -143,9 +144,51 @@ public void SetResolution (float xDpi, float yDpi)
throw new NotImplementedException ();
}
+ public void Save (string path, ImageFormat format)
+ {
+ if (path == null)
+ throw new ArgumentNullException ("path");
+
+ if (NativeCGImage == null)
+ throw new ObjectDisposedException ("cgimage");
+
+ using (var uiimage = new UIImage (NativeCGImage)){
+ NSError error;
+
+ if (format == ImageFormat.Jpeg){
+ using (var data = uiimage.AsJPEG ()){
+ if (data.Save (path, NSDataWritingOptions.Atomic, out error))
+ return;
+
+ throw new IOException ("Saving the file " + path + " " + error);
+ }
+ } else if (format == ImageFormat.Png){
+ using (var data = uiimage.AsPNG ()){
+ if (data.Save (path, NSDataWritingOptions.Atomic, out error))
+ return;
+
+ throw new IOException ("Saving the file " + path + " " + error);
+ }
+ } else
+ throw new ArgumentException ("Unsupported format, only Jpeg and Png are supported", "format");
+ }
+
+ }
+
public void Save (string path)
{
- throw new NotImplementedException ();
+ if (path == null)
+ throw new ArgumentNullException ("path");
+ var format = ImageFormat.Png;
+
+ var p = path.LastIndexOf (".");
+ if (p != -1 && p < path.Length){
+ switch (path.Substring (p + 1)){
+ case "png": break;
+ case "jpg": format = ImageFormat.Jpeg; break;
+ }
+ }
+ Save (path, format);
}
public BitmapData LockBits (RectangleF rect, ImageLockMode flags, PixelFormat format)
View
7 System.Drawing/Graphics.cs
@@ -26,7 +26,8 @@ namespace System.Drawing {
public sealed partial class Graphics : MarshalByRefObject, IDisposable {
internal CGContext context;
-
+ internal Pen LastPen;
+
public Graphics (CGContext context)
{
if (context == null)
@@ -141,7 +142,7 @@ public void DrawLine (Pen pen, Point pt1, Point pt2)
{
if (pen == null)
throw new ArgumentNullException ("pen");
-
+
MoveTo (pt1.X, pt1.Y);
LineTo (pt2.X, pt2.Y);
StrokePen (pen);
@@ -1318,7 +1319,7 @@ public void MultiplyTransform (Matrix matrix, MatrixOrder order)
if (order == MatrixOrder.Prepend)
context.ConcatCTM (matrix.transform);
else
- throw new NotImplementedException ();
+ context.ConcatCTM (matrix.transform);
}
public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, PointF [] pts)
View
13 System.Drawing/Pen.cs
@@ -91,6 +91,19 @@ public object Clone ()
internal void Setup (Graphics graphics, bool fill)
{
brush.Setup (graphics, fill);
+ // TODO: apply matrix
+
+ if (graphics.LastPen == this && !changed)
+ return;
+
+ graphics.context.SetLineWidth (width);
+ // miter limit
+ // join
+ // cap
+ // dashes
+
+ changed = false;
+ graphics.LastPen = this;
}
}
}
View
4 System.Drawing/SolidBrush.cs
@@ -56,9 +56,9 @@ internal override void Setup (Graphics graphics, bool fill)
{
bool sourceCopy = graphics.CompositingMode == CompositingMode.SourceCopy;
if (fill){
- graphics.context.SetFillColor (color.A / 255f, color.G/255f, color.B/255f, sourceCopy ? 1f : color.A/255f);
+ graphics.context.SetFillColor (color.R / 255f, color.G/255f, color.B/255f, sourceCopy ? 1f : color.A/255f);
} else {
- graphics.context.SetStrokeColor (color.A / 255f, color.G/255f, color.B/255f, sourceCopy ? 1f : color.A/255f);
+ graphics.context.SetStrokeColor (color.R / 255f, color.G/255f, color.B/255f, sourceCopy ? 1f : color.A/255f);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.