使用C#
我正在尝试将jpeg图像从3028x4051缩小到854x1171。这将产生接近1百万像素的图像,并保持纵横比。原始图像是。但图像的缩放效果很差。下面是图片的一部分。顶部是在MS paint中按比例缩小的图像,底部是在C#中按程序缩小的图像。我已经包括了我用来缩小和保存它的代码。有人知道会发生什么吗使用C#,c#,image,C#,Image,我正在尝试将jpeg图像从3028x4051缩小到854x1171。这将产生接近1百万像素的图像,并保持纵横比。原始图像是。但图像的缩放效果很差。下面是图片的一部分。顶部是在MS paint中按比例缩小的图像,底部是在C#中按程序缩小的图像。我已经包括了我用来缩小和保存它的代码。有人知道会发生什么吗 using (IRandomAccessStream sourceStream = await sourceFile.OpenAsync(FileAccessMode.Read)) { Bi
using (IRandomAccessStream sourceStream = await sourceFile.OpenAsync(FileAccessMode.Read))
{
BitmapDecoder myDecoder = await GetDecoder(sourceStream);
BitmapTransform myTransform = new BitmapTransform() { ScaledHeight = h, ScaledWidth = w };
await myDecoder.GetPixelDataAsync(
BitmapPixelFormat.Rgba8,
BitmapAlphaMode.Premultiplied,
myTransform,
ExifOrientationMode.IgnoreExifOrientation,
ColorManagementMode.DoNotColorManage);
BitmapEncoder myEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, destinationStream);
myEncoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied, w, h, 96, 96, pixelData.DetachPixelData());
await myEncoder.FlushAsync();
}
在创建
位图变换的新实例时,可以指定插值模式。线性模式是默认模式,因此要获得更好的结果,您需要尝试使用Cubic或Fant
using (IRandomAccessStream sourceStream = await sourceFile.OpenAsync(FileAccessMode.Read))
{
BitmapDecoder myDecoder = await GetDecoder(sourceStream);
BitmapTransform myTransform = new BitmapTransform() { ScaledHeight = h, ScaledWidth = w, InterpolationMode = BitmapInterpolationMode.Fant };
await myDecoder.GetPixelDataAsync(
BitmapPixelFormat.Rgba8,
BitmapAlphaMode.Premultiplied,
myTransform,
ExifOrientationMode.IgnoreExifOrientation,
ColorManagementMode.DoNotColorManage);
BitmapEncoder myEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, destinationStream);
myEncoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied, w, h, 96, 96, pixelData.DetachPixelData());
await myEncoder.FlushAsync();
}
检查我尝试使用的WriteableBitmap myWriteableBitmap=img1.Resize(w,h高度,writeablebitmappextensions.Interpolation.Bilinear)代码>图像的效果仍然很差