(void)Create(w, h, d);
}
+wxBitmap::wxBitmap(NSImage* cocoaNSImage)
+{
+ (void) Create(cocoaNSImage);
+}
+
+wxBitmap::wxBitmap(NSBitmapImageRep* cocoaNSBitmapImageRep)
+{
+ (void) Create(cocoaNSBitmapImageRep);
+}
+
wxBitmap::wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth)
{
(void) Create(data, type, width, height, depth);
return true;
}
+bool wxBitmap::Create(NSImage* cocoaNSImage)
+{
+ wxAutoNSAutoreleasePool pool;
+ NSBitmapImageRep *bitmapImageRep = [NSBitmapImageRep imageRepWithData:[cocoaNSImage TIFFRepresentation]];
+ return Create(bitmapImageRep);
+}
+
+bool wxBitmap::Create(NSBitmapImageRep *imageRep)
+{
+ UnRef();
+ m_refData = new wxBitmapRefData;
+ if(imageRep != nil)
+ {
+ M_BITMAPDATA->m_width = [imageRep pixelsWide];
+ M_BITMAPDATA->m_height = [imageRep pixelsHigh];
+ M_BITMAPDATA->m_depth = [imageRep bitsPerPixel];
+ M_BITMAPDATA->m_ok = true;
+ M_BITMAPDATA->m_numColors = 0;
+ M_BITMAPDATA->m_quality = 0;
+ M_BITMAPDATA->m_cocoaNSBitmapImageRep = [imageRep retain];
+ M_BITMAPDATA->m_bitmapMask = NULL;
+ return true;
+ }
+ else
+ return false;
+}
+
bool wxBitmap::Create(const void* data, wxBitmapType type, int width, int height, int depth)
{
UnRef();
return true;
}
-wxBitmap wxBitmap::GetSubBitmap(wxRect const&) const
+wxBitmap wxBitmap::GetSubBitmap(const wxRect& rect) const
{
- return wxNullBitmap;
+ wxAutoNSAutoreleasePool pool;
+ if(!Ok())
+ return wxNullBitmap;
+ NSImage *nsimage = GetNSImage(false);
+
+ [nsimage lockFocus];
+ NSRect imageRect = {{0,0}, [nsimage size]};
+ imageRect.origin.x = imageRect.size.width * rect.x / GetWidth();
+ imageRect.origin.y = imageRect.size.height * rect.y / GetHeight();
+ imageRect.size.width *= wx_static_cast(CGFloat, rect.width) / GetWidth();
+ imageRect.size.height *= wx_static_cast(CGFloat, rect.height) / GetHeight();
+
+ NSBitmapImageRep *newBitmapRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:imageRect];
+ [nsimage unlockFocus];
+
+ wxBitmap newBitmap(newBitmapRep);
+
+ return (newBitmap);
}
wxImage wxBitmap::ConvertToImage() const