이미지의 크기를 조정하는 함수를 작성하려고합니다. WinRT/Win8 함수에 대해 WriteableBitmapEx를 사용합니다. Resize();WriteableBitmapEx WInRT의 크기 조정 기능
public class PictureExtension
{
private MemoryRandomAccessStream _memoryRandomAccessStream;
private readonly Stream _dataStream;
private readonly double _height;
private readonly double _width;
public PictureExtension(Stream dataStream, double height, double width)
{
_dataStream = dataStream;
_memoryRandomAccessStream = (_dataStream.ToRandomAccessStream());
_height = height;
_width = width;
}
public byte[] ToArray(double maxSide)
{
if (_height <= maxSide && _width <= maxSide)
{
return _dataStream.ToArray();
}
else
{
var target = new WriteableBitmap((int) _width, (int) _height);
var aspectRatio = (double)_width/_height;
double newHeight;
double newWidth;
if (_width > _height)
{
newWidth = maxSide;
newHeight = newWidth/aspectRatio;
}
else
{
newHeight = maxSide;
newWidth = maxSide * aspectRatio;
}
int count = (int)_dataStream.Length;
using (var bmpStream = target.PixelBuffer.AsStream())
{
bmpStream.Seek(0, SeekOrigin.Begin);
bmpStream.Write(_dataStream.ToArray(), 0, _dataStream.ToArray().Length);
}
var resized = target.Resize((int)newWidth, (int)newHeight, WriteableBitmapExtensions.Interpolation.Bilinear);
return resized.ToByteArray();
}
}
}
}
바이트의이 기능의 배열을 반환하지만 더 이상 이미지가 아닙니다 .. 나는 무엇이 잘못 되었나요 .. PNG 및 JPG 형식의 테스트?
ToArray() 메서드입니다. ToArray()의 본문에 사용 된 Resize() 메서드를 찾고 계시지 않습니까? –