Results 1 to 9 of 9

Thread: How to make part of a bitmap transparent

  1. #1
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default How to make part of a bitmap transparent

    I have a bitmap of an item with a white background and i want it to be pasted onto something without showing a big white box around where i pasted it.
    I know you use SetTransparentColor(Bmp, 16777215); but it sets the color white (16777215) to black instead of making it transparent and showing what is behind the bitmap in the background.
    So now i have a big black box around it instead of white.
    So is there any way to make it sort of cut out the color white in the bitmap?
    There's no way all that SetTransparentColor does is change the specified color because there is already a procedure for that.

    Edit:
    I found out how to do it and came up with this procedure-
    SCAR Code:
    procedure DrawTransparent(x, y, Height, Width, Bmp: integer);
    var
      Bmp2: integer;
    begin
      Bmp2 := BitmapFromString(Width, Height, '');
      CopyClientToBitmap(Bmp2, x, y, x + Width, y + Height);
      SetTransparencyFromBitmap(Bmp, Bmp2);
      SetTransparentColor(Bmp, 16777215);
      FastDrawTransparent(0, 0, Bmp, Bmp2);
      SafeDrawBitmap(Bmp2, GetClientCanvas, x, y);
      FreeBitmap(Bmp2);
    end;

  2. #2
    Join Date
    May 2008
    Posts
    38
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    im not sure about this but is the black box appearing on the thing you want the bitmap to appear on? because if you try it it might actually work...some programs and pictures show transparency with a light grayish color...so maybe it'll appear transparent...because if you want to convert bitmap>text then the background has to be black then too...

    ohhh i just learned something from thinking about this...the black outside for the bmp is so that it knows the borders of the object lol...so dtm's are actually less precise than bmp's
    http://www.stats.srl-forums.com/sigs/5264.png


    Basic Auto-talker - 100% done (lol)
    Al-Kharid Kebab Buyer & Banker - 5% done (lol)

  3. #3
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    I'll post a script to better show what i am talking about.

  4. #4
    Join Date
    Apr 2007
    Posts
    994
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    For scar, any color in the bitmap that is black will be transparent. At least I think thats true.

    Thats why when you set the color to transparent it comes up with something black.
    [QUOTE]<GoF`> oh no its Raymooond
    <Raymooond> Heya
    <GoF`> is it ray or some other ray?
    <LeeLokHin> No idea
    <LeeLokHin> Raymond, what's the game you like the most?
    <Raymooond> Runescape
    <-- LeeLokHin has kicked Raymooond from #srl (Faker.)[/QUOTE]

  5. #5
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Script haves an error
    ~Hermen

  6. #6
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    A blank bitmap's default colour is black, so set change the background colour of Bmp2 with FastDrawClear to change the background colour or set the transparent colour of Bmp2 to 0 and then draw it with transparency onto the Debug image
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  7. #7
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    SetColorTransparent should work.
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  8. #8
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    So i still can't do what i need to do because the background i'm using is multi colored.
    This doesn't make sense to me because SetTransparentColor is just the same as changing the specified color to another one and that's not making is transparent at all.
    Like i said, there is a procedure for that already.

    I will update the example script with a multi colored background.

  9. #9
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Aha i found the solution.
    I knew SetTransparentColor wasn't useless
    But you have to use SetTransparencyFromBitmap and the 2nd bitmap has to be your background, you can't just draw on.
    SCAR Code:
    program New;
    var
      Bmp, Bmp2: integer;
      Canvas, Canvas2: TCanvas;
     


    begin
      Bmp := BitmapFromString(32, 26, 'beNqdVutTG9cVv/vSvnfvc3dlM' +
           'EgCUyMhJPRCLxAvGUMwcQAzjm1iAwU/MAQbknGNMSAwsXGcyWSm03' +
           'b6qZ3ONB/zH9IrnDaZ6fgDnNHu7J579Tvn/M7j7unpR5GAcvppMYD' +
           'w/0ogip/aL4rg968CAH//6z+AKIcAkAGQJEUBv21QAfjc1ABoKoHI' +
           'VwW+n/+ysgF+h8M1fJmvK0BYfrSmitpvSwL4+Z+/fDj588rGNxERB' +
           'AC0AIVbOnMS3KbmDRQahkLekMoGKGlC1dL6ZNChg27uj3K2TQI3IR' +
           'o1wYAm3ru7vLG+KwA5eznya6RA/de/f/nL335efvqsakhpCeREQTr' +
           'Dv0Wda6Yy6cifQW3KDl2zQd0GQ5YwZICqAWqK0BNSBBE8xO59Zsx6' +
           '0rRlzy3cu3V7gUeYvBL7iK8I4E2LvUXxmCkOqKCsgTgPEoRWk51zy' +
           'NwdLL0YrO4VB+eIsFcpzjnOfnVge6D4rJYbcoVvK/nGcG0FqV8S9Y' +
           '5rjRK1pIOEJnPMTNt//RfBt4G1SJ3ryPgMWlWtSUJcAivxzrso9LJ' +
           'WeTFQe9yXWyDGq6H8LWy8Gi7tlIurueSYrR2Ui/tj1afEXAybc1CZ' +
           'dkNDKohzRAH0dIab4ILcaLWfB+4aNh7g0A0sT0NU06SEDlb/EFtCc' +
           'JGpf0p18Vi+ouodZMxDbYYbSqfXu6/esLQKBDt9XU8CYwmbC9ieR9' +
           'YE1EdspbOZb/WMfGXLczY86yuqP/DMWWZMO9YEgpUQWCX2cveVpd4' +
           'I55abXvaNB1BZcIwpz/rCC41b2lqieylxtWwKzwN7jZoPiHkX67NE' +
           'n3KNgmFyCz2xDu7/ToB3qPnEV1eZPG+BeVefsPSqCx4x5VGANojz3' +
           'LGI54YdDJnDWWoJCIP0pmVPIsBDqBviN2HrMdYWqXEHKnNQmifmsC' +
           'K38FLnMYhgm7kvfPg1s9eIfpfTSM3PHa0WAuvEfHzJ9m3meg7zKcE' +
           'QUv+PlgYhJIQFPiMETdrGGAIvAmsrDFc9c8U3F5g6i6QZV63oQJB4' +
           'mRuUuShA3CWLQQ6CMSQ0YByRUkJdcqb0Cce3fYIJwh6DiGgEBy6/M' +
           'MXIItgJaFPLiEcI4frm/2j41/4Sm42pAUXlnSaJzfZsZkd8XYj7HB' +
           'iql6jnexhj6mH0JUEIW8xDYccLCKwz81W50qxmkZPBL1HmN1kEHEY' +
           'AiVjHRxOJaHtvWzQVuZxt68i2R1Pt7XwaHOazz1qc7UuI2hQinYMj' +
           'aK1SnXg2Z4Z65hQyX2a6dnpSqgx6Wlv7OmKZSFuuvS11uSUfjWQir' +
           'b2xzk/NKEFUX/va177pOWFOFEMOD7iVBItUZpw+EzMKWzCZsputzT' +
           '3vjXWdnkc4Q9+NDzwLs23P4mXDE+Fx7hFapgon10NshlgzVGmMDB2' +
           'OVHk79UU7z4XPa+v92Mim7261uEf1wacIYt4OXsgjDsXscGRoEWlf' +
           'MPtguPYyneLZSkWj58Ln2XpXSPPG2fTs1yPFH+q19YCte/Y605eJc' +
           'TxcfjvWP0Nk3k276asXwAeiuldIvs33HWZSh+VsI5fbz3W9yZYa2Z' +
           '5GMblbSO8V0rwAjrLpRu5i+OClj78r5o5yyW1fe+hbe/3dT4h+WMw' +
           '0cvGHTL2Njb185qiUm4TKRfAVsO/TNWpvX6ZP2pxNYm0R+jSwH1F9' +
           'GUkrzLrn6rNUmmbilGVdAF+UheNr5UMPfT9ePBkZ/bE+tI7R+/r4h' +
           'g9/ul7bn7j27vrYfai/rw8c14cvlt/v+9Obl0ye3w/j9TeT5c2wu8' +
           'n4mLKWXPWH0cEfJ0ZnoTHrWjwRF8CXJdAoZT/kCieF3HEp+76YPsl' +
           'njouJk/7s20r+uL/5+q7Sd1TpeZu/SH3ywXeAYweF9EEpuemj5z7e' +
           '7U9shuFhNn6Qi/MT4T42Gvnkq0LvTVvmDZyIxk7PKc1px2ed2PwcC' +
           'QFRAUqoObbOpqEgCc2vEUWUVH6C9MSi/xtl55J8e6y/NcpP6viV9l' +
           'SkpbetLRmLJDui/M6fs9FoJhbjz92RT5DzHxHS9IA=');
      Bmp2 := BitmapFromString(31, 24, 'beNoBuAhH9ykY5iIW5yAZ6Rsb' +
           '5BkT4RgO3hgL4SUI4iYL3iIF4yYG5SkG4i4L5zEM7zMG9DEF9jII+' +
           'DIL+zUY8XAs8ZhE67pb18lgjbNGYaBFT55PMohHHW9BFWI4Ek0xE0' +
           'gsFDYe5iEZ5h8a5xkb5RwV4h4S4SAP4i0O5zMS6TEL7DUN7DIL4D8' +
           'T4kET5kUO6kUN70UR8UUT8T8b+XQz9ZBC7axQ4sFar8FVfK5NZKVR' +
           'QY5GLXtLJG9EC0YmC0AiDy8X5ikV5ygV5yYV5y4Q5jQQ5zcO50kZ5' +
           'lwd544w35462bBHv7JKuq1FtaI8w5ZDyI5Fy4dG3ntA42824HQz1X' +
           'st1I8077hezsVmn7dXfK1RUJhOQYpFJnw/JXY+JWdD8DIQ8zcR6Dk' +
           'C6D0J6T0P7kEX92st94497L5c18Vfgag+bKxYZqlZYqxhZqpdbqxZ' +
           'drBbgalToLJgrrZhu7peycFfyMRgp8Bih7NccKpeUplhQopYKHlBI' +
           'Gw7H1s36jES7zkU8UMR80kY8EUZ80cf/245/41G9bVU47tZpq9Gfa' +
           'tRc6VMYJlIWI46W400YY81WZU/eKVUg6lWjK1UlK9SpbZQg7NQbLF' +
           'UXLBbR6BgPpZcMoFULXVNHlQ65DAV6jcX8D8W80Ma7UAY7kAb7k0h' +
           '62Um7Y027J9D371cwMVfusBeqLdanaxPnKpJn6tJkqhToLJmpbVqq' +
           'bdqqrdnnLdYa6tLV6xPSqxVNpVRM41PJnJMJGdIHEs57SIU8yUY9S' +
           'UZ9Dca8EAX8kob4o4u4qU74cJYzLxamrFWja9bjK9bf6xba6thXaZ' +
           'hUaBfVJ5RTJZbS5RfSpNeSJJdT49bSZpgRJ9kQ6VoPZ1gNZNXM4NO' +
           'J3NCE04i5yIR7ycY8Csb6kAc5k4c6V0g7LVR6sZY28lZw7xRjaZBi' +
           '6xViqtUeKJMW55RR5dSOY9OOI1UL3tVLnVTLXJTMHFRLnZRNIBZPI' +
           'pgPpFjOJVgN5VgP5JkP45hMHdN7TAa8zQh7TIf4Ekc3Vsd4mwk7LN' +
           'Z6L9W4MBT28BXyMZhwrxcwrxasbVUjK1WdaFSYZdMQJtiLXdSKWxL' +
           'KmdILmdHKmhRL2dOOXFUPHdXOINYQZBhLIBcLH5aN4Nf7zUp7TIh6' +
           'z0Y32Ml4H415ZRF0blL071N0L1Hy7c+0bk/v7U5y79HzcFdrshtiL' +
           'tfZaZKQbNeMYlMMHpJLWtEKV5ALFBEMF1JK2BGLGlKKHNKLntPJHN' +
           'UJm9UMnJX4aA86LFK1sRWoaxGna5OorVbvLdjy7ln5L9u4sBp1L1g' +
           'srNWpq9SgapOXp9FTpQ+RIw4LH42GUgSGjkNHi4KJSoMKSkREyILD' +
           'iYQDSgVHS4kKjcwLEE8MElGMk9K7rtS6r5T3LxV0K1Z06lh1aVl3K' +
           'Bk4ZZd6YxT6I5S35BN6YpK4YxJ1JtUxp5YwZhWv5ZUqZhTjY1HeoE' +
           '7YXEqTWMaR0gPKjsEIDgEFDQCFTYLGzsSFi0ZFTAfIT8z8ZxM75pK' +
           '55BD5nlB4WY62lg05U4z5EQq4jcb4jcZ2zcS5DAV4jUX3EMh3Usm3' +
           '0op4Eop41Yp34FE141MypZNv5pMqJJGjIM4eXswYXEmPWYaL10SKk' +
           'YWGz4UEz4i4koj40si20AU3jQT4jAW4iwX5ycY5yYV6CQO7ScN6iQ' +
           'J3ykR4S0U3TAS3i8Q3y0P3isL4igR1zQT1T0W00Yb1E8i0XIw2oVE' +
           '1pBLx5dNqqlWlaNLcY1DU307Kmo44CkX4DAH3TcF4FEV41sf5V4e5' +
           '10e5VoZ5FQV3koK3U0b4U8e4U8g010f020l34I116lH2LRUl7VfeK' +
           'lYZKBWWKRkU59fUqBmSZhfQpJdQJBdQZFeRY9aPH5QOnhR7ycq6jA' +
           'k4zQf2z4f2kEf4D0u4EEu3EQt2Est1VErzl0hz2Ei0mknzJFByKBL' +
           'yqxWprdxmLJrVpdXSZNWQ5JZRJJiPIhaQINaPnxXP3VVO3FROW5QL' +
           'mVGLGFHKltFz2Y2wmg0u2kxtW4utnEwvnk0v3s0wXwxx3stz4Iww5' +
           'FIxZRIx5xNo6pakalbhapdZ5NYX49VQH9QPHpRN3RSO3dVMmtKNmR' +
           'INWBFPFxFO1hCOFNAK008J0s9KEg7aplIZJNNY5FQbJNUcZNWc51H' +
           'eaBHgaJHkKVGo7FQoK1lnKpfmKlZZpZKUpFLRItJTno/S3g/NWU/M' +
           'l9ANFxCKVU8IEoyJkcyKUYyMkc0MUYzNEI1LUc8I0I6JD41h5IyW3' +
           '0xSHIyOWYtN2QrOGRDO2pGP3RIRIVLV59deqBVhKRRn7BUvrBNu6x' +
           'PsqJKpadUlptLWHI1SmUyPVgtHEYwFkAqIEYvHkQrIUUrIUMqJz4q' +
           'GkAxFUU3G0Y12zcR11Ee11Yf2nEw3YA7zplXyKZewLBitLNgtq9ez' +
           'bVb1Llg3bpg2ahJ1KdC0aZA25w73KtF0bZdwbVjqrVmZqJaXJpXSZ' +
           'BYO4VSNn5QNXpLMm9FN3FIMmtCLWY93SgL3TQV3C8R2TkX3kom3nE' +
           's4I0/4KZS1btc07pd0b1e0Llb07ZY17ZV1LdT07dT36tI2rBMuapN' +
           'nqRMf6NLVJ9NSJZKQ5RZO45YPotdQItgQ4VVQ4VVRoVWRIJT2y0V2' +
           'TAb1ysX0DQd0EAm0GUd1IM01J5Iy7hZzL1exr9kxLldxrVZ1bFR1q' +
           '5O2a9N37JN2bZOvbdVm6xMcqRBS5pHPI1ANYZLLnxMLHBJLnBMMGh' +
           'DLWVAM2lFNGhE5VQb4GMg6HIq6J5F3KhFwKxWrKtRmqtPkrBWobll' +
           'rLhmsLlmtrplv59Kw5ZByJRAs6JKrKlMnLNZjK5YbKBNQ4pONHtDJ' +
           '2hAIVg5HUMqHT0mHDEsFSgkGSkmGion6CYd7D0i7Uch5HUw5Y4/46' +
           '5E17VJzLxNurZLr6E+oKU/m6dDjKhEaaRQYaBRW5lOXZBYTZFUK4N' +
           'HNoZTLHpQJHlQHHFKGWJFG1lAK1M7KEoxJTwqIjknGi8eFIOivfA=' +
           '');
      SetTransparencyFromBitmap(Bmp, Bmp2);
     
      Canvas:= GetBitmapCanvas(Bmp);
      Canvas2:= GetDebugCanvas;
      DisplayDebugImgWindow(100, 100);
     
      //drawing the background
      Canvas2.Brush.Color:= 255;
      Canvas2.Pen.Color:= 255;
      Canvas2.Rectangle(0, 0, 25, 100);
      Canvas2.Brush.Color:= clBlue;
      Canvas2.Pen.Color:= clBlue;
      Canvas2.Rectangle(25, 0, 100, 100);
     
      SetTransparentColor(Bmp, 16777215);
      FastDrawTransparent(0, 0, Bmp, Bmp2);
      SafeDrawBitmap(Bmp2, Canvas2, 10, 10);
     
      FreeBitmap(Bmp);
      FreeBitmap(Bmp2);
    end.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help make some Bitmap Masks
    By benjaa in forum OSR Help
    Replies: 0
    Last Post: 03-10-2009, 07:17 AM
  2. What program do i need to make a Bitmap Mask?
    By Claymore in forum OSR Help
    Replies: 4
    Last Post: 07-27-2008, 03:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •