Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have an imagebox and I use OpenFileDialog to load a picture

After picture is loaded I have used this code because I don't know to use image already uploaded in my imagebox

I don't want to use bmp.UriSource() to load a new image like in this example

I want to use imagebox source to transform picture inside in many ways, and to update image inside

C#
BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri("pack://application:,,,/images/pic.png");
bmp.EndInit();
TransformedBitmap myRotatedBitmapSource = new TransformedBitmap();
myRotatedBitmapSource.BeginInit();
myRotatedBitmapSource.Source = bmp;
myRotatedBitmapSource.Transform = new RotateTransform(90);
myRotatedBitmapSource.EndInit();
image_box.Source = myRotatedBitmapSource;


What I have tried:

C#
Uri ur = new Uri(image_box.Source.ToString(), UriKind.Absolute);
BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = ur;
bmp.EndInit();
TransformedBitmap myRotatedBitmapSource = new TransformedBitmap();
myRotatedBitmapSource.BeginInit();
myRotatedBitmapSource.Source = bmp;
myRotatedBitmapSource.Transform = new RotateTransform(90);
myRotatedBitmapSource.EndInit();
image_box.Source = myRotatedBitmapSource;


after second click on button I got error

i do't want to use only rotate image, i want to use more options but i don't know to reuse image and to update it in imagebox
Posted
Comments
[no name] 4-Feb-19 19:02pm    
Stick to loading, manipulating, then assigning to an image control.

Then manipulate again and reassign.

Whatever else you're trying to do won't work.
sz3bbylA 5-Feb-19 13:18pm    
so, i don't know to do this , any example, link is helpfull

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