开发者

Add draggable shape on a picture in Android

Can anyone explain how can I add shape (for example a rectangle or an arrow) on to a image (in ImageView)? Once added, the开发者_Go百科 shape will need to be draggable to anywhere in the image. And finally need to save the image edited (with the shape on top of that).


What informations do you really need?

This can be some steps to do:

Maybe create a new object to handle this:

  • Create a new class and extend from ImageView or use LayerDrawable for that.
  • Write setters/getters for the main-background-image/bitmap.
  • Add your own Vector shape (create a new class with definable color,thickness... or hard-code it)
  • Do all of your drawings in onDraw-Methods
  • Implement onTouch interfaces to handle your selection and dragging.
  • Create new method (render to jpeg/png/..) to save your resulting image


  • Create a Custom view from View that completely overlaps your ImageView. This view will have a transparent background and contain the draggging view. Initially set visibility to invisible.
  • In Custom view class override the onTouch event where you update the dragging views margins.
  • On save, get drawing cache of the parent layout(that contains both the ImageView and Custom view) and use as needed.

Sample xml code:

Relative layout parent whose drawing cache has to be grabbed using rel.getDrawingCache()

<RelativeLayout .......>
        <ImageView ......./>
        <CustomView ......./>
</RelativeLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜