다음 문제가 있습니다. 바이트 배열을 WriteableBitmap
크기로 변환해야합니다. 나는 다음 코드를 쓴다. 통화 wb.Render(img, new ScaleTransform() { ScaleX = scale, ScaleY = scale });
후Silverlight의 이미지에서 WriteableBitmap 렌더링 문제가 있습니다.
private byte[] ResizeImage(byte[] array, double maxWidth, double maxHeight)
{
WriteableBitmap wb = null;
var stream = new MemoryStream(array);
stream.Seek(0, SeekOrigin.Begin);
var bmp = new WriteableBitmap(0, 0);
bmp.SetSource(stream);
stream.Close();
var img = new Image();
img.Source = bmp;
double scaleX = 1;
double scaleY = 1;
if (bmp.PixelHeight > maxHeight)
{
scaleY = maxHeight/bmp.PixelHeight;
}
if (bmp.PixelWidth > maxWidth)
{
scaleX = maxWidth/bmp.PixelWidth;
}
wb = new WriteableBitmap(0, 0);
var scale = Math.Min(scaleY, scaleX);
wb.Render(img, new ScaleTransform() { ScaleX = scale, ScaleY = scale });
wb.Invalidate();
return Utils.Encode(wb);
}
, wb
제로 픽셀을 갖는다.
도와주세요.
결과가 동일 ( –