@@ -486,90 +486,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
486486 return image;
487487}
488488
489- static PyObject*
490- FigureCanvas_write_bitmap (FigureCanvas* self, PyObject* args)
491- {
492- View* view = self->view ;
493- int n;
494- const unichar * characters;
495- NSSize size;
496- double width, height, dpi;
497-
498- if (!view)
499- {
500- PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
501- return NULL ;
502- }
503- /* NSSize contains CGFloat; cannot use size directly */
504- if (!PyArg_ParseTuple (args, " u#ddd" ,
505- &characters, &n, &width, &height, &dpi)) return NULL ;
506- size.width = width;
507- size.height = height;
508-
509- /* This function may be called from inside the event loop, when an
510- * autorelease pool is available, or from Python, when no autorelease
511- * pool is available. To be able to handle the latter case, we need to
512- * create an autorelease pool here. */
513-
514- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc ] init ];
515-
516- NSRect rect = [view bounds ];
517-
518- NSString * filename = [NSString stringWithCharacters: characters
519- length: (unsigned )n];
520- NSString * extension = [filename pathExtension ];
521-
522- /* Calling dataWithPDFInsideRect on the view causes its update status
523- * to be cleared. Save the status here, and invalidate the view if not
524- * up to date after calling dataWithPDFInsideRect. */
525- const BOOL invalid = [view needsDisplay ];
526- NSData * data = [view dataWithPDFInsideRect: rect];
527- if (invalid) [view setNeedsDisplay: YES ];
528-
529- NSImage * image = [[NSImage alloc ] initWithData: data];
530- NSImage *resizedImage = [[NSImage alloc ] initWithSize: size];
531-
532- [resizedImage lockFocus ];
533- [image drawInRect: NSMakeRect (0 , 0 , width, height) fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0 ];
534- [resizedImage unlockFocus ];
535- data = [resizedImage TIFFRepresentation ];
536- [image release ];
537- [resizedImage release ];
538-
539- NSBitmapImageRep * rep = [NSBitmapImageRep imageRepWithData: data];
540-
541- NSSize pxlSize = NSMakeSize ([rep pixelsWide ], [rep pixelsHigh ]);
542- NSSize newSize = NSMakeSize (72.0 * pxlSize.width / dpi, 72.0 * pxlSize.height / dpi);
543-
544- [rep setSize: newSize];
545-
546- NSBitmapImageFileType filetype;
547- if ([extension isEqualToString: @" bmp" ])
548- filetype = NSBMPFileType ;
549- else if ([extension isEqualToString: @" gif" ])
550- filetype = NSGIFFileType ;
551- else if ([extension isEqualToString: @" jpg" ] ||
552- [extension isEqualToString: @" jpeg" ])
553- filetype = NSJPEGFileType ;
554- else if ([extension isEqualToString: @" png" ])
555- filetype = NSPNGFileType ;
556- else if ([extension isEqualToString: @" tiff" ] ||
557- [extension isEqualToString: @" tif" ])
558- filetype = NSTIFFFileType ;
559- else
560- { PyErr_SetString (PyExc_ValueError, " Unknown file type" );
561- return NULL ;
562- }
563-
564- data = [rep representationUsingType: filetype properties: [NSDictionary dictionary ]];
565-
566- [data writeToFile: filename atomically: YES ];
567- [pool release ];
568-
569- Py_INCREF (Py_None);
570- return Py_None;
571- }
572-
573489static PyObject*
574490FigureCanvas_start_event_loop (FigureCanvas* self, PyObject* args, PyObject* keywords)
575491{
@@ -685,12 +601,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
685601 METH_NOARGS,
686602 " Removes the current rubberband rectangle."
687603 },
688- {" write_bitmap" ,
689- (PyCFunction)FigureCanvas_write_bitmap,
690- METH_VARARGS,
691- " Saves the figure to the specified file as a bitmap\n "
692- " (bmp, gif, jpeg, or png).\n "
693- },
694604 {" start_event_loop" ,
695605 (PyCFunction)FigureCanvas_start_event_loop,
696606 METH_KEYWORDS | METH_VARARGS,
0 commit comments