Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi.
On Form i have only panel, every PicterBox creates dynamically.
I load images on panel, and create new Picterbox for every image.
I can move this PicterBoxes, but when one PicterBox cross another, it loses Images transparent background. I know, that it's becouse all PicterBoxes has Panel as Parent.
I got this
<img src='http://rghost.ru/46169807/image.png' />
but want this
<img src='http://rghost.ru/46169920/image.png' />
Any help with this?
Posted
Comments
Sunny_Kumar_ 22-May-13 2:00am    
are you sure you're using png images instead of jpg?
Dmitrii Grishchenko 22-May-13 3:30am    
yes. it's png

1 solution

On a screen, there is no such thing as "transparency". This is a metaphor meaning that you can see one image through another one. So, sometimes the solutions defines what do you want to see.

Use PNG images supporting transparency. Make sure transparency feature is actually used. I don't know what did you used, but one of good tools which can do it is, for example, open-source GIMP:
http://en.wikipedia.org/wiki/GIMP[^],
http://www.gimp.org/[^].

Don't use PictireBox. Directly render two bitmaps on some control, by overriding its OnPaint method or handling the event Paint. Use one of the methods System.Drawing.Graphics.DrawImage:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[^].

For further detail, please see my past answers:

How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^];

Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
How to speed up my vb.net application?[^].

—SA
 
Share this answer
 
Comments
Dmitrii Grishchenko 22-May-13 3:31am    
I used PictureBox becouse i need to move, scale images. Will it be possible to move bitmaps if I render them on same control?
Sergey Alexandrovich Kryukov 22-May-13 11:58am    
Of course. And this is yet another good reason for not using PictureBox. I explained it all in referenced past answers. You effectively move by changing some parameter (field of the class used in Paint handler); and, to put it to work, call Invalidate. This is how animated or interactive behavior of graphics is developed.
—SA
Dmitrii Grishchenko 23-May-13 3:17am    
Thanks for your reply, but i realy can't understand one thing. As you said I used DrawImage instead of PictureBox, but I don't know how to move drawen image. How I can get image position to change it? And what to do, when I have two or three images on control?
Sergey Alexandrovich Kryukov 23-May-13 8:29am    
How about your fantasy? It's pretty easy to just invent. OK, I explained above, and it is explained in my referenced answers. You don't move images, you move model of images (think MVC). Let's say you have a control and its class, then model is its instance field. You click or drag on screen, model moves. On each moving event (keyboard, mouse), all configuration space moves, and you call Invalidate. Animation is the same, but you move without events, in a separate thread. Invalidate in BeginInvoke (delegate UI-related call to the UI thread via its event queue).
—SA
Sergey Alexandrovich Kryukov 23-May-13 8:31am    
Transparency would mean that some elements of graphics will be visible through others. It simply means that you draw them with alpha channel "colors", where alpha value is sometimes less then maximum (like 255).
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900