-
Notifications
You must be signed in to change notification settings - Fork 45
Document image drawing in Kiva #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| Kiva Image Rendering | ||
| ==================== | ||
|
|
||
| Drawing images in kiva is accomplished via | ||
| :py:meth:`GraphicsContext.draw_image`. A unique feature of drawing images | ||
| (relative to path drawing) is that you can apply an arbitrary translation and | ||
| scaling to the image without involving the current transformation matrix. | ||
|
|
||
| The signature for :py:meth:`draw_image` is straightforward: | ||
|
|
||
| .. automethod:: kiva.abstract_graphics_context.AbstractGraphicsContext.draw_image | ||
| :noindex: | ||
|
|
||
| The ``image`` object that is passed to :py:meth:`draw_image` can be a numpy | ||
| array, a `PIL <https://pillow.readthedocs.io/en/stable/>`_ ``Image`` instance, | ||
| or another ``GraphicsContext`` instance of the same backend. If ``image`` is a | ||
| numpy array, it is typically converted to a more convenient format via | ||
| `PIL.Image.fromarray <https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.fromarray>`_. | ||
| Therefore, one must be careful about the expected pixel format of the image. If | ||
| your image is rendering with incorrect colors, this might be the problem. | ||
| Passing the other allowed versions of ``image`` should give a more consistent | ||
| result. | ||
|
|
||
| If ``image`` contains an alpha channel and transparent or translucent pixels, | ||
| this transparency should also be honored by the destination graphics context. | ||
| However, not all backends may support this. | ||
|
|
||
| Regarding the ``rect`` argument to :py:meth:`draw_image`, if it is not | ||
| specified then the bounding rectangle of the graphics context will be used. As | ||
| mentioned before, ``rect`` can be used to apply an arbitrary translation and | ||
| scaling to an image. The translation is the x,y position of the rectangle and | ||
| the scaling is the ratio of the image's width and height to those of the | ||
| rectangle. In every case, ``rect`` will be transformed by the current | ||
| transformation matrix. | ||
|
|
||
| Special considerations | ||
| ---------------------- | ||
| If you only want to draw a subset of an image, you should pass only that subset | ||
| to :py:meth:`draw_image`. The Kiva API does not support defining a "source" | ||
| rectangle when drawing images, only a "destination". | ||
|
|
||
| If drawing images with some scaling applied, one might wish to have control | ||
| over the interpolation used when drawing the image. This can be accomplished | ||
| with the :py:meth:`set_image_interpolation` method. | ||
|
|
||
| .. note:: | ||
| :py:meth:`set_image_interpolation` is currently only implemented by the | ||
| ``kiva.agg`` backend. Other backends may have the method, but it is | ||
| effectively a no-op. | ||
|
|
||
| Saving images | ||
| ------------- | ||
| One can also save the contents of a graphics context to an image. This is done | ||
| via the :py:meth:`save` method: | ||
|
|
||
| .. automethod:: kiva.abstract_graphics_context.AbstractGraphicsContext.save | ||
| :noindex: | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.