PASTE LOGO INTO IMAGE . . .
2021-01-15-175941
All --
I am working on an APP for a customer that would like to paste their LOGO into the LOWER LEFT CORNER of each image.
They have a couple of versions of their logo but they would like to use a version that has a TRANSPARENT BACKGROUND so the CAMERA IMAGE shows in the space around the LOGO.
So . . .
The image below is a mock up of what I am working to accomplish. LOGO 1 (Left) and LOGO 2 (Center) are PNG IMAGES with the BACKGROUND set up to be transparent. LOGO 3 (Right) is a JPG IMAGE with GREEN as the background and SHADOW generated by the APP that I used to make the MOCK UP.
I thought the ANNOTATION TOOL might give me the functions to overlay a LOGO like this onto the image but the UI does not show an ANNOTATE WITH IMAGE TOOL.
My efforts to handle the PNG IMAGES with IMAGE PRO and get them into the image in the manner shown have failed. Putting the PNG IMAGE on the WINDOWS CLIPBOARD and pasting it into the image does not work either.
Is there IP10 CODE which will allow an IP10 APP to "stamp" a logo like LOGO 1 or LOGO 2 onto an image with TRANSPARENCY? If not, is there CODE which will allow me to "stamp" a LOGO like LOGO 3 into an image without opening the LOGO IMAGE and doing a COPY in IP10?
I have attached the PNG FILES and JPG FILE for the three LOGOs to help you help me.
Thanks in advance.
-- Matt
0
Best Answers
-
2021-01-16-150933Yuri --Thank you very much.That looks perfect.I think this will be a home run!Thanks again.-- Matt
0 -
Hi Matt,
Yes, the project requires a reference to MediaCy.Controls.Common.Vb.dll, which you added by importing dependencies.
The function McImageFromBitmap creates a new image, so just assigning it to im variable, will not modify the original image, you would need to merge the new image with the old. It could be done by a Copy operation.
Here is a new macro with 2 versions (Duplicate and Overwrite). Note that BitmapFromMcImage uses current image LUT creating Bitmap, so if you want to preserve pixel values, the LUT must be reset, which is done in the macro.Imports MediaCy.Controls.Common.Vb Public Module Module1 'Add logo to the active image and show it in a new workspace Public Sub AddLogoToActiveImageDuplicate Dim im As McImage=ThisApplication.ActiveImage AddLogoToImage(im,False) End Sub 'Add logo to the active image and overwrite the existing image Public Sub AddLogoToActiveImageOverwrite() Dim im As McImage=ThisApplication.ActiveImage AddLogoToImage(im,True) End Sub Private Sub AddLogoToImage(im As McImage, bOverwrite As Boolean) If im Is Nothing Then Exit Sub'no image If bOverwrite Then 'reset LUT as BitmapFromMcImage uses active LUT im.LookupTables.Reset End If 'define logo file name Dim logoName As String="D:\Logo.png" 'define logo size Dim logoSize As New System.Drawing.Size(128,128) Dim bmLogo As New System.Drawing.Bitmap(logoName) Dim imbm As System.Drawing.Bitmap=MediaCy.Controls.Common.Vb.McImageUtils.BitmapFromMcImage(im) Dim gr As System.Drawing.Graphics= System.Drawing.Graphics.FromImage(imbm) gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic 'draw logo to the bottom left corner with logoSize gr.DrawImage(bmLogo,0,imbm.Height-logoSize.Height,logoSize.Width,logoSize.Height) gr.Dispose() Dim im2 As McImage=MediaCy.Controls.Common.Vb.McImageUtils.McImageFromBitmap(imbm) If bOverwrite Then 'copy new image to the original im.Op.Copy(im2)'copy Else 'show the new image im2.Name=im.Name & "_Logo" im2.Visible=True End If End Sub End Module
Yuri0
Answers
Image-Pro doesn't handle transparency layer, so the easiest way would be to use System,Drawing tools.
Here is the macro, which will add logo with transparency to the bottom-left corner of the active image:
Imports MediaCy.Controls.Common.Vb Public Module Module1 Public Sub AddLogoToActiveImage Dim im As McImage=ThisApplication.ActiveImage If im Is Nothing Then Exit Sub'no image 'define logo file name Dim logoName As String="D:\Logo.png" 'define logo size Dim logoSize As New System.Drawing.Size(128,128) Dim bmLogo As New System.Drawing.Bitmap(logoName) Dim imbm As System.Drawing.Bitmap=MediaCy.Controls.Common.Vb.McImageUtils.BitmapFromMcImage(im) Dim gr As System.Drawing.Graphics= System.Drawing.Graphics.FromImage(imbm) gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic 'draw logo to the bottom left corner with logoSize gr.DrawImage(bmLogo,0,imbm.Height-logoSize.Height,logoSize.Width,logoSize.Height) gr.Dispose() Dim im2 As McImage=MediaCy.Controls.Common.Vb.McImageUtils.McImageFromBitmap(imbm) im2.Name=im.Name & "_Logo" im2.Visible=True End Sub End Module
The result will look like this:I've also attached the project.
Yuri
to the APP CODE in my PROJECT and added
I did an