Click here to Skip to main content
15,888,242 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in my wpf application, the user can upload an image.
Now, when the image is not centered and the background is transparent, i want to crop the image. is it posiible?

What I have tried:

.......................................................................................
Posted
Comments
Sergey Alexandrovich Kryukov 15-May-16 16:45pm    
Keeping in mind your past question, let me ask you: do you mean rectangular cropping? The problem is way too trivial.
Please understand: this is the only notion of "cropping".
—SA
oronsultan 15-May-16 22:36pm    
hey sergey, no, i dont mean rectanguler cropping. what i'm doing is cliping ellipsegeomtry inside a path and then do this:
BitmapImage bmi2 = new BitmapImage();
RenderTargetBitmap rtb = new RenderTargetBitmap(Convert.ToInt32(pathBack.ActualWidth), Convert.ToInt32(pathBack.ActualHeight), 0, 0, PixelFormats.Pbgra32);
pathBack.Clip = circle;
rtb.Render(pathBack);
PngBitmapEncoder pngImage = new PngBitmapEncoder();
pngImage.Frames.Add(BitmapFrame.Create(rtb));
using (Stream fileStream = File.Create(@"C:\Users\Desktop\EW\test\2.png"))
{
pngImage.Save(fileStream);
}
the problem is that when i choose the righth side of the image, the cropped png comes when the circle is on the left side of the image and the right size is blanked. same for each direction...what i mean is that the cropped picture actually does give me what i have chosen but instead of cropping the unselected parts it just made them transparent. i need to remove that. thanks...

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