600 X 400 寸法の画像を含む BitmapImage オブジェクトがあります。ここで、私の C# コード ビハインドから、objA に元の画像の上半分のトリミングされた画像が含まれ、objB に下半分のトリミングされた画像が含まれるように、それぞれ 600 X 200 のサイズの objA と objB という 2 つの新しい BitmapImage オブジェクトを作成する必要があります。
8984 次
1 に答える
5
BitmapSource topHalf = new CroppedBitmap(sourceBitmap, topRect);
BitmapSource bottomHalf = new CroppedBitmap(sourceBitmap, bottomRect);
結果は ではありませんがBitmapImage
、有効なImageSource
であり、表示するだけであれば問題ありません。
編集:実際にはそれを行う方法がありますが、かなり醜いです...Image
元の画像でコントロールを作成し、WriteableBitmap.Render
メソッドを使用してレンダリングする必要があります。
Image imageControl = new Image();
imageControl.Source = originalImage;
// Required because the Image control is not part of the visual tree (see doc)
Size size = new Size(originalImage.PixelWidth, originalImage.PixelHeight);
imageControl.Measure(size);
Rect rect = new Rect(new Point(0, 0), size);
imageControl.Arrange(ref rect);
WriteableBitmap topHalf = new WriteableBitmap(originalImage.PixelWidth, originalImage.PixelHeight / 2);
WriteableBitmap bottomHalf = new WriteableBitmap(originalImage.PixelWidth, originalImage.PixelHeight / 2);
Transform transform = new TranslateTransform();
topHalf.Render(originalImage, transform);
transform.Y = originalImage.PixelHeight / 2;
bottomHalf.Render(originalImage, transform);
免責事項: このコードは完全にテストされていません ;)
于 2010-09-25T14:49:02.957 に答える