开发者

How to display images on top of each other using C# (Forms or WPF)?

开发者 https://www.devze.com 2023-03-21 03:43 出处:网络
I need to display images on top of each other. This can either be a composite\\layered image or separate images.This will typically be a larger image with smaller images on top. With the composite\\la

I need to display images on top of each other. This can either be a composite\layered image or separate images. This will typically be a larger image with smaller images on top. With the composite\layered approach the smaller images would each need to be a separate (and accessible) layer. With the separate images app开发者_开发知识库roach the smaller images are on top with a transparent background. With either approach the smaller images must be accessible i.e. can be moved (dragged) or deleted. The app needs to display these images together (as if it was one image) and keep track of the coordinates (position) of the smaller images.

The current (proof-of-concept) solution has a PictureBox control that displays the large image and a treeview. Nodes are dragged from the treeview to the picture box and rendered using the graphics DrawString or DrawImage methods – these draw the smaller images. The problem is that once the smaller image is drawn I cannot get back to it as a separate graphics object. The picture box “sees” it as part of the current image.

I need to do this in C# (WinForms or WPF). And the image type must be a common and open format i.e. not proprietary. Preferably no 3rd party controls.

Any suggestions\guidance?


WPF would be the technology of my choice for this project.

  • Drag & Drop way nicer, without flickering, better concept
  • Rendering directly on HW, way smoother for image manipulation

General idea of the implementation:

  • MVVM pattern
  • ViewModel holding your layer information
  • ItemsControl bound to the collection of Small overlay Images holding a DataTemplate which visualizes the images thour custom UserControl based on a Thumb (for drag & drop functionality) displayes the small images on top.

Easy to add functionality to drag, edit, hide each small image seperately.


The problem is that once the smaller image is drawn I cannot get back to it as a separate graphics object. The picture box “sees” it as part of the current image.

That behaviour is perfectly normal. GDI drawing does not work with objects. To do what you are asking, you need to track any event that can cause a change in the final image and when such an event occur, you need to draw the whole image from the begining, including the first image (assigning the background image, I guess).


May be create picture box per image. The transparent background will give the effect of single image.

0

精彩评论

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