KiCad PCB EDA Suite
bitmap.cpp File Reference
#include <wx/image.h>
#include <wx/bitmap.h>
#include <wx/mstream.h>
#include <wx/menu.h>
#include <wx/menuitem.h>
#include <wx/aui/auibar.h>
#include <cstdint>
#include <mutex>
#include <unordered_map>
#include <common.h>
#include <bitmaps.h>
#include <pgm_base.h>
#include <eda_base_frame.h>
#include <eda_draw_frame.h>
#include <settings/common_settings.h>

Go to the source code of this file.

Classes

struct  SCALED_BITMAP_ID
 
struct  std::hash< SCALED_BITMAP_ID >
 

Namespaces

 std
 

Template specialization to enable wxStrings for certain containers (e.g. unordered_map)


 

Functions

wxBitmap KiBitmap (BITMAP_DEF aBitmap)
 Construct a wxBitmap from a memory record, held in a BITMAP_DEF. More...
 
int KiIconScale (wxWindow *aWindow)
 Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScaledSeparator. More...
 
static int get_scale_factor (wxWindow *aWindow)
 
wxBitmap KiScaledBitmap (BITMAP_DEF aBitmap, wxWindow *aWindow)
 Construct a wxBitmap from a memory record, scaling it if device DPI demands it. More...
 
wxBitmap KiScaledBitmap (const wxBitmap &aBitmap, wxWindow *aWindow)
 Overload of the above function that takes another wxBitmap as a parameter. More...
 
wxBitmap * KiBitmapNew (BITMAP_DEF aBitmap)
 Allocate a wxBitmap on heap from a memory record, held in a BITMAP_DEF. More...
 
bool SaveCanvasImageToFile (EDA_DRAW_FRAME *aFrame, const wxString &aFileName, wxBitmapType aBitmapType)
 Save the current view as an image file. More...
 
void AddBitmapToMenuItem (wxMenuItem *aMenu, const wxBitmap &aImage)
 Add a bitmap to a menuitem. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aMenu. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, int aId, const wxString &aText, const wxString &aHelpText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aMenu. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, wxMenu *aSubMenu, int aId, const wxString &aText, const wxBitmap &aImage)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aSubMenu in aMenu. More...
 
wxMenuItem * AddMenuItem (wxMenu *aMenu, wxMenu *aSubMenu, int aId, const wxString &aText, const wxString &aHelpText, const wxBitmap &aImage)
 Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aSubMenu in aMenu. More...
 

Function Documentation

◆ AddBitmapToMenuItem()

void AddBitmapToMenuItem ( wxMenuItem *  aMenu,
const wxBitmap &  aImage 
)

Add a bitmap to a menuitem.

Parameters
aMenuis the menuitem.
aImageis the icon to add to aMenu. It is added only if use images in menus config option allows it. For wxITEM_CHECK or wxITEM_RADIO menuitems, the bitmap is added only on Windows, other platforms do not support it

Definition at line 205 of file bitmap.cpp.

206 {
207  // Retrieve the global applicaton show icon option:
208  bool useImagesInMenus = Pgm().GetCommonSettings()->m_Appearance.use_icons_in_menus;
209 
210  wxItemKind menu_type = aMenu->GetKind();
211 
212  if( useImagesInMenus )
213  {
214  if( menu_type == wxITEM_CHECK || menu_type == wxITEM_RADIO )
215  {
216  #if defined( __WINDOWS__ )
217  aMenu->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
218  // A workaround to a strange bug on Windows, wx Widgets 3.0:
219  // size of bitmaps is not taken in account for wxITEM_{CHECK,RADIO} menu
220  // unless we call SetFont
221  aMenu->SetFont( *wxNORMAL_FONT );
222  #endif
223  }
224  else if( menu_type != wxITEM_RADIO )
225  {
226  aMenu->SetBitmap( aImage );
227  }
228  }
229 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
const BITMAP_OPAQUE checked_ok_xpm[1]
Definition: checked_ok.cpp:51

References checked_ok_xpm, KiBitmap(), and Pgm().

Referenced by ACTION_MENU::Add(), CONDITIONAL_MENU::AddCheckItem(), CONDITIONAL_MENU::AddItem(), AddMenuItem(), ACTION_MENU::appendCopy(), ACTION_MENU::DisplayTitle(), CONDITIONAL_MENU::Evaluate(), and SIM_PLOT_FRAME::setIconsForMenuItems().

◆ AddMenuItem() [1/4]

wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
int  aId,
const wxString &  aText,
const wxBitmap &  aImage,
wxItemKind  aType = wxITEM_NORMAL 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aMenu.

Parameters
aMenuis the menu to add the new item.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aImageis the icon to add to the new menu item.
aTypeis the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
Returns
a pointer to the new created wxMenuItem

Definition at line 232 of file bitmap.cpp.

234 {
235  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
236  AddBitmapToMenuItem( item, aImage );
237 
238  aMenu->Append( item );
239 
240  return item;
241 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:205

References AddBitmapToMenuItem().

Referenced by PCB_LAYER_WIDGET::AddRightClickMenuItems(), GERBER_LAYER_WIDGET::AddRightClickMenuItems(), DIALOG_CONFIGURE_PATHS::OnGridCellRightClick(), TREE_PROJECT_FRAME::OnRight(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PANEL_COLOR_SETTINGS::ShowColorContextMenu(), and SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU().

◆ AddMenuItem() [2/4]

wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
int  aId,
const wxString &  aText,
const wxString &  aHelpText,
const wxBitmap &  aImage,
wxItemKind  aType = wxITEM_NORMAL 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aMenu.

Parameters
aMenuis the menu to add the new item.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aHelpTextis the help message string for the new menu item.
aImageis the icon to add to the new menu item.
aTypeis the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
Returns
a pointer to the new created wxMenuItem

Definition at line 244 of file bitmap.cpp.

247 {
248  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
249  AddBitmapToMenuItem( item, aImage );
250 
251  aMenu->Append( item );
252 
253  return item;
254 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:205

References AddBitmapToMenuItem().

◆ AddMenuItem() [3/4]

wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
wxMenu *  aSubMenu,
int  aId,
const wxString &  aText,
const wxBitmap &  aImage 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into aSubMenu in aMenu.

Parameters
aMenuis the menu to add the new submenu item.
aSubMenuis the submenu to add the new menu.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aImageis the icon to add to the new menu item.
Returns
a pointer to the new created wxMenuItem

Definition at line 257 of file bitmap.cpp.

259 {
260  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText );
261  item->SetSubMenu( aSubMenu );
262  AddBitmapToMenuItem( item, aImage );
263 
264  aMenu->Append( item );
265 
266  return item;
267 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:205

References AddBitmapToMenuItem().

◆ AddMenuItem() [4/4]

wxMenuItem* AddMenuItem ( wxMenu *  aMenu,
wxMenu *  aSubMenu,
int  aId,
const wxString &  aText,
const wxString &  aHelpText,
const wxBitmap &  aImage 
)

Function AddMenuItem is an inline helper function to create and insert a menu item with an icon and a help message string into aSubMenu in aMenu.

Parameters
aMenuis the menu to add the new submenu item.
aSubMenuis the submenu to add the new menu.
aIdis the command ID for the new menu item.
aTextis the string for the new menu item.
aHelpTextis the help message string for the new menu item.
aImageis the icon to add to the new menu item.
Returns
a pointer to the new created wxMenuItem

Definition at line 270 of file bitmap.cpp.

273 {
274  wxMenuItem* item = new wxMenuItem( aMenu, aId, aText, aHelpText );
275  item->SetSubMenu( aSubMenu );
276  AddBitmapToMenuItem( item, aImage );
277 
278  aMenu->Append( item );
279 
280  return item;
281 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:205

References AddBitmapToMenuItem().

◆ get_scale_factor()

static int get_scale_factor ( wxWindow *  aWindow)
static

Definition at line 105 of file bitmap.cpp.

106 {
107  int requested_scale = Pgm().GetCommonSettings()->m_Appearance.icon_scale;
108 
109  if( requested_scale > 0 )
110  return requested_scale;
111  else
112  return KiIconScale( aWindow );
113 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
Definition: bitmap.cpp:90

References KiIconScale(), and Pgm().

Referenced by KiScaledBitmap().

◆ KiBitmap()

wxBitmap KiBitmap ( BITMAP_DEF  aBitmap)

Construct a wxBitmap from a memory record, held in a BITMAP_DEF.

Definition at line 80 of file bitmap.cpp.

81 {
82  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
83  wxImage image( is, wxBITMAP_TYPE_PNG );
84  wxBitmap bitmap( image );
85 
86  return bitmap;
87 }
const unsigned char * png
Definition: bitmap_def.h:31

References BITMAP_OPAQUE::byteCount, and BITMAP_OPAQUE::png.

Referenced by ACTION_MENU::Add(), AddBitmapToMenuItem(), CONDITIONAL_MENU::AddCheckItem(), CONDITIONAL_MENU::AddItem(), PCB_LAYER_WIDGET::AddRightClickMenuItems(), GERBER_LAYER_WIDGET::AddRightClickMenuItems(), BM2CMP_FRAME::BM2CMP_FRAME(), GRID_CELL_ICON_TEXT_POPUP::Create(), DIALOG_ABOUT::createStaticBitmap(), CVPCB_MAINFRAME::CVPCB_MAINFRAME(), DIALOG_ABOUT::DIALOG_ABOUT(), DIALOG_BOM::DIALOG_BOM(), DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS(), DIALOG_COPPER_ZONE::DIALOG_COPPER_ZONE(), DIALOG_EDIT_COMPONENT_IN_LIBRARY::DIALOG_EDIT_COMPONENT_IN_LIBRARY(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC(), DIALOG_EDIT_LINE_STYLE::DIALOG_EDIT_LINE_STYLE(), DIALOG_EXCHANGE_FOOTPRINTS::DIALOG_EXCHANGE_FOOTPRINTS(), DIALOG_EXPORT_SVG::DIALOG_EXPORT_SVG(), DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL(), DIALOG_FOOTPRINT_BOARD_EDITOR::DIALOG_FOOTPRINT_BOARD_EDITOR(), DIALOG_FOOTPRINT_FP_EDITOR::DIALOG_FOOTPRINT_FP_EDITOR(), DIALOG_FP_PLUGIN_OPTIONS::DIALOG_FP_PLUGIN_OPTIONS(), DIALOG_IMPORT_SETTINGS::DIALOG_IMPORT_SETTINGS(), DIALOG_LIB_EDIT_PIN::DIALOG_LIB_EDIT_PIN(), DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE(), DIALOG_MIGRATE_SETTINGS::DIALOG_MIGRATE_SETTINGS(), DIALOG_NETLIST::DIALOG_NETLIST(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::DIALOG_PAD_PRIMITIVE_POLY_PROPS(), DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES(), DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC(), DIALOG_SCH_IMPORT_SETTINGS::DIALOG_SCH_IMPORT_SETTINGS(), DIALOG_SCH_SHEET_PROPS::DIALOG_SCH_SHEET_PROPS(), DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME(), ACTION_MENU::DisplayTitle(), GRID_CELL_ICON_TEXT_RENDERER::Draw(), EDA_3D_VIEWER::EDA_3D_VIEWER(), CONDITIONAL_MENU::Evaluate(), EVT_GRID_CMD_CELL_CHANGED(), EVT_MENU_RANGE(), EVT_UPDATE_UI_RANGE(), FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME(), FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME(), GERBVIEW_FRAME::GERBVIEW_FRAME(), HIERARCHY_TREE::HIERARCHY_TREE(), DIALOG_EDIT_ONE_FIELD::init(), DIALOG_PLOT::init_Dialog(), DIALOG_3D_VIEW_OPTIONS::initDialog(), DIALOG_GEN_FOOTPRINT_POSITION::initDialog(), DIALOG_GENDRILL::InitDisplayParams(), DIALOG_ANNOTATE::InitValues(), LIB_EDIT_FRAME::LIB_EDIT_FRAME(), LIB_VIEW_FRAME::LIB_VIEW_FRAME(), DIALOG_CONFIGURE_PATHS::OnGridCellRightClick(), WIZARD_3DSHAPE_LIBS_DOWNLOADER::OnPageChanged(), TREE_PROJECT_FRAME::OnRight(), LAYER_WIDGET::OnRightDownLayer(), LAYER_WIDGET::OnRightDownRender(), SIM_PLOT_FRAME::onSimFinished(), SIM_PLOT_FRAME::onSimStarted(), PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS(), PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::PANEL_EESCHEMA_TEMPLATE_FIELDNAMES(), PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE(), PANEL_PCBNEW_ACTION_PLUGINS::PANEL_PCBNEW_ACTION_PLUGINS(), PANEL_PREV_3D::PANEL_PREV_3D(), PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES(), PANEL_SETUP_TRACKS_AND_VIAS::PANEL_SETUP_TRACKS_AND_VIAS(), PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE(), PANEL_TEXT_VARIABLES::PANEL_TEXT_VARIABLES(), PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME(), PinShapeComboBox::PinShapeComboBox(), PinTypeComboBox::PinTypeComboBox(), PL_EDITOR_FRAME::PL_EDITOR_FRAME(), PANEL_SETUP_PINMAP::ReBuildMatrixPanel(), FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::SCH_EDIT_FRAME(), PANEL_SETUP_PINMAP::setDRCMatrixButtonState(), SIM_PLOT_FRAME::setIconsForMenuItems(), PANEL_MODEDIT_DEFAULTS::Show(), PANEL_SETUP_FEATURE_CONSTRAINTS::Show(), PANEL_COLOR_SETTINGS::ShowColorContextMenu(), SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU(), SIM_PLOT_FRAME::SIM_PLOT_FRAME(), TEXT_BUTTON_FILE_BROWSER::TEXT_BUTTON_FILE_BROWSER(), TEXT_BUTTON_FP_CHOOSER::TEXT_BUTTON_FP_CHOOSER(), TEXT_BUTTON_SYMBOL_CHOOSER::TEXT_BUTTON_SYMBOL_CHOOSER(), TEXT_BUTTON_URL::TEXT_BUTTON_URL(), BM2CMP_FRAME::ToggleAspectRatioLock(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataToWindow(), TREEPROJECTFILES::TREEPROJECTFILES(), DIALOG_JUNCTION_PROPS::updateColorButton(), and DIALOG_EDIT_LINE_STYLE::updateColorButton().

◆ KiBitmapNew()

wxBitmap* KiBitmapNew ( BITMAP_DEF  aBitmap)

Allocate a wxBitmap on heap from a memory record, held in a BITMAP_DEF.

Returns
wxBitmap* - caller owns it.

Definition at line 167 of file bitmap.cpp.

168 {
169  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
170  wxImage image( is, wxBITMAP_TYPE_PNG );
171  wxBitmap* bitmap = new wxBitmap( image );
172 
173  return bitmap;
174 }
const unsigned char * png
Definition: bitmap_def.h:31

References BITMAP_OPAQUE::byteCount, and BITMAP_OPAQUE::png.

Referenced by ABOUT_APP_INFO::CreateKiBitmap().

◆ KiIconScale()

int KiIconScale ( wxWindow *  aWindow)

Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScaledSeparator.

Definition at line 90 of file bitmap.cpp.

91 {
92  const int vert_size = aWindow->ConvertDialogToPixels( wxSize( 0, 8 ) ).y;
93 
94  // Autoscale won't exceed unity until the system has quite high resolution,
95  // because we don't want the icons to look obviously scaled on a system
96  // where it's easy to see it.
97 
98  if( vert_size > 34 ) return 8;
99  else if( vert_size > 29 ) return 7;
100  else if( vert_size > 24 ) return 6;
101  else return 4;
102 }

Referenced by ACTION_TOOLBAR::AddScaledSeparator(), get_scale_factor(), PANEL_COMMON_SETTINGS::OnIconScaleAuto(), PCB_EDIT_FRAME::PrepareLayerIndicator(), and PANEL_COMMON_SETTINGS::TransferDataToWindow().

◆ KiScaledBitmap() [1/2]

wxBitmap KiScaledBitmap ( BITMAP_DEF  aBitmap,
wxWindow *  aWindow 
)

Construct a wxBitmap from a memory record, scaling it if device DPI demands it.

Internally this may use caching to avoid scaling the same image twice. If caching is used, it's guaranteed threadsafe.

Parameters
aBitmapbitmap definition
aWindowtarget window for scaling context

Definition at line 116 of file bitmap.cpp.

117 {
118  // Bitmap conversions are cached because they can be slow.
119  static std::unordered_map<SCALED_BITMAP_ID, wxBitmap> bitmap_cache;
120  static std::mutex bitmap_cache_mutex;
121  const int scale = get_scale_factor( aWindow );
122 
123  SCALED_BITMAP_ID id = { aBitmap, scale };
124 
125  std::lock_guard<std::mutex> guard( bitmap_cache_mutex );
126  auto it = bitmap_cache.find( id );
127 
128  if( it != bitmap_cache.end() )
129  {
130  return it->second;
131  }
132  else
133  {
134  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
135  wxImage image( is, wxBITMAP_TYPE_PNG );
136 
137  // Bilinear seems to genuinely look better for these line-drawing icons
138  // than bicubic, despite claims in the wx documentation that bicubic is
139  // "highest quality". I don't recommend changing this. Bicubic looks
140  // blurry and makes me want an eye exam.
141  image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
142  wxIMAGE_QUALITY_BILINEAR );
143  return bitmap_cache.emplace( id, wxBitmap( image ) ).first->second;
144  }
145 }
static int get_scale_factor(wxWindow *aWindow)
Definition: bitmap.cpp:105
const unsigned char * png
Definition: bitmap_def.h:31
const int scale

References BITMAP_OPAQUE::byteCount, get_scale_factor(), BITMAP_OPAQUE::png, and scale.

Referenced by ACTION_TOOLBAR::Add(), ACTION_TOOLBAR::AddButton(), PANEL_SETUP_BOARD_STACKUP::PANEL_SETUP_BOARD_STACKUP(), PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar(), KICAD_MANAGER_FRAME::RecreateBaseHToolbar(), LIB_VIEW_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), GERBVIEW_FRAME::ReCreateHToolbar(), KICAD_MANAGER_FRAME::RecreateLauncher(), EDA_3D_VIEWER::ReCreateMainToolbar(), GERBVIEW_FRAME::ReCreateOptToolbar(), and LIB_EDIT_FRAME::ReCreateVToolbar().

◆ KiScaledBitmap() [2/2]

wxBitmap KiScaledBitmap ( const wxBitmap &  aBitmap,
wxWindow *  aWindow 
)

Overload of the above function that takes another wxBitmap as a parameter.

Parameters
aBitmapbitmap definition
aWindowtarget window for scaling context

Definition at line 148 of file bitmap.cpp.

149 {
150  const int scale = get_scale_factor( aWindow );
151 
152  if( scale == 4)
153  {
154  return wxBitmap( aBitmap );
155  }
156  else
157  {
158  wxImage image = aBitmap.ConvertToImage();
159  image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
160  wxIMAGE_QUALITY_BILINEAR );
161 
162  return wxBitmap( image );
163  }
164 }
static int get_scale_factor(wxWindow *aWindow)
Definition: bitmap.cpp:105
const int scale

References get_scale_factor(), and scale.

◆ SaveCanvasImageToFile()

bool SaveCanvasImageToFile ( EDA_DRAW_FRAME aFrame,
const wxString &  aFileName,
wxBitmapType  aBitmapType = wxBITMAP_TYPE_PNG 
)

Save the current view as an image file.

Parameters
aFrameThe current draw frame view to save.
aFileNameThe file name to save the image. This will overwrite an exisiting file.
aBitmapTypeThe type of bitmap create as defined by wxImage.
Returns
True if the file was successfully saved or false if the file failed to be saved.

Definition at line 177 of file bitmap.cpp.

179 {
180  wxCHECK( aFrame != nullptr, false );
181 
182  bool retv = true;
183 
184  // Make a screen copy of the canvas:
185  wxSize image_size = aFrame->GetCanvas()->GetClientSize();
186 
187  wxClientDC dc( aFrame->GetCanvas() );
188  wxBitmap bitmap( image_size.x, image_size.y );
189  wxMemoryDC memdc;
190 
191  memdc.SelectObject( bitmap );
192  memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
193  memdc.SelectObject( wxNullBitmap );
194 
195  wxImage image = bitmap.ConvertToImage();
196 
197  if( !image.SaveFile( aFileName, aBitmapType ) )
198  retv = false;
199 
200  image.Destroy();
201  return retv;
202 }
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.

References EDA_DRAW_FRAME::GetCanvas().

Referenced by LIB_CONTROL::ExportView(), and FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng().