Markwon icon indicating copy to clipboard operation
Markwon copied to clipboard

change Img size

Open sunleidehao opened this issue 4 years ago • 6 comments

  • Markwon version: {4.6.2}

When the label has no width information, I want to specify the width of the image to fill the whole screen. What should I do? thank you just like this <p><img src="https://xjej-1256912561.cos.ap-chengdu.myqcloud.com/xinfal200514133952902.png" /></p>

sunleidehao avatar Dec 06 '21 10:12 sunleidehao

Hello @sunleidehao ,

you can take look at the FitWidthImageSizeResolverSample sample that achieves this with a custom ImageSizeResolver

noties avatar Dec 06 '21 11:12 noties

Hello @noties Where is the FitWidthImageSizeResolverSample?

hijunmeng avatar Dec 09 '21 12:12 hijunmeng

Hello @hijunmeng ,

this is a file in this repository, you can search for it

noties avatar Dec 09 '21 22:12 noties

hello @noties I tried, but I couldn't find anything.

hijunmeng avatar Dec 10 '21 03:12 hijunmeng

Hello @hijunmeng ,

sorry, it is not pushed yet 😅

class FitWidthImageSizeResolverSample : MarkwonTextViewSample() {
  override fun render() {
    val md = """
      # Fit Width Image
      
      ![wiki](https://en.wikipedia.org/static/images/project-logos/enwiki-2x.png)
      
      And some text after and then an inline image that takes full width again: ![wiki](https://en.wikipedia.org/static/images/project-logos/enwiki-2x.png)
    """.trimIndent()

    val markwon = Markwon.builder(context)
      .usePlugin(object : AbstractMarkwonPlugin() {
        override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
          builder.imageSizeResolver(FitWidthImageSizeResolver())
        }
      })
      .usePlugin(ImagesPlugin.create())
      .build()

    markwon.setMarkdown(textView, md)
  }

  private class FitWidthImageSizeResolver : ImageSizeResolverDef() {
    override fun resolveImageSize(drawable: AsyncDrawable): Rect {
      return resolveImageSize(
        ImageSize(
          ImageSize.Dimension(100F, UNIT_PERCENT),
          null
        ),
        // important detail - `drawable.result` bounds must be used
        drawable.result.bounds,
        drawable.lastKnownCanvasWidth,
        drawable.lastKnowTextSize
      )
    }
  }
}

noties avatar Dec 10 '21 10:12 noties

Can you send me an example written in Java : FitWidthImageSizeResolver
Thank you very much

sunleidehao avatar Dec 29 '21 08:12 sunleidehao

Image size remains same in lists also. How can I consider the indent set by list in image width ?

damionx7 avatar Aug 04 '23 14:08 damionx7