On Fri, 31 Jan 2014, Wolfgang wrote:
> Hello all,
> 
> I found a strange behaviour with opacity.
> 
> Example:
> Public Sub ButtonStart_Click()
> Dim img1, img2 As Image
> Dim i As Integer
> 
>   'let us load an image to img1
>   img1 = Image.Load("data/map.png")
> 
> 
>   For i = 1 To 20
>       img2 = img1
>       img2.Opacity(0.9)
>       PictureBox1.Picture = img1.Picture
>       PictureBox2.Picture = img2.Picture
>       Wait 0.2
>   Next
> 
> End
> 
> 1. I load an image to "img1" and copy it to "img2".
> 2. Then I change the opacity of img2 to 90%.
> 3. I display both images in my form.
> 4. I repeat this 20 times.
> 
> What I expect:
> is that img1 should show the original visual impression and img2 show a
> lighter version of it
> 
> What I get:
> *BOTH* images get lighter and lighter with each loop. *Both* images are
> totally blurred out and the end of the loop.
> 
> How comes? Did I misunderstand "Opacity"? Why can't I change only one
> image's opacity?
> 

I'd guess that with img2 = img1 you don't create a copy of img1 but only
another reference to the same picture in memory.

This means if you change the image img2 points to (img2.Opacity(0.9)), then,
since img1 points to the same memory, img1 is also changed. To get two
distinct pictures, use

  img2 = img1.Copy()

(Of course, if you do this, you will do the same thing 20 times with your
loop.)

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to