How can I load 2 Images in one PictureBox ?
Here is an example:
http://postimg.org/image/l78kth897/
Thank you so much.
You can use Graphics.DrawImage() to draw any image anywhere inside a PictureBox or any other control for that matter. If you're writing your own control, override OnPaint(). If you want to use an existing PictureBox, simply use its Paint event to do this:
e.Graphics.DrawImage(YourImageObjectHere, ...);
e.Graphics.DrawImage(YourSecondImageObjectHere, ...);
GDI+ already supports transparency channel, so if your images have transparent areas, they'll draw just like the sample image you have posted. DrawImage() has over a dozen overloads, using which you can control several aspects of how an image is drawn. The simplest one takes the image object and the position to draw at.
Remember that an image object is an object of System.Drawing.Image or one of its derived classes. If all you have is the path of the image, you should use Image.FromFile() to create an Image object from that image file first.
Related
I'm using this project to find a Bitmap inside another Bitmap, its working perfectly but I want to make it support transparency, that mean I want to search for a Bitmap which contains transparency inside another Bitmap. To clearify more, in this example I want to modify the code make it able to find the red dot (with transparency) inside the image :
The image
The red dot
In a geographical software written in C#, a PictureBox is used to show GIS map that is saved as a png file in a temporary directory. There is some geometric shapes we need to be drawn on map. We used System.Drawing methods to perform this action.
Sometimes we need to change some properties these shapes or delete them, we need to remove the shapes without making beneath them black. Drawing them again with Color.Transparent obviously doesn't work, using Graphics#Clear(Color.Transparent) doesn't work too for the same reason.
We even tried using another picture box with transparent background that is used only for purpose of drawing shapes on; so that when we use Graphics#Clear(Color.Transparent) map container remains untouched. Sounded like a perfect idea at first, but because i don't know how and why it makes map container PictureBox invisible and map viewer panel is totally black, this idea failed too.
MapViewerForm
|-- Toolbar
|-- StatusBar
|-- MapViewer Panel (Provides scrollbars)
|-- MapContainer Pictutebox
|-- Shapes drawing canvas PictureBbox (The same size and location as map container, only difference is z-order)
I prefer to use the two PictureBoxes and making 'layers' idea, i think it's less unprofessional than the other idea (I am actually a java developer and this is a C# project!), I think there should be something like java's JLayeredPane in C# to adjust z-order of those two picture boxes and omit black screen bug, But if there is a solution to draw shapes on map container itself and then clear them without losing portions of maps lying behind them i'd appreciate that answer too.
P.S: If we load map picture from file and store it in a Bitmap or Image private field and when we need to clear drawings, load image from that field with a piece of code like picMapArea.Image = MapViewer.getInstance().getMapImage(); (Note: MapViewer is a singleton class) the painted shapes will be gone but it's obviously not anything like a "good idea" because of poor performance and lagging.
Thanks in advance.
Simply draw the shapes in an event handler for the picturebox Paint event.
To restore the view, all you have to do is call the picturebox Invalidate() method, so it repaints the Image, and not draw anything in your Paint event handler.
Just use an additional Bitmap:
Bitmap original = LoadBitmap(...);
Bitmap copy = new Bitmap(original);
Graphics graph = Graphics.FromImage(copy);
// draw some extra
PictureBox1.Image = copy;
I would like to know how I can create one image from many. I would like to create a tile in my windows phone application like in this image (specifically, the People tile):
(source: addictivetips.com)
I have nine pictures, and I would create an image, that I will add like tile to background. Does anybody know how can I create an image that looks like the one in that picture?
I have very little experience in this space, but have you considered creating a control that simply displays up to 9 pictures side by side in a grid like that? You then can bind each image independently & change them out however you want. This article touches on how to bind phontos in WP7 nicely:
http://msdn.microsoft.com/en-us/library/hh286418(v=vs.92).aspx
If you're talking about assembling an actual graphic image like a jpeg or bitmap, you'll need to look at the Image Class, Bitmap Class, and Graphics Class. Essentially you'll need to implement the following steps:
Load the relevant images with From method in Image, typically Image.FromFile.
Determine how many rows and columns you'll be using.
Calculate the total width and height for your layout using the widths and heights of the loaded images with appropriate padding added.
Create a new Bitmap of the appropriate size with the correct background color and iamge format.
Have variables for the current drawing location (x & y).
Have variables for the current row and column in your layout.
In a loop, Create your Graphics object.
Use Graphics.DrawImage to add your loaded image to the layout bitmap.
Increment your drawing row and or column as appropriate.
Calculate your new drawing location.
Repeat until done.
One of the options is to use WriteableBitmapEx
Also you can probably find an answer to your question here: How can I merge two images into one?
I've got this topimage with alpha channel in it and I need to put this image over another background image, while the alpha channel from the top image stays intact obviously.
Now I've seen some tutorials with Canvas, but my project doesn't seem to recognize Canvas.
Anyone got an idea why I cant use Canvas or how to put those 2 images over each other?
Ok, I will try to answer: after loading the image, like this more or less, pseudocode:
Bitmap bmp = new Bitmap("MyCooolSemiTransparentImage.png");
bmp.MakeTransparent(colorHaveToBeRenderedTransparent);
colorHaveToBeRenderedTransparent is a color wich results non transparent after loading it into Bitmap object.
EDIT
if alphachannel is ok, here is a simple tutorial how to draw in image on WinForms:
msdn: DrawImage
Call method provided in yuor forms OnPaint override and you will get what you want.
Hope this helps.
Regards.
I've got a button in my WinForms plugin. It's got an image on it. The thing is, when I click the button, I want the image to change from whatever image it is now, to whatever image I want it to be.
So basically how do i make button change its image? The image type is System.Drawing.Image.
In order to change a Button's image in WinForms you set it's Image property. You can either load a bitmap from a file with Bitmap.FromFile, or you can draw an image using the Graphic class by creating a new instance of Bitmap using the Width/Height constructor (i.e. new Bitmap(100, 100)) and then use the Graphic.FromImage method. Lookup the documentation on the Graphic class for more info.