PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 27, 2022

[FIXED] How to crop bitmap and get the lower 50% of the Image

 July 27, 2022     c#, crop, image-processing     No comments   

Issue

I have an Image which I want to crop. I already know that my required content is in the lower part of the image so how can I automatically crop it using Rectangle ?

I tried to use this Code (Below) to crop but it didn't help. I haven't used Rectangle much so please guide me.

private Bitmap cropImage(Bitmap img)
{
    int height= img.Height / 2;
    Rectangle CropArea = new Rectangle(100,height, 1400, 900);
    Bitmap bmpCrop = img.Clone(CropArea, img.PixelFormat);
    return bmpCrop;
}

the cropped image turned out fine but it's hardcoded. I need to make it dynamic so it gives same result for different images


Solution

Thanks @John for your answer. this code will cut 50% of the image and give your it's lower half:

private Bitmap cropImage(Bitmap img)
{
    int height= img.Height / 2;
    int newWidth = img.Width -100;
    int newHeight = img.Height - height;
    Rectangle CropArea = new Rectangle(100,height,newWidth,newHeight);
    Bitmap bmpCrop = img.Clone(CropArea, img.PixelFormat);
    return bmpCrop;
}


Answered By - Abdul Moiz
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing