私はUWPで初めてです。私の最初のタスクは想像力です。今は想像線を描く動的矩形を作成する方法を見つけようとしています。 p.s.悪い文法には申し訳ありません。UWP動的矩形を作成します
私のプログラムは、ファイルを開くためのボタンを持っている必要がありますし、画面上のユーザーが変更したり、移動することができますダイナミック長方形である必要があり、ユーザーの押しボタンを「保存」の画像は、矩形サイズ としてクロップされますとき、私のC#のコード がありますありがとう)
namespace Crop1
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
SoftwareBitmap softwareBitmap;
private async void OpenFile(object sender, RoutedEventArgs e)
{
FileOpenPicker fileOpenPicker = new FileOpenPicker();
fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
fileOpenPicker.FileTypeFilter.Add(".jpg");
fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
var inputFile = await fileOpenPicker.PickSingleFileAsync();
if (inputFile == null)
{
// The user cancelled the picking operation
return;
}
using (IRandomAccessStream stream = await inputFile.OpenAsync(FileAccessMode.Read))
{
// Create the decoder from the stream
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
// Get the SoftwareBitmap representation of the file
softwareBitmap = await decoder.GetSoftwareBitmapAsync();
}
if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight)
{
softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
}
var source = new SoftwareBitmapSource();
await source.SetBitmapAsync(softwareBitmap);
// Set the source of the Image control
//imageControl.Source = source;
p1rect1.Fill = new ImageBrush
{
ImageSource = source
};
}
private async void Save(object sender, RoutedEventArgs e)
{
FileSavePicker fileSavePicker = new FileSavePicker();
fileSavePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
fileSavePicker.FileTypeChoices.Add("JPEG files", new List<string>() { ".jpg" , ".png"});
fileSavePicker.SuggestedFileName = "image";
var outputFile = await fileSavePicker.PickSaveFileAsync();
if (outputFile == null)
{
// The user cancelled the picking operation
return;
}
// SoftwareBitmap softwareBitmap;
// BitmapDecoder decoder = await BitmapDecoder.CreateAsync(imageControl);
SaveSoftwareBitmapToFile(softwareBitmap, outputFile);
}
private async void SaveSoftwareBitmapToFile(SoftwareBitmap softwareBitmap, StorageFile outputFile)
{
using (IRandomAccessStream stream = await outputFile.OpenAsync(FileAccessMode.ReadWrite))
{
// Create an encoder with the desired format
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
// Set the software bitmap
encoder.SetSoftwareBitmap(softwareBitmap);
//// Set additional encoding parameters, if needed
//encoder.BitmapTransform.ScaledWidth = 320;
//encoder.BitmapTransform.ScaledHeight = 240;
// encoder.BitmapTransform.Rotation = Windows.Graphics.Imaging.BitmapRotation.Clockwise90Degrees;
encoder.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Fant;
encoder.IsThumbnailGenerated = true;
try
{
await encoder.FlushAsync();
}
catch (Exception err)
{
switch (err.HResult)
{
case unchecked((int)0x88982F81): //WINCODEC_ERR_UNSUPPORTEDOPERATION
// If the encoder does not support writing a thumbnail, then try again
// but disable thumbnail generation.
encoder.IsThumbnailGenerated = false;
break;
default:
throw err;
}
}
if (encoder.IsThumbnailGenerated == false)
{
await encoder.FlushAsync();
}
}
}
}
}
あなたのコードを表示してください、あなたは何を試してみましたか? –
イメージして、あなたが望むものを教えてもらえますか? – lindexi
@lindexi私のプログラムは、ファイルを開くためにボタンを持っている必要がありますし、画面上でユーザーが変更または移動することができる動的矩形でなければならず、ユーザーが「保存」ボタンを押すと矩形サイズとしてクロップされます – Fr13nd