Transparency

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Transparency

Post by PepsiHog » Tue Nov 25, 2014 1:28 pm

Is there a way to have more than one transparent color within one image? I am working on a project that I want to eliminate colors from a picture. It's not for the purpose of editing. It's a filter for a so-called security macro I am working on creating. I tried making more than one color transparent but was unsuccessful.

Any clever ideas on how one may be able to accomplish this by manipulation?

Thanks,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Transparency

Post by JRL » Tue Nov 25, 2014 1:44 pm

Though you can only have one transparent color at a time, one way to get multiple transparent colors is to use two dialogs. Set the dialog with the image in front and the second dialog of the same size to the rear. Make the first color transparent in the image containing dialog and make the background dialog the color you want to make transparent next. Take a screen shot of the image then replace the image in the dialog with the screen shot. When you then make the second color your transparent color in the image dialog you have made two colors transparent. And of course this can go on to a third, fourth, etc colors.

If your image is larger than the desktop you'll have to break it up and work on it in segments then reassemble the image segments.

I know this will work because I wrote a script to do it five or six years ago. I could find it and dust it off but it was pre v12 so I'd probably start over on it anyway.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Transparency

Post by JRL » Tue Nov 25, 2014 6:52 pm

Spent my lunch break creating a sample similar to what I was talking about. This script cycles through using the same background color over and over. To use this you will select a jpg, png or bmp image file. The file should be no larger than your display. When the image shows on your screen you can pick on it and all pixels in the image that match the color of the pixel you select will turn red. You can select as many times as you want. When you quit, the image final condition is saved on your desktop and is named "Transparentpixelstempfile.bmp"

Don't move the dialogs or things will not work properly
Press Esc or close dialog1 to quit the script.

In any case this should give you an idea about how one might accomplish multiple transparent colors in an image.

Code: Select all

OnEvent>Key_down,VK27,0,Quit

SRT>Quit
  Exit>0
END>Quit

//Select file to work with.
Input>vImageFile,Image to work with


Dialog>Dialog1
object Dialog1: TForm
  AutoSize = True
  Caption = 'Image'
  ClientHeight = 300
  ClientWidth = 400

  Position = poScreenCenter
  Color = 255
  object MSImage1: tMSImage
    Left = 0
    Top = 0
    Width = 300
    Height = 400
    AutoSize = True
  end
end
EndDialog>Dialog1

Dialog>Dialog2
object Dialog2: TForm
  Caption = 'BackGround'
  Color = 255
end
EndDialog>Dialog2


AddDialogHandler>Dialog1,MSImage1,OnClick,Process
SetDialogProperty>Dialog1,MSImage1,LoadImage,vImageFile

//Only works with BMP files so if not a BMP we need to convert to a BMP
Show>Dialog1
  
Dialog>TitleBarSizeCalculation
  Button=1,0,0,0,0,0
EndDialog>TitleBarSizeCalculation
  GoSub>Setup
  CloseDialog>Dialog1


//Make Dialog2 the same size and location as Dialog1
Let>WIN_USEHANDLE=1
  MoveWindow>Dialog2.handle,Dia1X,Dia1Y
  ResizeWindow>Dialog2.handle,Dia1W,Dia1H
Let>WIN_USEHANDLE=0

Show>Dialog2
Show>Dialog1,

SRT>MoveDialog2
  Let>WIN_USEHANDLE=1
    GetWindowPos>Dialog1.handle,Dia1X,Dia1Y
    MoveWindow>Dialog2.handle,Dia1X,Dia1Y
  Let>WIN_USEHANDLE=0
  GoSub>Setup
END>MoveDialog2

SRT>Process
  GetCursorPos>CurX,CurY
  GetPixelColor>CurX,CurY,vPixelColor
  SetDialogProperty>Dialog1,,TransparentColor,True
  SetDialogProperty>Dialog1,,TransparentColorValue,vPixelColor
  ScreenCapture>ImageX,ImageY,ImageR,ImageB,%desktop_dir%\Transparentpixelstempfile.bmp
  Let>vImageFile=%desktop_dir%\Transparentpixelstempfile.bmp
  SetDialogProperty>Dialog1,MSImage1,LoadImage,vImageFile
  SetDialogProperty>Dialog1,,TransparentColor,False
END>Process


SRT>Setup
  Let>WIN_USEHANDLE=1
  MoveWindow>TitleBarSizeCalculation.handle,0,0
  GetWindowPos>TitleBarSizeCalculation.msButton1.handle,OffSetX,OffSetY
  GetWindowPos>Dialog1.handle,Dia1X,Dia1Y
  GetWindowSize>Dialog1.handle,Dia1W,Dia1H
Let>WIN_USEHANDLE=0
  Let>ImageX=%Dia1X%+%OffsetX%
  Let>ImageY=%Dia1Y%+%OffsetY%
  Let>ImageR={%ImageX%+%Dia1W%-%OffSetX%-%OffSetX%}
  Let>ImageB={%ImageY%+%Dia1H%-%OffSetX%-%OffSetY%}
  ScreenCapture>ImageX,ImageY,ImageR,ImageB,%desktop_dir%\Transparentpixelstempfile.bmp
  Let>vImageFile=%desktop_dir%\Transparentpixelstempfile.bmp
  SetDialogProperty>Dialog1,MSImage1,LoadImage,vImageFile
END>Setup

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts