J
J
jnas2015-01-25 10:21:25
Windows phone
jnas, 2015-01-25 10:21:25

How to open and scale a BitmapImage?

Hello,
I just started programming, I ask for help, I can’t figure out how to scale an image with two fingers, just like when opening an image in albums?
More details available code

<ListView Grid.Row="0" Margin="19,0,0,0" x:Name="MyPanel"  IsItemClickEnabled="True" ItemClick="ItemView_ItemClick">
            
            <TextBlock x:Uid="Header" Text="My" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0"/>
            <TextBlock Text="{Binding Title}" Style="{ThemeResource BaseTextBlockStyle}" Margin="0,10,0,0" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}" />
            <TextBlock x:Name="mtext" Style="{ThemeResource BaseTextBlockStyle}"/>
            
        </ListView>

in c#
private void PanelAddImage(string img) {
            count++;
            string G = "img" + count.ToString();
            BitmapImage I = new BitmapImage(new Uri(img, UriKind.Absolute));
            MyPanel.Items.Add(new Image { Name = G, Source = I});
        }

that is, with the help of PanelAddImage I add an image to the ListView
and then I planned that by clicking on the image it would somehow open, well, so that I could scale the image, I can’t figure out how to implement this function of “opening” the image with scaling,
I tried to do it through WebView by clicking on the image. but alas, nothing happened ...
I ask for help, where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Grekhov, 2015-01-27
@Sterk

BitmapImage has DecodePixelWidth, DecodePixelHeight size to convert.

var uri = value as string;
            if (string.IsNullOrWhiteSpace(uri))
                return null;
            var image = new BitmapImage();
            image.BeginInit();
            image.UriSource = new Uri(uri);
            if (Width != null)
                image.DecodePixelWidth = (int)Width;
            if (Height != null)
                image.DecodePixelHeight = (int)Height;
            image.EndInit();
            return image;

Or you can set the size of the control, not the source, I think this is your case.
var uri = value as string;
            if (string.IsNullOrWhiteSpace(uri))
                return null;
            var source = new BitmapImage(new Uri(uri));
            var image = new Image { Source = source };
            if (Width != null)
                image.Width = (int)Width;
            if (Height != null)
                image.Height = (int)Height;
            return image;

Do the click processing and change the size of the control.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question