나는 이미지 파일을하고 100 × 100 SoftwareBitmap
로 축소하고 ImageSource
로 돌아갑니다.
이미 SoftwareBitmap
이 있으니 더욱 쉽게 작업 할 수 있다고 생각합니다. 그러나 이것이 당신에게 아이디어를 줄 수 있기를 바랍니다.
새로 조정 된 SoftwareBitmap
인스턴스를 초기화하는 동안 PixelBuffer
의 경우에만 WritableBitmap
이 필요합니다. 우리가 가지고있는 바이트 [] 픽셀 데이터 (픽셀 로컬 변수)에서 직접 IBuffer를 생성 할 수 있다면 직접 SoftwareBitmap.CreateCopyFromBuffer()
메소드에 제공 할 수 있습니다. 이 경우 WritableBitmap
이 필요 없습니다.
private async Task<ImageSource> ProcessImageAsync(StorageFile ImageFile)
{
if (ImageFile == null)
throw new ArgumentNullException("ImageFile cannot be null.");
//The new size of processed image.
const int side = 100;
//Initialize bitmap transformations to be applied to the image.
var transform = new BitmapTransform() { ScaledWidth = side, ScaledHeight = side, InterpolationMode = BitmapInterpolationMode.Cubic };
//Get image pixels.
var stream = await ImageFile.OpenStreamForReadAsync();
var decoder = await BitmapDecoder.CreateAsync(stream.AsRandomAccessStream());
var pixelData = await decoder.GetPixelDataAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, transform, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.ColorManageToSRgb);
var pixels = pixelData.DetachPixelData();
//Initialize writable bitmap.
var wBitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
await wBitmap.SetSourceAsync(stream.AsRandomAccessStream());
//Create a software bitmap from the writable bitmap's pixel buffer.
var sBitmap = SoftwareBitmap.CreateCopyFromBuffer(wBitmap.PixelBuffer, BitmapPixelFormat.Bgra8, side, side, BitmapAlphaMode.Premultiplied);
//Create software bitmap source.
var sBitmapSource = new SoftwareBitmapSource();
await sBitmapSource.SetBitmapAsync(sBitmap);
return sBitmapSource;
}
PS :
여기에 코드입니다. 이 문장은 대답의 일부가 아니지만, 저는 XAML/C#에 대해 많은 것을 배웠고 MVA 및 Channel9 비디오에서 Windows Store 응용 프로그램을 개발한다고 말해야합니다! :)
모든 언어가 될 수 있습니다. 이미지 크기 조정은 간단하지 않습니다. 몇 가지 C 언어 알고리즘이 있습니다 : https://github.com/MalcolmMcLean/babyxrc/tree/master/src –
저는 과거에 이것을하기 위해 ImageMagick을 사용했습니다. 그것은 꽤 똑바로 앞으로 https://magick.codeplex.com/ –
BitmapTransform에 ScaledHeight 및 ScaledWidth 메서드를 봐도 될까요? https://msdn.microsoft.com/library/windows/apps/br226254#methods 내 지역이 아니므로 Google과 비슷합니다. – JohnLBevan