@@ -1162,15 +1162,29 @@ def _print_image(self, filename, filetype, *args, **kwargs):
1162
1162
gc = renderer .new_gc ()
1163
1163
1164
1164
self .figure .draw (renderer )
1165
+
1166
+ # image is the object that we call SaveFile on.
1167
+ image = self .bitmap
1168
+
1169
+ # set the JPEG quality appropriately. Unfortunately, it is only possible
1170
+ # to set the quality on a wx.Image object. So if we are saving a JPEG,
1171
+ # convert the wx.Bitmap to a wx.Image, and set the quality.
1172
+ if filetype == wx .BITMAP_TYPE_JPEG :
1173
+ jpeg_quality = kwargs .get ('quality' ,rcParams ['savefig.jpeg_quality' ])
1174
+ image = self .bitmap .ConvertToImage ()
1175
+ image .SetOption (wx .IMAGE_OPTION_QUALITY ,jpeg_quality )
1176
+
1165
1177
1166
1178
# Now that we have rendered into the bitmap, save it
1167
1179
# to the appropriate file type and clean up
1168
1180
if is_string_like (filename ):
1169
- if not self . bitmap .SaveFile (filename , filetype ):
1181
+ if not image .SaveFile (filename , filetype ):
1170
1182
DEBUG_MSG ('print_figure() file save error' , 4 , self )
1171
1183
raise RuntimeError ('Could not save figure to %s\n ' % (filename ))
1172
1184
elif is_writable_file_like (filename ):
1173
- if not self .bitmap .ConvertToImage ().SaveStream (filename , filetype ):
1185
+ if not isinstance (image ,wx .Image ):
1186
+ image = image .ConvertToImage ()
1187
+ if not image .SaveStream (filename , filetype ):
1174
1188
DEBUG_MSG ('print_figure() file save error' , 4 , self )
1175
1189
raise RuntimeError ('Could not save figure to %s\n ' % (filename ))
1176
1190
0 commit comments