How To Crop Image In Specific Size

broken image


Sometimes I need to crop images to specific sizes or aspect ratios. For example, the following list shows some recommended image sizes for Google Business.

How do I crop (not resize) a picture to a specific (pixel by pixel) size? You know how on some forums, avatars are recommended to be '128 x 128' pixels? How can I do that? (In Preview, crop is a 'guessing'-drag-y crop). I did this with MSPaint in Windows.sigh. Mac really needs a simple Paint-ish application. Crop the image by doing one of the following: You can also outcrop, or add a margin around a picture, by dragging the cropping handles outward rather than inward. (Optional) To reposition the crop area, either change the crop area by dragging the edges or corners of the crop rectangle, or move the picture.

  • Profile image – 250×250 pixels
  • Cover photo – 1080×608 pixels
  • Shared images – 497×373 pixels

Unfortunately if you use a program like MS Paint to crop the image, it's hard to get a desired size that is nicely centered on an area of interest. This example shows how you can crop images by positioning a selection rectangle over a desired part of the image.

Now say I want to reduce the size. I can go to image, click resize in the pull-down menu and change the percentage. Make sure to keep the aspect ratio checked so that the photo doesn't distort. Let's make it half the size.// Notice that the pixel size at the bottom is now 73×82. You will also observe however that image looks blurred. For instance, 16:9 is perfect for landscape photography, while 3:4 is the best size for portraits. If you want to resize your image to a specific aspect ratio, click on Crop, then select one of the ratios in the toolbar. Now, move the frame to capture your subject or object perfectly. 3) Resize to a social media image size. To crop to different shapes, crop each picture one at time On the PICTURE TOOLS FORMAT tab, click Crop Crop to Shape, and then pick the shape you want. Crop to fit or fill a shape You can have a picture as the fill for a shape.

Use the File menu's Open command to open an image file. Next, enter the width and height of the area that you want to select. Then click and drag the selection rectangle to select the part of the image that you want to keep. Finally, use the File menu's Save As command to save the selected part of the image into a new file.

The following sections describe the main pieces of the program's code.

The program uses the following variables to keep track of the selection rectangle.

The variable SelectedRect gtracks the currently selected rectangle. The value Dragging is true while a drag is in progress. The point LastPoint stores the last mouse position while a drag is in progress.

When you press the mouse button down on the picImage PictureBox, the following event handler executes.

This code calls the SelectedRect rectangle's Contains method to determine whether the mouse's location is inside the rectangle. If the mouse is not inside the rectangle, the method returns without doing anything.

If the mouse is inside the rectangle, the code saves the mouse location in variable LastPoint and sets Dragging to true.

If you move the mouse over the PictureBox, the following event handler executes.

This code checks the Dragging variable to see if a drag is in progress.

If a drag is in progress, the code subtracts the coordinates of the previous mouse location (stored in the variable LastPoint) from the mouse's current location. It uses the difference in coordinates to update the upper left corner of the selection rectangle. It then saves the mouse's current location in variable LastPoint and refreshes the PictureBox to display new selection rectangle.

If no drag is in progress, the code calls the selection rectangle's Contains method to see if the mouse if over the currently selected rectangle. If the mouse is over the rectangle, the program displays the SizeAll cursor. If the mouse is not over the rectangle, the program displays the default cursor.

When you release the mouse button, the following event handler executes.

This code simply sets Dragging to false to end the current drag.

The following code shows how the program's PictureBox draws the selection rectangle.

This code creates a two-pixel-wide red Pen and uses it to draw the selection rectangle.

The code then changes the pen's color to yellow, gives it a dash pattern, and redraws the rectangle with the modified pen. The result is the thick, dashed, red and yellow rectangle shown in the picture at the top of the post.

When you invoke the File menu's Save As command, the following code executes.

This code displays a SaveFileDialog to let you pick the file that should contain the selected part of the image. If you pick a file and click Save, the code creates a new Bitmap that is the same size as the rectangle and makes a Graphics object associated with the Bitmap. The code then uses the Graphics object's DrawImage method to draw the selected part of the image on the Bitmap.

The code finishes by using the SaveImage method to save the bitmap into the file with the appropriate file format (JPG, PNG, BMP, etc.). For information on the SaveImage method, see my post Save images with an appropriate format depending on the file name's extension in C#.

If you change the value in the width or height text box, one of the following event handlers executes.

These methods try to parse the width and height values. If a value is not a valid integer, the program sets that value to zero. It then sets the selection rectangle's corresponding size accordingly and refreshes the PictureBox to show the resized rectangle.

This example lets you crop images to a specific size relatively easily. A nice enhancement would be to let you change the size of the selection rectangle while preserving its aspect ratio. Maybe I'll add that feature some day if I'm really bored.

Download the example to experiment with it and to see additional details.



Microsoft Paint is a simple graphics editor included with the Windows operating system. If you need to do some basic image editing, Paint is the perfect lightweight app. In this tech tip, we'll look at two tasks: how to resize an image and how to crop an image.

Resizing an Image

  1. Open an image in Paint. Right click on the image file and choose Open with > Paint.
  2. Choose Resize from the toolbar.
  3. In the window that appears, you can resize based on percentage or pixels. Choose which option at the top. Make sure Maintain aspect ratio is selected at the bottom so that the resized image won't be distorted.
  4. Change either the horizontal (width) or vertical (height) field. Then click OK.

Note: Never size an image up (to larger dimensions) unless you want to make the image blurrier. Realistically you can only size an image down to make it smaller.

Cropping an Image in Paint

Resize

What if, instead of resizing, you want to crop an image? How to use a backup drive. For example, you may have a screenshot and you want to crop it to show only a portion of the image. Here's how to crop an image in Paint.

  1. With the image open in Paint, click the Select option on the toolbar.
  2. Click and drag on the image to select the portion you want to keep.
  3. Click the Crop button on the toolbar.

Then the image will be trimmed down to your selection.

And that's how you can resize and crop images in Microsoft Paint. This is a quick and easy way to edit images, especially screenshots, without firing up a bulkier and more complex program like Adobe Photoshop.

Crop And Resize Image

Recent Posts

Happy Holidays from OXEN Technology

Crop Image To Specific Size In Windows 10

Recently OXEN has launched our new offering, Enhanced Security, which includes exciting new security features! We know that the businesses and organizations we serve need increasingly advanced tools to combat sophisticated cyber threats. Here we want to talk about what these tools are and how they can benefit your business.
If you use Microsoft Teams to communicate regularly with your team members, you may frequently want to refer back to certain messages. But finding a single message in a deluge of chat messages can be almost impossible!




broken image