B4J Question [Solved] How to copy a part of a Canvas onto the same Canvas.

klaus

Expert
Licensed User
Longtime User
I want to copy a part of a Canvas to another place of the same Canvas.
In B4A I use Canvas.DrawBitmap(Canvas.Bitmap, SourceRectange, DestinationRectangle).
In B4J I have two problems:
- DrawImage has no source rectangle to get a part of the source image.
- Canvas has no Image propety, how can I get the image from the Canvas and better a part of it?

The question is related to to this thread.
I want to move the 59 lower rows one row up.
This is done, in B4A, with cvsGraph.DrawBitmap(cvsGraph.Bitmap, rectMoveSource, rectMoveDest).
 

Daestrum

Expert
Licensed User
Longtime User
Off the top of my head I guess you would need to
a) grab a snapshot of the canvas ( look at snapshotParameters setViewport not inbuilt snapshot)
b) write back to the canvas object (drawimage) allowing for the 1 line missing at bottom
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
this works fine...

just make sure it's added to the rootpanel or it won't work.

B4X:
Dim c As Canvas
Dim i As Image
i.Initialize(File.DirAssets,"image.png")
c.Initialize("")
Form1.RootPane.AddNode(c,0,0,100,100)
c.DrawImage(i,0,0,100,100)
c.DrawImage2(c.Snapshot,0,0,20,100,50,0,20,100)

copyToSameBitmap.png
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
Does this technique not degrade the details of the image, when used like this?
Having just read your earlier thread about aliaising, it is probably the DrawImage that may blur the result.

I am trying to do a similar thing with bar codes written to a canvas, and I am finding that some blurring is taking place when I re-write them with DrawImage.
 
Last edited:
Upvote 0
Top