How to choose a Photo Selector? - c#

I want the user be able to choose an avatar for himself. I implement selecting an image like this:
PhotoChooserTask photoChooser = new PhotoChooserTask();
photoChooser.Completed += photoChooser_Completed;
photoChooser.Show();
But after this, I want to show a one cell grid, and user can zoom in and out the picture to locate a part of image which wants be in the avatar. just like Instagram apps or WhatsApp.
How can I implement this second part? any reference or any example is appreciated. thanks

Set the PixelHeight and PixelWidth properties of the PhotoChooserTask before calling Show. The user will then be able to crop the image to the dimensions set.
PhotoChooserTask photoChooser = new PhotoChooserTask();
photoChooser.PixelHeight = 100;
photoChooser.PixelWidth = 100;
photoChooser.Completed += photoChooser_Completed;
photoChooser.Show();

For the "locating a part of the image" question, i think this will help
Getting a particular Portion of Image (Picture)
Display the image inside a rectangle and you can cut out only the part that appears inside the rectangle.

Related

Coloring area of an image on mouse click over picturebox

I would like to be able to fill any given area of an image with a given color, much like you can use paint to fill a rectangle, circle or any other shape delimited by a color.
To make this simpler I already have made the picture box source image to have the same size as the picture box itself, which should make things a bit easier.
How can I do this given that I have a picture box with an image and an already defined color and the user only has to click over the picture box to fill in any area with such color.
void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
// The color to be used
Color color = Color.Red;
// Image has same dimensions as picturebox to make things easier
Image img = pictureBox1.Image;
// Where it was clicked.
Point clickCoords = new Point(e.X, e.Y);
// Coloring that area clicked much like Paint does. How?
...
// After coloring show the result in the picture box again
pictureBox1.Image = img;
}
Thanks.
EDIT: Example of my desired behavior.
To make my goal obvious, let me add this small example.
You know MS Paint right?
You selected the pencil tool and start doing anything on the canvas, doesn't matter form or shape or even if the points your are doing with the pencil are connected or not.
Now you select the bucket tool and start clicking on the canvas. What will it do? Fill in the selected area according to the color you clicked over and how far she goes without changing with the color you have selected on the color pallet.
This is the behavior I want to emulate on my picture box mouse click event.
What you are looking for is a flood-fill algorithm. This should do the trick just fine.
The algorithm recursively searched for neighboring uncolored pixels, until it hits a wall.
You can use the code from here:
// Load the image (probably from your stream)
Image image = Image.FromFile( imagePath );
using (Graphics g = Graphics.FromImage(image))
{
Color customColor = Color.FromArgb(50, Color.Gray);
SolidBrush shadowBrush = new SolidBrush(customColor);
g.FillRectangles(shadowBrush, new RectangleF[] { rectFToFill });
}
image.Save( imageNewPath );
, but there is a one thing you missed - a rectFToFill, which you should define according your click event. There are a lot of strategies you can use, I suggest you to handle a Drag event or something like that, save the event start point and end point, after that define the rectangular you must fill:
You should examine the event points and after that create the Rectangle(F) structure using some of its constructors.
The Graphics class has a dozen methods you can use to draw some shapes or lines on your Image.

Crop picture right after taken in windows phone 8 development

I am creating app that allow user to use pictures from photo hub & take new photo to edit
I know that I can take picture from PhotoChoserTask but I want 2 seperate things.
Now I need to crop taken picture right after capture (like what I can do with PhotoChoserTask)
How can I achieve it?
Unfortunately CameraCaptureTask doesn't have Height and Width properties, so you cannot crop the image right after it is taken.
You can do two things:
1 - (I don't prefer this one!) Allow the user to take a picture using the CamerCaptureTask and then after it is completed, call the PhotoChoserTask so that the user again chooses the clicked image. Using this option you can crop the image using the Height and Width properties of the PhotoChoserTask
2 - Use Nokia Imaging SDK to crop the image. This SDK has many filters including the Crop filter which can be used to crop images. It is not as easy the PhotoChoserTask crop but you can still crop the image. There is sample code to crop an image on this page. Check it out!
Hope this helps!
Same as PhotoChoserTask, CameraCapturTask also has 'completed' event. Both are same so you can apply the same code of PhotoChoserTask 'completed' event to CameraCaptureTask 'completed' event. Use 'e.ChosenPhoto' argument property to get the stream of captured image.

Winform auto size to picture box

I'm wanting my winform to conform to the size of an image I pass to an image box held on my form. When I start the program it looks like this:
Then when I pass an image to my picture box it reshapes to this:
However, what I actually want is for the winform to resemble this. I had to manually drag the window to get it this way:
I'm not entirely sure how I can achieve the third one via code. At the moment this is what i have:
this.Size = new Size(imagePreview.Width, imagePreview.Height);
Is there something else I can do code wise so i always end up with the result in the third picture, no matter what size of the image?
There is one built-in property that could help you - Size Mode. Try it and if this does not suit your needs you can implement your own method for this - click me!

Images Scaling Down in draw in C#

Alright guys last little bit of this project I'll ask for help on I promise.
So I go to load the images, works fine however I notice upon loading that the dimensions of the image have been scaled down in the y to 300 (all are a constant value of 433) and up or down from their original width to 600.
I'm using the following method to load them
foreach (string file in Directory.EnumerateFiles(imagePath, "*.JPG"))
{
Image contents = Image.FromFile(file);
treesImage[count] = contents;
count++;
}
and this is the resulting image when I have it loaded.
http://i.stack.imgur.com/Q40kK.png
As you can see the image below the red rectangle is quite small
Any help would be appreciated. If you require any more information please post below and I'll make sure to edit the original question with the relevant information as soon as humanly possible.
EDIT: I am using a simple windows form application and not another graphical framework for my own reasons.
Thanks in advance :)
I'll assume you are using a PictureBox control to display the image.
When someone chooses a tree from your map, you obviously set the PictureBox Image property to the image object referenced by the index in the array. Use the Image object to set the ClientSize of the PictureBox control.
...
Image img = treesImage[idx];
MyPictureBox.SizeMode = PictureBoxSizeMode.Normal;
MyPictureBox.ClientSize = new Size(img.Width,img.Height);
MyPictureBox.Image = img;
...
Alternately you can define one size for your PictureBox and force all the images to be scaled to that size by setting the control SizeMode property to StretchImage declaratively.
I would recommend that you create a simple class (MyImageInfo for example) that would store the Path, Width, and Height of the images found in your first function into a list and then just as before when a user clicks to view an image you set the width and height of the PictureBox and then call the LoadAsync(path) method to get the image. then you aren't storing all images in memory at once, just as you need them since it doesn't look like this requires a lot of quick jumping from image to image.

How to create an Image object from an Icon for use with ToolStripStatusLabel items

I need to be able to set an icon on a ToolStripStatusLabel item in a C# Windows Forms application. The item will being displaying an image and text. I assumed that I could use an Icon with such an item but I am mistaken. What is the best way of creating an Image object from an existing Icon object?
the intended code will look something like:
Image image = new Image(); // Get this image somehow from a pre-existing Icon object
serverInfoToolStripStatusLabel.Text = "Connected to server X";
serverInfoToolStripStatusLabel.Image = image;
(NB: serverInfoToolStripStatusLabel is declared as System.Windows.Forms.ToolStripStatusLabel)
regards.
Icon has the ToBitmap method, which will give you a Bitmap, which is an Image
You can set the image directly in designer.
If you have to use code, why not add the image to your project Resources and then assign the image property to it?

Categories

Resources