Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have master 3d image and i want to set at run time another image as a label on master image. How can i do in WPF application. Please help me......
Posted

1 solution

From your question, let's assume that you have two images:

1. Please try this code

(1) One is master (baseImage )image
(2) The other one is, Label image (topImage)

First, please overlay the topImage on the baseImage. If you need to show both images, set the transparency to lower value. Then, display the image where do you want it to display(whether it is on WPF or WinForms apps). Please do this before displaying the image on the fly.


C#
public Image OverlayImage(Image baseImage, Image topImage, float transparency)
        {
            System.Drawing.Imaging.ImageAttributes ia = new     System.Drawing.Imaging.ImageAttributes();
            System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix();
            cm.Matrix33 = transparency;
            ia.SetColorMatrix(cm);
            Graphics g = null;
            try
            {
                g = Graphics.FromImage(baseImage);                              
                Rectangle rect = new Rectangle((int)(topImage.Width * 0.1), (int)(topImage.Height * 0.2), (int)(topImage.Width * 0.8), (int)(topImage.Height * 0.6));
                // YOU MAY DEFINE THE RECT AS THIS AS WELL
                //Rectangle rect = new Rectangle(0, 0, baseImage.Width,      baseImage.Height, baseImage.Width);
                g.DrawImage(topImage, rect, 0, 0, topImage.Width, topImage.Height, GraphicsUnit.Pixel, ia);
                return baseImage;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                g.Dispose();
                topImage.Dispose();
            }
          
        }


2. I only make the above code for Format32bppIndexed format. As we know there are many image formats. If you want to use third party, please try this. It has Overlay and watermark functionalities which suite for your questions as well:
http://www.artuxsoft.com/[^]
 
Share this answer
 
Comments
Sandeep Mewara 5-Jun-12 11:22am    
5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900