Skip to content

Commit

Permalink
Mac: Bitmap now ignores image's DPI setting for sizing (like other pl…
Browse files Browse the repository at this point in the history
…atforms)

Mac: Update MonoMac.dll to pull in latest changes/fixes
  • Loading branch information
Curtis Wensley authored and Curtis Wensley committed Aug 1, 2012
1 parent d09a570 commit 6613d13
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Binary file modified Libraries/MonoMac/MonoMac.dll
Binary file not shown.
34 changes: 26 additions & 8 deletions Source/Eto.Platform.Mac/Drawing/BitmapHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public override uint TranslateDataToArgb (uint bitmapData)

public class BitmapHandler : ImageHandler<NSImage, Bitmap>, IBitmap
{
NSBitmapImageRep rep;
NSImageRep rep;
NSBitmapImageRep bmprep;
bool alpha = true;

public BitmapHandler ()
Expand All @@ -60,11 +61,17 @@ public BitmapHandler (NSImage image)
public void Create (string fileName)
{
Control = new NSImage (fileName);
rep = Control.BestRepresentationForDevice(null);
bmprep = rep as NSBitmapImageRep;
Control.Size = new SD.SizeF(rep.PixelsWide, rep.PixelsHigh);
}

public void Create (Stream stream)
{
Control = new NSImage (NSData.FromStream (stream));
rep = Control.BestRepresentationForDevice(null);
bmprep = rep as NSBitmapImageRep;
Control.Size = new SD.SizeF(rep.PixelsWide, rep.PixelsHigh);
}

public void Create (int width, int height, PixelFormat pixelFormat)
Expand All @@ -79,7 +86,7 @@ public void Create (int width, int height, PixelFormat pixelFormat)
int bytesPerPixel = bitsPerPixel / 8;
int bytesPerRow = bytesPerPixel * width;

rep = new NSBitmapImageRep (IntPtr.Zero, width, height, bitsPerComponent, 3, false, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel);
rep = bmprep = new NSBitmapImageRep (IntPtr.Zero, width, height, bitsPerComponent, 3, false, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel);
Control = new NSImage ();
Control.AddRepresentation (rep);

Expand All @@ -98,7 +105,7 @@ public void Create (int width, int height, PixelFormat pixelFormat)
int bytesPerPixel = bitsPerPixel / 8;
int bytesPerRow = bytesPerPixel * width;

rep = new NSBitmapImageRep (IntPtr.Zero, width, height, bitsPerComponent, numComponents, false, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel);
rep = bmprep = new NSBitmapImageRep (IntPtr.Zero, width, height, bitsPerComponent, numComponents, false, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel);
Control = new NSImage ();
Control.AddRepresentation (rep);

Expand All @@ -115,7 +122,7 @@ public void Create (int width, int height, PixelFormat pixelFormat)
int bytesPerPixel = bitsPerPixel / 8;
int bytesPerRow = bytesPerPixel * width;

rep = new NSBitmapImageRep (IntPtr.Zero, width, height, bitsPerComponent, numComponents, true, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel);
rep = bmprep = new NSBitmapImageRep (IntPtr.Zero, width, height, bitsPerComponent, numComponents, true, false, NSColorSpace.DeviceRGB, bytesPerRow, bitsPerPixel);
Control = new NSImage ();
Control.AddRepresentation (rep);

Expand Down Expand Up @@ -146,7 +153,10 @@ public override NSImage GetImage ()
public BitmapData Lock ()
{
//Control.LockFocus();
return new BitmapDataHandler (rep.BitmapData, rep.BytesPerRow, Control);
if (bmprep != null)
return new BitmapDataHandler (bmprep.BitmapData, bmprep.BytesPerRow, Control);
else
return null;
}

public void Unlock (BitmapData bitmapData)
Expand Down Expand Up @@ -183,8 +193,8 @@ public void Save (Stream stream, ImageFormat format)
var newrep = reps.OfType<NSBitmapImageRep> ().FirstOrDefault ();
if (newrep == null) {
NSData tiff;
if (this.rep != null)
tiff = this.rep.TiffRepresentation;
if (this.bmprep != null)
tiff = this.bmprep.TiffRepresentation;
else
tiff = Control.AsTiff ();
newrep = new NSBitmapImageRep (tiff);
Expand All @@ -197,7 +207,15 @@ public void Save (Stream stream, ImageFormat format)
}

public override Size Size {
get { return Generator.ConvertF (Control.Size); }
get {
NSImageRep rep = this.rep;
if (rep == null)
rep = Control.BestRepresentationForDevice (null);
if (rep != null)
return new Size(rep.PixelsWide, rep.PixelsHigh);
else
return Generator.ConvertF (Control.Size);
}
}

/*
Expand Down

0 comments on commit 6613d13

Please sign in to comment.