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
-
Hi Matt,
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
0 -
2021-01-17-174239Yuri --I have bumped into a problem with your solution.I downloaded the IPX FILE and loaded the PROJECT into IP10.I created a FILE at
\Logo.png
and everything worked fine withSub AddLogoToActiveImagewhen it was insideLogoToImage.ippI copiedSub AddLogoToActiveImage
to the APP CODE in my PROJECT and addedImports MediaCy.Controls.Common.vbto the APP CODE.When I attempt to LOAD my PROJECT, the following is displayed.It seems there is issue withDim imbm As System.Drawing.Bitmap=MediaCy.Controls.Common.Vb.McImageUtils.BitmapFromMcImage(im)as my PROJECT is configured.Update . . .
I did anEXPORT DEPENDENCIESonLogoToImage.ippand then did anIMPORT DEPENDENCIESon my PROJECTMy PROJECT now loads properly.It seems that addingImports MediaCy.Controls.Common.vbto the APP CODE was not adequate.It looks like doing aSCRIPT + PROJECT + REFERENCES with the following checked is also required.Is this correct?Also . . .I would like the LOGO to appear in the ORIGINAL IMAGE.I attempted to modify your code to make this happen but my results were not what I need.My attempt and the results are below.The lineim = MediaCy.Controls.Common.Vb.McImageUtils.McImageFromBitmap(imbm)
did not generate any errors but the LOGO did not appear in the ORIGINAL IMAGE WINDOW.I looked for something likeim.refreshto update the window but I did not see anything.I put in theim.Visible = Trueto see if that would get the results that I was seeking. You see that the results is another IMAGE WINDOWCan the CODE transfer the BITMAP that is held in IMBM with the CAMERA IMAGE + LOGO IMAGE back into the ORIGINAL IMAGE?Thanks.-- Matt-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Public Sub AddLogoToActiveImage2 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 im = MediaCy.Controls.Common.Vb.McImageUtils.McImageFromBitmap(imbm) im.Visible = True End Sub
0 -
2021-01-18-095848Yuri --Thank you very much for this additional CODE.I got to thinking about this last night and I thought perhaps I should have triedThisApplication.ActiveImage = MediaCy.Controls.Common.Vb.McImageUtils.McImageFromBitmap(imbm)rather thanim = MediaCy.Controls.Common.Vb.McImageUtils.McImageFromBitmap(imbm)because changing IM does not automatically change THISAPPLICATION.ACTIVEIMAGEI will add your CODE to the APP shortly and I am confident this will generate the results we need.I assume that since all of the variables that are used are LOCAL that no special action needs to be taken to dispose of them to avoid MEMORY ISSUES.Thanks again.-- Matt
0 -
2021-01-18-123122Yuri (and All) --I took Yuri's CODE and modified it a bit. See below.With this code, when AA.JPG is open and
Public Sub AddLogoToActiveImageDuplicate AddLogoToImage(.25, .5, False) End Sub
is run, the result isWith this code, when AA.JPG is open and'Add logo to the active image and overwrite the existing image Public Sub AddLogoToActiveImageOverwrite() AddLogoToImage(.5, .25, True) End Sub
is run, the result isYuri, thank you for providing the guidance I needed to add this feature to the APP for this project.-- Matt-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'Add logo to the active image and show it in a new workspace Public Sub AddLogoToActiveImageDuplicate AddLogoToImage(.25, .5, False) End Sub 'Add logo to the active image and overwrite the existing image Public Sub AddLogoToActiveImageOverwrite() AddLogoToImage(.5, .25, True) End Sub Private Sub AddLogoToImage(MySizeFactor As Single, MyMarginFactor As Single, bOverwrite As Boolean) 'This is a modified version of the AddLogoToImage created by YuriG and posted 'on the MEDIA CY FORUM in DISCUSSION 1130 with subject PASTE LOGO INTO IMAGE 'CONNECT WITH THE ACTIVE IMAGE Dim im As McImage = _ ThisApplication.ActiveImage 'ERROR TRAP FOR NO IMAGE If im Is Nothing _ Then Exit Sub End If 'ACTION FOR OVERWRITE VS DUPLICATE If bOverwrite _ Then 'RESET LUT BECAUSE THE BITMAP FROM MCIMAGE FUNCTION USES THE ACTIVE LUT im.LookupTables.Reset Else 'DO NOTHING DoEvents End If 'SET THE LOGO FILE NAME Dim logoName As String= _ "D:\Logo.png" 'CREATE A BITMAP OF THE LOGO IMAGE IN RAM Dim bmLogo As New System.Drawing.Bitmap(logoName) 'DETERMINE THE LOGO IMAGE DIMENSIONS Dim MyLogoWidth As Integer = _ bmLogo.Width Dim MyLogoHeight As Integer = _ bmLogo.Height '-- DETERMINE THE STAMP SIZE FROM THE LOGO SIZE, THE SIZE FACTOR, AND THE IMAGE SIZE 'DETERMINE THE STAMP WIDTH FROM THE SIZE FACTOR AND THE IMAGE SIZE Dim MyStampWidth As Single = _ ThisApplication.ActiveImage.Width * MySizeFactor 'DETERMINE THE STAMP HEIGHT FROM THE STAMP WIDTH AND THE LOGO SIZE Dim MyStampHeight As Single = _ MyStampWidth * (MyLogoHeight / MyLogoWidth) 'SET UP THE STAMP SIZE VARIABLE Dim StampSize As New System.Drawing.Size _ ( _ MyStampWidth, _ MyStampHeight _ ) 'SET UP THE DISTANCE FOR THE STAMP FROM THE LOWER LEFT CORNER OF THE IMAGE Dim StampMargin As New System.Drawing.Size _ ( _ MyMarginFactor * ThisApplication.ActiveImage.Width, _ MyMarginFactor * ThisApplication.ActiveImage.Height _ ) 'CREATE A WORKING BITMAP OF THE ORIGINAL IMAGE IN RAM Dim imbm As System.Drawing.Bitmap = _ MediaCy.Controls.Common.Vb.McImageUtils.BitmapFromMcImage(im) 'CONNECT THE GRAPHICS ENGINE TO THE WORKING BITMAP Dim gr As System.Drawing.Graphics = _ System.Drawing.Graphics.FromImage(imbm) 'CONFIGURE THE SMOOTHING MODE FOR THE GRAPHICS ENGINE gr.SmoothingMode = _ System.Drawing.Drawing2D.SmoothingMode.HighQuality 'CONFIGURE THE INITERPOLATION MODE FOR THE GRAPHICS ENGINE gr.InterpolationMode = _ System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic 'DRAW THE LOGO INTO THE LOWER LEFT CORNER OF THE WORKING BITMAP USING THE STAMP DIMENSIONS gr.DrawImage _ ( _ bmLogo, _ 0 + StampMargin.Width , _ imbm.Height - StampMargin.Height - StampSize.Height, _ StampSize.Width, _ StampSize.Height _ ) 'DISPOSE OF THE CONNECTION WITH THE GRAPHICS ENGINE gr.Dispose() 'CREATE AN MCIMAGE LINK TO THE WORKING BITMAP Dim im2 As McImage = _ MediaCy.Controls.Common.Vb.McImageUtils.McImageFromBitmap(imbm) 'IF THE OVERWRITE OPTION IS ON 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
0
Categories
- All Categories
- 961 Image-Pro v9 and higher
- 9 Image-Pro FAQs
- 18 Image-Pro Download & Install
- 448 Image-Pro General Discussions
- 486 Image-Pro Automation (Macros, Apps, Reports)
- 20 AutoQuant Deconvolution
- 2 AutoQuant Download & Install
- 18 AutoQuant General Discussions
- 195 Image-Pro Plus v7 and lower
- 3 Image-Pro Plus Download & Install
- 106 Image-Pro Plus General Discussions
- 86 Image-Pro Plus Automation with Macros
- 19 Legacy Products
- 16 Image-Pro Premier 3D General Discussions
- 26 Image-Pro Insight General Discussions