Reputation: 349
I am adding two different images on win2d canvas in different points and different size and run application display two images perfect points set to display. Then how I am select image and move on canvas.
Upvotes: 2
Views: 617
Reputation: 8161
Win2D is an immediate mode graphics library (from Wikipedia)
Immediate mode rendering is a style for application programming interfaces of graphics libraries, in which client calls directly cause rendering of graphics objects to the display. It does not preclude the use of double-buffering. In contrast to retained mode, lists of objects to be rendered are not saved by the API library. Instead, the application must re-issue all drawing commands required to describe the entire scene each time a new frame is required, regardless of actual changes. This method provides the maximum amount of control and flexibility to the application program.
So it's up to you to keep the reference of any object you want to modify, because once it's drawn it is lost.
So define your CanvasBitmap
as a global resource or create some type of ResourceLocator. Then create a your own class that stores x,y,width,height kinda like a custom object;
public class GenericItem
{
public CanvasBitmap b;
public int x;
public int y;
public int w;
public int h;
}
Modified Example from Win2D:
CanvasBitmap cat, mouse;
GenericItem gi_cat;
load your bitmaps in:
async Task CreateResourcesAsync(CanvasControl sender)
{
cat = await CanvasBitmap.LoadAsync(sender, "ShawnsCat.jpg");
mouse = await CanvasBitmap.LoadAsync(sender, "Mouse.png");
// create your GenericItem here
gi_cat = new GenericItem();
// fill in your x,y,width,height,bitmap
}
now draw
void myWidget_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
args.DrawingSession.DrawImage(gi_cat.b, gi_cat.x, gi_cat.y);
}
now you can modify gi_cat.x gi_cat.y and whatever property you added.
gi_cat.x = 500;
gi_cat.y = 250;
and you can cause a redraw calling the Invalidate Method on the canvas control.
name_of_your_canvas.Invalidate();
which will cause the canvas control to redraw with the new position.
Basically you have to handle everything yourself. If you looking for a DOM like approach then just use the regular Canvas
control available in XAML.
I have a pretty in depth Win2D Walkthrough here :
Win2D Getting Started: Windows Universal Application
Upvotes: 3