0

画像を宣言してxamlファイルからソースを設定するのではなく、誰かが初期化の部分を実行し、画像の座標を設定し、コードで完全にソースを設定できますか?

4

2 に答える 2

0

ソースを指定して新しいイメージを作成する必要があります。

Image myImage = new Image();
BitmapImage bitmapImage = new BitmapImage(new Uri("/YourSource", UriKind.Relative)); //Or UriKind.Absolute depending in the path
myImage.Source = bitmapImage;

画像をいくつかの座標に配置する場合は、Canvasを背後に配置し、Canvas座標を使用して画像を配置できます。使用する:

 _myCanvas.Children.Add(myImage);  //To add your image to Canvas, declared on Xaml or previously created and added to your control
Canvas.SetTop(myImage, 100);   //Set Y coordenate relative to Canvas initial point
Canvas.SetLeft(myImage, 100);  // Set X
于 2012-10-03T11:58:50.017 に答える
0
// Create Image Element
Image myImage = new Image();
myImage.Width = 200;

// Create source
BitmapImage myBitmapImage = new BitmapImage();

// BitmapImage.UriSource must be in a BeginInit/EndInit block
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg");

// To save significant application memory, set the DecodePixelWidth or   
// DecodePixelHeight of the BitmapImage value of the image source to the desired  
// height or width of the rendered image. If you don't do this, the application will  
// cache the image as though it were rendered as its normal size rather then just  
// the size that is displayed. 
// Note: In order to preserve aspect ratio, set DecodePixelWidth 
// or DecodePixelHeight but not both.
myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
//set image source
myImage.Source = myBitmapImage;
于 2012-10-03T11:52:55.143 に答える