File: wx.ImageHandler.txt

package info (click to toggle)
wxpython4.0 4.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 211,112 kB
  • sloc: cpp: 888,355; python: 223,130; makefile: 52,087; ansic: 45,780; sh: 3,012; xml: 1,534; perl: 264
file content (619 lines) | stat: -rw-r--r-- 14,891 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2018 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.ImageHandler:

==========================================================================================================================================
|phoenix_title|  **wx.ImageHandler**
==========================================================================================================================================

This is the base class for implementing image file loading/saving, and image creation from data.          

It is used within :ref:`wx.Image`  and is not normally seen by the application. 

If you wish to extend the capabilities of :ref:`wx.Image`, derive a class from :ref:`wx.ImageHandler`  and add the handler using :meth:`wx.Image.AddHandler`   in your application initialization. 

Note that all ImageHandlers provided by wxWidgets are part of the :ref:`Core`  library. For details about the default handlers, please see the section :ref:`Available image handlers <wx.Image>`  in the :ref:`wx.Image`  class documentation. 



|phoenix_title| Note (Legal Issue)
==================================

This software is based in part on the work of the Independent ``JPEG`` Group. (Applies when wxWidgets is linked with ``JPEG`` support. :ref:`wx.JPEGHandler`  uses libjpeg created by ``IJG``.)   



.. seealso:: :ref:`wx.Image`, :ref:`wx.InitAllImageHandlers`    







|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>ImageHandler</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.ImageHandler_inheritance.png" alt="Inheritance diagram of ImageHandler" usemap="#dummy" class="inheritance"/></center>
   </div>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.Object.html" title="wx.Object" alt="" coords="29,5,111,35"/> <area shape="rect" id="node2" href="wx.ImageHandler.html" title="wx.ImageHandler" alt="" coords="5,83,136,112"/> </map> 
   </p>

|


|sub_classes| Known Subclasses
==============================

:ref:`wx.GIFHandler`, :ref:`wx.IFFHandler`, :ref:`wx.JPEGHandler`, :ref:`wx.PCXHandler`, :ref:`wx.PNGHandler`, :ref:`wx.PNMHandler`, :ref:`wx.TGAHandler`, :ref:`wx.TIFFHandler`, :ref:`wx.XPMHandler`

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.ImageHandler.__init__`                                                Default constructor.
:meth:`~wx.ImageHandler.CanRead`                                                 Returns ``True`` if this handler supports the image format contained in the given stream.
:meth:`~wx.ImageHandler.DoCanRead`                                               Called to test if this handler can read an image from the given stream.
:meth:`~wx.ImageHandler.DoGetImageCount`                                         Called to get the number of images available in a multi-image file type, if supported.
:meth:`~wx.ImageHandler.GetAltExtensions`                                        Returns the other file extensions associated with this handler.
:meth:`~wx.ImageHandler.GetExtension`                                            Gets the preferred file extension associated with this handler.
:meth:`~wx.ImageHandler.GetImageCount`                                           If the image file contains more than one image and the image handler is capable of retrieving these individually, this function will return the number of available images.
:meth:`~wx.ImageHandler.GetMimeType`                                             Gets the MIME type associated with this handler.
:meth:`~wx.ImageHandler.GetName`                                                 Gets the name of this handler.
:meth:`~wx.ImageHandler.GetType`                                                 Gets the image type associated with this handler.
:meth:`~wx.ImageHandler.LoadFile`                                                Loads a image from a stream, putting the resulting data into `image`.
:meth:`~wx.ImageHandler.SaveFile`                                                Saves a image in the output stream.
:meth:`~wx.ImageHandler.SetAltExtensions`                                        Sets the alternative file extensions associated with this handler.
:meth:`~wx.ImageHandler.SetExtension`                                            Sets the preferred file extension associated with this handler.
:meth:`~wx.ImageHandler.SetMimeType`                                             Sets the handler MIME type.
:meth:`~wx.ImageHandler.SetName`                                                 Sets the handler name.
:meth:`~wx.ImageHandler.SetType`                                                 Sets the bitmap type for the handler.
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.ImageHandler.AltExtensions`                                           See :meth:`~wx.ImageHandler.GetAltExtensions` and :meth:`~wx.ImageHandler.SetAltExtensions`
:attr:`~wx.ImageHandler.Extension`                                               See :meth:`~wx.ImageHandler.GetExtension` and :meth:`~wx.ImageHandler.SetExtension`
:attr:`~wx.ImageHandler.MimeType`                                                See :meth:`~wx.ImageHandler.GetMimeType` and :meth:`~wx.ImageHandler.SetMimeType`
:attr:`~wx.ImageHandler.Name`                                                    See :meth:`~wx.ImageHandler.GetName` and :meth:`~wx.ImageHandler.SetName`
:attr:`~wx.ImageHandler.Type`                                                    See :meth:`~wx.ImageHandler.GetType` and :meth:`~wx.ImageHandler.SetType`
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.ImageHandler(Object)

   **Possible constructors**::

       ImageHandler()
       
   
   This is the base class for implementing image file loading/saving, and
   image creation from data.



   .. method:: __init__(self)

      Default constructor.                  

      In your own default constructor, initialise the members m_name, m_extension and m_type.                   





   .. method:: CanRead(self, *args, **kw)



      |overload| Overloaded Implementations:

      **~~~**

      
      **CanRead** `(self, stream)`
      
      Returns ``True`` if this handler supports the image format contained in the given stream.                  
      
      This function doesn't modify the current stream position (because it restores the original position before returning; this however requires the stream to be seekable; see :meth:`wx.StreamBase.IsSeekable` ).                  
      
      
      :param `stream`: 
      :type `stream`: wx.InputStream
      
      
      
      
      :rtype: `bool`
      
      
      
      
      
      
      
      **~~~**

      
      **CanRead** `(self, filename)`
      
      Returns ``True`` if this handler supports the image format contained in the file with the given name.                  
      
      This function doesn't modify the current stream position (because it restores the original position before returning; this however requires the stream to be seekable; see :meth:`wx.StreamBase.IsSeekable` ).                  
      
      
      :param `filename`: 
      :type `filename`: string
      
      
      
      
      :rtype: `bool`
      
      
      
      
      
      
      
      **~~~**






   .. method:: DoCanRead(self, stream)

      Called to test if this handler can read an image from the given stream.                  

      ``NOTE``: this function is allowed to change the current stream position since CallDoCanRead() will take care of restoring it later                  


      :param `stream`: 
      :type `stream`: wx.InputStream




      :rtype: `bool`








   .. method:: DoGetImageCount(self, stream)

      Called to get the number of images available in a multi-image file type, if supported.                  

      ``NOTE``: this function is allowed to change the current stream position since :meth:`GetImageCount`   will take care of restoring it later                  


      :param `stream`: 
      :type `stream`: wx.InputStream




      :rtype: `int`








   .. method:: GetAltExtensions(self)

      Returns the other file extensions associated with this handler.                  

      The preferred extension for this handler is returned by :meth:`GetExtension` . 

                

      :rtype: `list of strings`







      .. versionadded:: 2.9.0 
     








   .. method:: GetExtension(self)

      Gets the preferred file extension associated with this handler.                  

                

      :rtype: `string`







      .. seealso:: :meth:`GetAltExtensions`     








   .. method:: GetImageCount(self, stream)

      If the image file contains more than one image and the image handler is capable of retrieving these individually, this function will return the number of available images.                  




      :param `stream`: Opened input stream for reading image data. This function doesn't modify the current stream position (because it restores the original position before returning; this however requires the stream to be seekable; see :meth:`wx.StreamBase.IsSeekable` ).  
      :type `stream`: wx.InputStream






      :rtype: `int`



                  



      :returns: 

         Number of available images. For most image handlers, this is 1 (exceptions are ``TIFF`` and ``ICO`` formats as well as animated GIFs for which this function returns the number of frames in the animation).   








   .. method:: GetMimeType(self)

      Gets the MIME type associated with this handler.                  

      :rtype: `string`








   .. method:: GetName(self)

      Gets the name of this handler.                  

      :rtype: `string`








   .. method:: GetType(self)

      Gets the image type associated with this handler.                  

      :rtype: :ref:`wx.BitmapType`








   .. method:: LoadFile(self, image, stream, verbose=True, index=-1)

      Loads a image from a stream, putting the resulting data into `image`.                  

      If the image file contains more than one image and the image handler is capable of retrieving these individually, `index`  indicates which image to read from the stream. 




      :param `image`: The image object which is to be affected by this operation.   
      :type `image`: wx.Image
      :param `stream`: Opened input stream for reading image data.   
      :type `stream`: wx.InputStream
      :param `verbose`: If set to ``True``, errors reported by the image handler will produce LogMessages.   
      :type `verbose`: bool
      :param `index`: The index of the image in the file (starting from zero).  
      :type `index`: int












      :rtype: `bool`



                  



      :returns: 

         ``True`` if the operation succeeded, ``False`` otherwise.  







      .. seealso:: :meth:`wx.Image.LoadFile` , :meth:`wx.Image.SaveFile` , :meth:`SaveFile`     








   .. method:: SaveFile(self, image, stream, verbose=True)

      Saves a image in the output stream.                  




      :param `image`: The image object which is to be affected by this operation.   
      :type `image`: wx.Image
      :param `stream`: Opened output stream for writing the data.   
      :type `stream`: wx.OutputStream
      :param `verbose`: If set to ``True``, errors reported by the image handler will produce LogMessages.  
      :type `verbose`: bool










      :rtype: `bool`



                  



      :returns: 

         ``True`` if the operation succeeded, ``False`` otherwise.  







      .. seealso:: :meth:`wx.Image.LoadFile` , :meth:`wx.Image.SaveFile` , :meth:`LoadFile`     








   .. method:: SetAltExtensions(self, extensions)

      Sets the alternative file extensions associated with this handler.                  




      :param `extensions`: Array of file extensions.  
      :type `extensions`: list of strings




                  



      .. versionadded:: 2.9.0 
     







      .. seealso:: :meth:`SetExtension`   








   .. method:: SetExtension(self, extension)

      Sets the preferred file extension associated with this handler.                  




      :param `extension`: File extension without leading dot.  
      :type `extension`: string




                  



      .. seealso:: :meth:`SetAltExtensions`     








   .. method:: SetMimeType(self, mimetype)

      Sets the handler MIME type.                  




      :param `mimetype`: Handler MIME type.   
      :type `mimetype`: string




                  





   .. method:: SetName(self, name)

      Sets the handler name.                  




      :param `name`: Handler name.   
      :type `name`: string




                  





   .. method:: SetType(self, type)

      Sets the bitmap type for the handler.                  




      :param `type`: 
      :type `type`: wx.BitmapType




      The bitmap type.  

                  





   .. attribute:: AltExtensions

      See :meth:`~wx.ImageHandler.GetAltExtensions` and :meth:`~wx.ImageHandler.SetAltExtensions`


   .. attribute:: Extension

      See :meth:`~wx.ImageHandler.GetExtension` and :meth:`~wx.ImageHandler.SetExtension`


   .. attribute:: MimeType

      See :meth:`~wx.ImageHandler.GetMimeType` and :meth:`~wx.ImageHandler.SetMimeType`


   .. attribute:: Name

      See :meth:`~wx.ImageHandler.GetName` and :meth:`~wx.ImageHandler.SetName`


   .. attribute:: Type

      See :meth:`~wx.ImageHandler.GetType` and :meth:`~wx.ImageHandler.SetType`