Skip to content

Display custom type with PNG support #307

@jwortmann

Description

@jwortmann

How can I use imshow to display an image of my custom type which has support for the image/png MIME type via Base.show?

Is it not supported, or is imshow not the appropriate function for this? Or does ImageView support some kind of AbstractDisplay, so that I could write display(ImageViewDisplay, Foo())?

Minimum non-working example:

julia> using ImageView, PNGFiles, TestImages

julia> struct Foo end

julia> Base.show(io::IO, ::MIME"image/png", x::Foo) = PNGFiles.save(io, testimage("mandrill"))

julia> imshow(Foo())
ERROR: MethodError: no method matching size(::Foo)

Closest candidates are:
  size(::Core.Compiler.StmtRange)
   @ Base show.jl:2774
  size(::Base.ExceptionStack)
   @ Base errorshow.jl:1018
  size(::Base.AsyncGenerator)
   @ Base asyncmap.jl:389
  ...

Stacktrace:
 [1] axes(A::Foo)
   @ Base .\abstractarray.jl:98
 [2] roi(A::Foo, dims::Tuple{Int64, Int64})
   @ ImageView C:\Users\jwortmann\.julia\packages\ImageView\Gg1GW\src\slicing.jl:45
 [3] imshow(img::Any; axes::Any, name::Any, aspect::Any)
   @ ImageView C:\Users\jwortmann\.julia\packages\ImageView\Gg1GW\src\ImageView.jl:277
 [4] imshow(img::Any)
   @ ImageView C:\Users\jwortmann\.julia\packages\ImageView\Gg1GW\src\ImageView.jl:274
 [5] top-level scope
   @ REPL[13]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions