Skip to content
Browse files

Implement DrawImage methods part 1.

  • Loading branch information...
1 parent e573e31 commit 22fbaf05eaa8773734d3724cdbff09c6305aaee5 @kjpou1 kjpou1 committed Aug 29, 2013
View
30 Samples/MonoMac/DrawImageTests/AppDelegate.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Drawing;
+using MonoMac.Foundation;
+using MonoMac.AppKit;
+using MonoMac.ObjCRuntime;
+
+namespace DrawImageTests
+{
+ public partial class AppDelegate : NSApplicationDelegate
+ {
+ MainWindowController mainWindowController;
+
+ public AppDelegate ()
+ {
+ }
+
+ public override void FinishedLaunching (NSObject notification)
+ {
+ mainWindowController = new MainWindowController ();
+ mainWindowController.Window.MakeKeyAndOrderFront (this);
+ mainWindowController.Window.ContentView.AddSubview(new DrawingView(mainWindowController.Window.ContentView.Bounds));
+ }
+
+ public override bool ApplicationShouldTerminateAfterLastWindowClosed (NSApplication sender)
+ {
+ return true;
+ }
+ }
+}
+
View
10 Samples/MonoMac/DrawImageTests/AppDelegate.designer.cs
@@ -0,0 +1,10 @@
+
+namespace DrawImageTests
+{
+ // Should subclass MonoMac.AppKit.NSResponder
+ [MonoMac.Foundation.Register("AppDelegate")]
+ public partial class AppDelegate
+ {
+ }
+}
+
View
105 Samples/MonoMac/DrawImageTests/DrawImageTests.csproj
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
+ <ProductVersion>10.0.0</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{1C81B532-1642-45E6-860A-A8F3817734E7}</ProjectGuid>
+ <ProjectTypeGuids>{948B3504-5B70-4649-8FE4-BDE1FB46EC69};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>DrawImageTests</RootNamespace>
+ <MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
+ <AssemblyName>DrawImageTests</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <UseSGen>false</UseSGen>
+ <IncludeMonoRuntime>false</IncludeMonoRuntime>
+ <EnablePackageSigning>false</EnablePackageSigning>
+ <CodeSigningKey>Mac Developer</CodeSigningKey>
+ <EnableCodeSigning>false</EnableCodeSigning>
+ <CreatePackage>false</CreatePackage>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
+ <DebugType>full</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <LinkMode>Full</LinkMode>
+ <UseSGen>false</UseSGen>
+ <IncludeMonoRuntime>true</IncludeMonoRuntime>
+ <EnablePackageSigning>false</EnablePackageSigning>
+ <CodeSigningKey>Developer ID Application</CodeSigningKey>
+ <EnableCodeSigning>true</EnableCodeSigning>
+ <CreatePackage>true</CreatePackage>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|iPhoneSimulator' ">
+ <DebugType>full</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\iPhoneSimulator\AppStore</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <LinkMode>Full</LinkMode>
+ <UseSGen>false</UseSGen>
+ <IncludeMonoRuntime>true</IncludeMonoRuntime>
+ <PackageSigningKey>3rd Party Mac Developer Installer</PackageSigningKey>
+ <CreatePackage>true</CreatePackage>
+ <CodeSigningKey>3rd Party Mac Developer Application</CodeSigningKey>
+ <EnableCodeSigning>true</EnableCodeSigning>
+ <EnablePackageSigning>true</EnablePackageSigning>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="MonoMac">
+ <HintPath>..\..\..\..\monomac\src\MonoMac.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="Resources\" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="MainWindow.cs" />
+ <Compile Include="MainWindowController.cs" />
+ <Compile Include="MainWindow.designer.cs">
+ <DependentUpon>MainWindow.cs</DependentUpon>
+ </Compile>
+ <Compile Include="Main.cs" />
+ <Compile Include="AppDelegate.cs" />
+ <Compile Include="AppDelegate.designer.cs">
+ <DependentUpon>AppDelegate.cs</DependentUpon>
+ </Compile>
+ <Compile Include="DrawingView.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <InterfaceDefinition Include="MainWindow.xib" />
+ <InterfaceDefinition Include="MainMenu.xib" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Info.plist" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\sysdrawing-coregraphics-Mac\sysdrawing-coregraphics-Mac.csproj">
+ <Project>{C675FE3F-497D-4CE7-B441-3C0299B30C10}</Project>
+ <Name>sysdrawing-coregraphics-Mac</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="bitmap25.png" />
+ <Content Include="bitmap50.png" />
+ </ItemGroup>
+</Project>
View
90 Samples/MonoMac/DrawImageTests/DrawingView.cs
@@ -0,0 +1,90 @@
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Drawing.Imaging;
+
+using MonoMac.Foundation;
+using MonoMac.AppKit;
+
+namespace DrawImageTests
+{
+ public partial class DrawingView : MonoMac.AppKit.NSView
+ {
+
+ #region Constructors
+
+ // Called when created from unmanaged code
+ public DrawingView (IntPtr handle) : base (handle)
+ {
+ Initialize ();
+ }
+
+ // Called when created directly from a XIB file
+ [Export ("initWithCoder:")]
+ public DrawingView (NSCoder coder) : base (coder)
+ {
+ Initialize ();
+ }
+
+ // Shared initialization code
+ void Initialize ()
+ {
+ this.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
+ }
+
+ public DrawingView (RectangleF rect) : base (rect)
+ {
+ Initialize();
+ }
+
+#endregion
+
+ Font Font = new System.Drawing.Font("Helvetica",12);
+
+ Image bmp;
+ Image bmp2;
+
+ Rectangle src = new Rectangle(0, 0, 50, 50);
+ RectangleF srcF = new Rectangle(0, 0, 50, 50);
+ Rectangle dst = new Rectangle(170, 170, 100, 100);
+ RectangleF dstF = new Rectangle(270, 270, 100, 100);
+
+ public override void DrawRect (System.Drawing.RectangleF dirtyRect)
+ {
+ Graphics g = new Graphics();
+ g.InterpolationMode = InterpolationMode.NearestNeighbor;
+
+ g.Clear(Color.Wheat);
+
+ var mainBundle = NSBundle.MainBundle;
+ var filePath = mainBundle.PathForResource("bitmap25","png");
+
+ var bmp = Image.FromFile(filePath);
+
+ filePath = mainBundle.PathForResource("bitmap50","png");
+
+ var bmp2 = Image.FromFile(filePath);
+
+
+ //g.DrawImage(bmp, new Point[]{new Point(170,10), new Point(250,0), new Point(100,100)}, src, GraphicsUnit.Pixel );
+ //g.DrawImage(bmp, new PointF[]{new PointF(70,10), new PointF(150,0), new PointF(10,100)}, srcF, GraphicsUnit.Pixel );
+ // Create parallelogram for drawing image.
+ Point ulCorner = new Point(110, 100);
+ Point urCorner = new Point(350, 100);
+ Point llCorner = new Point(100, 200);
+ Point[] destPara = {ulCorner, urCorner, llCorner};
+
+ g.DrawImage(bmp2, destPara);
+
+ //g.DrawImage (bmp, dst);
+
+
+ g.Dispose();
+
+ }
+ }
+}
+
View
16 Samples/MonoMac/DrawImageTests/Info.plist
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleName</key>
+ <string>DrawImageTests</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>10.6</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
View
18 Samples/MonoMac/DrawImageTests/Main.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Drawing;
+using MonoMac.Foundation;
+using MonoMac.AppKit;
+using MonoMac.ObjCRuntime;
+
+namespace DrawImageTests
+{
+ class MainClass
+ {
+ static void Main (string[] args)
+ {
+ NSApplication.Init ();
+ NSApplication.Main (args);
+ }
+ }
+}
+
View
4,074 Samples/MonoMac/DrawImageTests/MainMenu.xib
4,074 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
30 Samples/MonoMac/DrawImageTests/MainWindow.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using MonoMac.Foundation;
+using MonoMac.AppKit;
+
+namespace DrawImageTests
+{
+ public partial class MainWindow : MonoMac.AppKit.NSWindow
+ {
+ #region Constructors
+ // Called when created from unmanaged code
+ public MainWindow (IntPtr handle) : base (handle)
+ {
+ Initialize ();
+ }
+ // Called when created directly from a XIB file
+ [Export ("initWithCoder:")]
+ public MainWindow (NSCoder coder) : base (coder)
+ {
+ Initialize ();
+ }
+ // Shared initialization code
+ void Initialize ()
+ {
+ }
+ #endregion
+ }
+}
+
View
15 Samples/MonoMac/DrawImageTests/MainWindow.designer.cs
@@ -0,0 +1,15 @@
+
+namespace DrawImageTests
+{
+ // Should subclass MonoMac.AppKit.NSWindow
+ [MonoMac.Foundation.Register("MainWindow")]
+ public partial class MainWindow
+ {
+ }
+ // Should subclass MonoMac.AppKit.NSWindowController
+ [MonoMac.Foundation.Register("MainWindowController")]
+ public partial class MainWindowController
+ {
+ }
+}
+
View
189 Samples/MonoMac/DrawImageTests/MainWindow.xib
@@ -0,0 +1,189 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
+ <data>
+ <int key="IBDocument.SystemTarget">1060</int>
+ <string key="IBDocument.SystemVersion">10D573</string>
+ <string key="IBDocument.InterfaceBuilderVersion">762</string>
+ <string key="IBDocument.AppKitVersion">1038.29</string>
+ <string key="IBDocument.HIToolboxVersion">460.00</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="NS.object.0">762</string>
+ </object>
+ <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="2" />
+ </object>
+ <object class="NSArray" key="IBDocument.PluginDependencies">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ </object>
+ <object class="NSMutableDictionary" key="IBDocument.Metadata">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys" id="0">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSCustomObject" id="1001">
+ <string key="NSClassName">MainWindowController</string>
+ </object>
+ <object class="NSCustomObject" id="1003">
+ <string key="NSClassName">FirstResponder</string>
+ </object>
+ <object class="NSCustomObject" id="1004">
+ <string key="NSClassName">NSApplication</string>
+ </object>
+ <object class="NSWindowTemplate" id="748157544">
+ <int key="NSWindowStyleMask">15</int>
+ <int key="NSWindowBacking">2</int>
+ <string key="NSWindowRect">{{131, 74}, {606, 354}}</string>
+ <int key="NSWTFlags">611844096</int>
+ <string key="NSWindowTitle">Window</string>
+ <string key="NSWindowClass">MainWindow</string>
+ <nil key="NSViewClass" />
+ <string key="NSWindowContentMaxSize">{1.79769e+308, 1.79769e+308}</string>
+ <object class="NSView" key="NSWindowView" id="312036702">
+ <reference key="NSNextResponder" />
+ <int key="NSvFlags">256</int>
+ <string key="NSFrameSize">{606, 354}</string>
+ <reference key="NSSuperview" />
+ </object>
+ <string key="NSScreenRect">{{0, 0}, {1280, 778}}</string>
+ <string key="NSMaxSize">{1.79769e+308, 1.79769e+308}</string>
+ </object>
+ </object>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <object class="NSMutableArray" key="connectionRecords">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">window</string>
+ <reference key="source" ref="1001" />
+ <reference key="destination" ref="748157544" />
+ </object>
+ <int key="connectionID">6</int>
+ </object>
+ </object>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <object class="NSArray" key="orderedObjects">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <reference key="object" ref="0" />
+ <reference key="children" ref="1000" />
+ <nil key="parent" />
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="1001" />
+ <reference key="parent" ref="0" />
+ <string key="objectName">File's Owner</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="1003" />
+ <reference key="parent" ref="0" />
+ <string key="objectName">First Responder</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-3</int>
+ <reference key="object" ref="1004" />
+ <reference key="parent" ref="0" />
+ <string key="objectName">Application</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">2</int>
+ <reference key="object" ref="748157544" />
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="312036702" />
+ </object>
+ <reference key="parent" ref="0" />
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">3</int>
+ <reference key="object" ref="312036702" />
+ <reference key="parent" ref="748157544" />
+ </object>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="flattenedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>-1.IBPluginDependency</string>
+ <string>-2.IBPluginDependency</string>
+ <string>-3.IBPluginDependency</string>
+ <string>2.IBEditorWindowLastContentRect</string>
+ <string>2.IBPluginDependency</string>
+ <string>2.IBWindowTemplateEditedContentRect</string>
+ <string>2.NSWindowTemplate.visibleAtLaunch</string>
+ <string>3.IBPluginDependency</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>{{319, 371}, {606, 354}}</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>{{319, 371}, {606, 354}}</string>
+ <boolean value="YES" />
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="unlocalizedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0" />
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="activeLocalization" />
+ <object class="NSMutableDictionary" key="localizations">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0" />
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="sourceID" />
+ <int key="maxID">6</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <object class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">MainWindow</string>
+ <string key="superclassName">NSWindow</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBUserSource</string>
+ <string key="minorKey" />
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">MainWindowController</string>
+ <string key="superclassName">NSWindowController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBUserSource</string>
+ <string key="minorKey" />
+ </object>
+ </object>
+ </object>
+ </object>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
+ <integer value="3000" key="NS.object.0" />
+ </object>
+ <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
+ <nil key="IBDocument.LastKnownRelativeProjectPath" />
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ </data>
+</archive>
View
41 Samples/MonoMac/DrawImageTests/MainWindowController.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using MonoMac.Foundation;
+using MonoMac.AppKit;
+
+namespace DrawImageTests
+{
+ public partial class MainWindowController : MonoMac.AppKit.NSWindowController
+ {
+ #region Constructors
+ // Called when created from unmanaged code
+ public MainWindowController (IntPtr handle) : base (handle)
+ {
+ Initialize ();
+ }
+ // Called when created directly from a XIB file
+ [Export ("initWithCoder:")]
+ public MainWindowController (NSCoder coder) : base (coder)
+ {
+ Initialize ();
+ }
+ // Call to load from the XIB/NIB file
+ public MainWindowController () : base ("MainWindow")
+ {
+ Initialize ();
+ }
+ // Shared initialization code
+ void Initialize ()
+ {
+ }
+ #endregion
+ //strongly typed window accessor
+ public new MainWindow Window {
+ get {
+ return (MainWindow)base.Window;
+ }
+ }
+ }
+}
+
View
BIN Samples/MonoMac/DrawImageTests/bitmap25.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Samples/MonoMac/DrawImageTests/bitmap50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
113 System.Drawing/Graphics-DrawImage.cs
@@ -18,6 +18,12 @@ namespace System.Drawing
{
public partial class Graphics {
public delegate bool DrawImageAbort (IntPtr callbackData);
+
+ /// <summary>
+ /// Draws the specified Image at the specified location and with the specified size.
+ /// </summary>
+ /// <param name="image">Image.</param>
+ /// <param name="rect">Rect.</param>
public void DrawImage (Image image, RectangleF rect)
{
if (image == null)
@@ -34,6 +40,11 @@ public void DrawImage (Image image, RectangleF rect)
}
}
+ /// <summary>
+ /// Draws the specified Image, using its original physical size, at the specified location.
+ /// </summary>
+ /// <param name="image">Image.</param>
+ /// <param name="point">Point.</param>
public void DrawImage (Image image, PointF point)
{
if (image == null)
@@ -42,41 +53,120 @@ public void DrawImage (Image image, PointF point)
DrawImage(image, point.X, point.Y);
}
+ /// <summary>
+ /// Draws the specified Image at the specified location and with the specified shape and size.
+ ///
+ /// The destPoints parameter specifies three points of a parallelogram. The three Point structures
+ /// represent the upper-left, upper-right, and lower-left corners of the parallelogram. The fourth
+ /// point is extrapolated from the first three to form a parallelogram.
+ ///
+ /// The image represented by the image parameter is scaled and sheared to fit the shape of the
+ /// parallelogram specified by the destPoints parameters.
+ /// </summary>
+ /// <param name="image">Image.</param>
+ /// <param name="destPoints">Destination points.</param>
public void DrawImage (Image image, Point [] destPoints)
{
if (image == null)
throw new ArgumentNullException ("image");
if (destPoints == null)
throw new ArgumentNullException ("destPoints");
-
- //Status status = GDIPlus.GdipDrawImagePointsI (nativeObject, image.NativeObject, destPoints, destPoints.Length);
- //GDIPlus.CheckStatus (status);
- throw new NotImplementedException ();
+
+ if (destPoints.Length < 3)
+ throw new ArgumentException ("Destination points must be an array with a length of 3 or 4. " +
+ "A length of 3 defines a parallelogram with the upper-left, upper-right, " +
+ "and lower-left corners. A length of 4 defines a quadrilateral with the " +
+ "fourth element of the array specifying the lower-right coordinate.");
+
+ // Windows throws a Not Implemented error if the points are more than 3
+ if (destPoints.Length > 3)
+ throw new NotImplementedException ();
+
+ context.SaveState ();
+
+
+ var rect = new RectangleF (0,0, destPoints [1].X - destPoints [0].X, destPoints [2].Y - destPoints [0].Y);
+
+ // We need to give this some perspective so we will manipulate the transform matrix
+ // associated to the context
+ var affine = GeomUtilities.CreateGeometricTransform (rect, destPoints);
+ context.ConcatCTM (affine);
+
+ context.DrawImage(rect, image.NativeCGImage);
+
+ context.RestoreState ();
+
}
+ /// <summary>
+ /// Draws the specified Image, using its original physical size, at the specified location.
+ ///
+ /// </summary>
+ /// <param name="image">Image.</param>
+ /// <param name="point">Point.</param>
public void DrawImage (Image image, Point point)
{
if (image == null)
throw new ArgumentNullException ("image");
DrawImage (image, point.X, point.Y);
}
+ /// <summary>
+ /// Draws the specified Image at the specified location and with the specified size.
+ ///
+ /// The image represented by the image object is scaled to the dimensions of the rect rectangle.
+ /// </summary>
+ /// <param name="image">Image.</param>
+ /// <param name="rect">Rect.</param>
public void DrawImage (Image image, Rectangle rect)
{
if (image == null)
throw new ArgumentNullException ("image");
DrawImage (image, rect.X, rect.Y, rect.Width, rect.Height);
}
+ /// <summary>
+ /// Draws the specified Image at the specified location and with the specified shape and size.
+ ///
+ /// The destPoints parameter specifies three points of a parallelogram. The three PointF structures
+ /// represent the upper-left, upper-right, and lower-left corners of the parallelogram. The fourth point
+ /// is extrapolated from the first three to form a parallelogram.
+ ///
+ /// The image represented by the image object is scaled and sheared to fit the shape of the parallelogram
+ /// specified by the destPoints parameter.
+ /// </summary>
+ /// <param name="image">Image.</param>
+ /// <param name="destPoints">Destination points.</param>
public void DrawImage (Image image, PointF [] destPoints)
{
if (image == null)
throw new ArgumentNullException ("image");
if (destPoints == null)
throw new ArgumentNullException ("destPoints");
- throw new NotImplementedException ();
- //Status status = GDIPlus.GdipDrawImagePoints (nativeObject, image.NativeObject, destPoints, destPoints.Length);
- //GDIPlus.CheckStatus (status);
+ if (destPoints.Length < 3)
+ throw new ArgumentException ("Destination points must be an array with a length of 3 or 4. " +
+ "A length of 3 defines a parallelogram with the upper-left, upper-right, " +
+ "and lower-left corners. A length of 4 defines a quadrilateral with the " +
+ "fourth element of the array specifying the lower-right coordinate.");
+
+ // Windows throws a Not Implemented error if the points are more than 3
+ if (destPoints.Length > 3)
+ throw new NotImplementedException ();
+
+ context.SaveState ();
+
+
+ var rect = new RectangleF (0,0, destPoints [1].X - destPoints [0].X, destPoints [2].Y - destPoints [0].Y);
+
+ // We need to give this some perspective so we will manipulate the transform matrix
+ // associated to the context
+ var affine = GeomUtilities.CreateGeometricTransform (rect, destPoints);
+ context.ConcatCTM (affine);
+
+ context.DrawImage(rect, image.NativeCGImage);
+
+ context.RestoreState ();
+
}
public void DrawImage (Image image, int x, int y)
@@ -120,12 +210,16 @@ public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, Grap
if (destPoints == null)
throw new ArgumentNullException ("destPoints");
- throw new NotImplementedException ();
+ //throw new NotImplementedException ();
//Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
// destPoints, destPoints.Length , srcRect.X, srcRect.Y,
// srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero,
// null, IntPtr.Zero);
//GDIPlus.CheckStatus (status);
+
+ context.DrawImage (srcRect, image.NativeCGImage);
+
+
}
public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)
@@ -135,12 +229,13 @@ public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, Gr
if (destPoints == null)
throw new ArgumentNullException ("destPoints");
- throw new NotImplementedException ();
+ //throw new NotImplementedException ();
//Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
// destPoints, destPoints.Length , srcRect.X, srcRect.Y,
// srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero,
// null, IntPtr.Zero);
//GDIPlus.CheckStatus (status);
+ context.DrawImage (srcRect, image.NativeCGImage);
}
public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit,
View
4 Tests/Tests.csproj
@@ -123,4 +123,8 @@
<Name>sysdrawing-coregraphics</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <BundleResource Include="bitmap25.png" />
+ <BundleResource Include="bitmap50.png" />
+ </ItemGroup>
</Project>
View
BIN Tests/bitmap25.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Tests/bitmap50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
57 Utilities/GeomUtilities.cs
@@ -367,6 +367,63 @@ static double Erf(double x)
return sign * y;
}
+ /// <summary>
+ /// This method initializes the new CGAffineTransform such that it represents the geometric transform that maps the rectangle
+ /// specified by the rect parameter to the parallelogram defined by the three points in the plgpts parameter.
+ ///
+ /// The upper-left corner of the rectangle is mapped to the first point in the plgpts array, the upper-right corner
+ /// is mapped to the second point, and the lower-left corner is mapped to the third point. The lower-right point of
+ /// the parallelogram is implied by the first three.
+ /// </summary>
+ /// <returns>The affine transform.</returns>
+ /// <param name="rect">Rectangle.</param>
+ /// <param name="points">Points.</param>
+ internal static CGAffineTransform CreateGeometricTransform(RectangleF rect, PointF[] points)
+ {
+ var p0 = points [0];
+ var p1 = points [1];
+ var p2 = points [2];
+
+ var width = rect.Width;
+ var height = rect.Height;
+
+ float m11 = (p1.X - p0.X) / width;
+ float m12 = (p1.Y - p0.Y) / width;
+ float m21 = (p2.X - p0.X) / height;
+ float m22 = (p2.Y - p0.Y) / height;
+
+ return new CGAffineTransform (m11, m12, m21, m22, p0.X, p0.Y);
+
+ }
+
+ /// <summary>
+ /// This method initializes the new CGAffineTransform such that it represents the geometric transform that maps the rectangle
+ /// specified by the rect parameter to the parallelogram defined by the three points in the plgpts parameter.
+ ///
+ /// The upper-left corner of the rectangle is mapped to the first point in the plgpts array, the upper-right corner
+ /// is mapped to the second point, and the lower-left corner is mapped to the third point. The lower-right point of
+ /// the parallelogram is implied by the first three.
+ /// </summary>
+ /// <returns>The affine transform.</returns>
+ /// <param name="rect">Rectangle.</param>
+ /// <param name="points">Points.</param>
+ internal static CGAffineTransform CreateGeometricTransform(RectangleF rect, Point[] points)
+ {
+ var p0 = points [0];
+ var p1 = points [1];
+ var p2 = points [2];
+
+ var width = rect.Width;
+ var height = rect.Height;
+
+ float m11 = (p1.X - p0.X) / width;
+ float m12 = (p1.Y - p0.Y) / width;
+ float m21 = (p2.X - p0.X) / height;
+ float m22 = (p2.Y - p0.Y) / height;
+
+ return new CGAffineTransform (m11, m12, m21, m22, p0.X, p0.Y);
+
+ }
}
}
View
19 sysdrawing-coregraphics.sln
@@ -69,6 +69,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextureBrushTest", "Samples
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinearGradientBrushTest", "Samples\MonoMac\LinearGradientBrushTest\LinearGradientBrushTest.csproj", "{70083C13-6398-43E1-A75A-CC8A3EB9D7FA}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawImageTests", "Samples\MonoMac\DrawImageTests\DrawImageTests.csproj", "{1C81B532-1642-45E6-860A-A8F3817734E7}"
+EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples.MonoTouch", "Samples.MonoTouch", "{9F1E821E-5BAC-40C6-9FBE-4C81C1AD4E6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample", "Samples\MonoTouch\sample\sample.csproj", "{F6AEFFC5-4807-49A3-83C5-661E655CB59A}"
@@ -270,6 +272,20 @@ Global
{15A4C3D1-419B-4F0D-9894-93A92693BE20}.Release|iPhone.Build.0 = Release|iPhone
{15A4C3D1-419B-4F0D-9894-93A92693BE20}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{15A4C3D1-419B-4F0D-9894-93A92693BE20}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.Ad-Hoc|iPhone.ActiveCfg = Debug|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.Ad-Hoc|iPhone.Build.0 = Debug|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.AppStore|iPhone.ActiveCfg = Debug|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.AppStore|iPhone.Build.0 = Debug|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.AppStore|iPhoneSimulator.ActiveCfg = AppStore|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.AppStore|iPhoneSimulator.Build.0 = AppStore|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.Debug|iPhone.ActiveCfg = Debug|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.Debug|iPhone.Build.0 = Debug|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.Release|iPhone.ActiveCfg = Release|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.Release|iPhone.Build.0 = Release|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
+ {1C81B532-1642-45E6-860A-A8F3817734E7}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
{23B098F3-5BD5-4091-B61D-3EA06E511F0F}.Ad-Hoc|iPhone.ActiveCfg = Debug|iPhoneSimulator
{23B098F3-5BD5-4091-B61D-3EA06E511F0F}.Ad-Hoc|iPhone.Build.0 = Debug|iPhoneSimulator
{23B098F3-5BD5-4091-B61D-3EA06E511F0F}.AppStore|iPhone.ActiveCfg = AppStore|iPhoneSimulator
@@ -1016,6 +1032,7 @@ Global
{3CF93BDF-561C-42FF-B227-93CB39DE94BF} = {A28D8EBD-ABB8-46BA-B536-7074058B0C84}
{8334DB3C-C6D8-4AF0-A70C-12405D50E18C} = {A28D8EBD-ABB8-46BA-B536-7074058B0C84}
{70083C13-6398-43E1-A75A-CC8A3EB9D7FA} = {A28D8EBD-ABB8-46BA-B536-7074058B0C84}
+ {1C81B532-1642-45E6-860A-A8F3817734E7} = {A28D8EBD-ABB8-46BA-B536-7074058B0C84}
{F6AEFFC5-4807-49A3-83C5-661E655CB59A} = {9F1E821E-5BAC-40C6-9FBE-4C81C1AD4E6A}
{376D4335-5ED4-4A24-BF16-4DDFFCE61B6D} = {9F1E821E-5BAC-40C6-9FBE-4C81C1AD4E6A}
{E8E64FE2-DF66-4BF2-921B-F9B8DECFB663} = {9F1E821E-5BAC-40C6-9FBE-4C81C1AD4E6A}
@@ -1049,7 +1066,7 @@ Global
{67375DDB-4C86-4581-966E-48DE06FAD73C} = {9F1E821E-5BAC-40C6-9FBE-4C81C1AD4E6A}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
- StartupItem = Samples\MonoMac\Example1_5\Example1_5.csproj
+ StartupItem = Samples\MonoMac\DrawImageTests\DrawImageTests.csproj
Policies = $0
$0.TextStylePolicy = $1
$1.inheritsSet = Mono

0 comments on commit 22fbaf0

Please sign in to comment.
Something went wrong with that request. Please try again.