image transparent

Discussion in 'Questions (Windows Mobile)' started by hung, Aug 3, 2007.

  1. hung

    hung Member Licensed User

    :sign0085:I am using forelayer and drawer (imagelib.dll) to drawimage1. The transparent color on drawimage1 works fine and the background can be view through the transparent color.

    However, when I draw two images, the second image overlaps the first image, then I find the first image is covered by the second image and the transparent color.

    I thought it is due to I can use only onle forelayer. Any walkaround to solve that?
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    If you are using ImageLib, then you could draw on the back layer with transparency.
    That way, many drawings can overlap without hiding each other.
    Code:
    Sub App_Start
          Form1.Show
          drawer1.New1(
    "Form1",false)
          bmpSrc.New1(AppPath & 
    "\smiley.gif"'Loads an image from a file named smiley.gif
          rectSrc.New1(0,0,bmpSrc.Width,bmpSrc.Height) 'Same size as the image.
          rectDest.New1(100,100,25,25)
          drawer1.SetTransparentColor1(bmpSrc.GetPixel1(
    0,0)) 'Sets the transparent color to be the color of pixel (0,0) in the bitmap
          drawer1.DrawImage1(bmpSrc.Value,rectSrc.Value,rectDest.Value,true)
           rectDest.X = 
    80
            drawer1.DrawImage1(bmpSrc.Value,rectSrc.Value,rectDest.Value,
    true)
          drawer1.Refresh2(rectDest.Value)     
    End Sub
     
  3. hung

    hung Member Licensed User

    Thanks. Yes, that works for static objects.

    For simulating moving objects, I was using drawer.fillrectangle with forelayer transparency to to erase the forelayer so the background can resume viewable.

    If I use background layer to draw the objects, I can not resume the background image easily. As shown in the attached screen cap.


    To recover the background image, Is this the only way?:
    - instead of erase old image, redraw the background image on background with only the portion that is covered but old image.

    :sign0137:... it would be great if the transparency setting on background layer can apply to forelayer.
     

    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed User

    You could also draw on the fore layer using transparency.
    That way, the background will not be altered from the drawings.
     

    Attached Files:

  5. hung

    hung Member Licensed User

    Yes, I used fore layer in first sample but I found the problem that the fore layer transparency is referring to background image only, if second image overlaps first image, the transparent part of second image will show the background image part, but not the first image part (as attached in my first message).

    When I use background layer to draw overlap image, in the Repaint loop, I need to draw the background image portion, then first image, at last the second image, so I can see the second image is on top of first image (as attached).

    So what I see is the transparency of forelayer will redraw background image, but instead if it would be good if the transparency is on forelayer then on backgound layer, so when I use fore layer, I don't need to redraw backgound image in the Repaint loop but got the result as in the attached image.
     

    Attached Files:

Loading...