本文整理汇总了C#中ManagedCuda.NPP.NPPImage_8uC3.ResizeSqrPixel方法的典型用法代码示例。如果您正苦于以下问题:C# NPPImage_8uC3.ResizeSqrPixel方法的具体用法?C# NPPImage_8uC3.ResizeSqrPixel怎么用?C# NPPImage_8uC3.ResizeSqrPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ManagedCuda.NPP.NPPImage_8uC3
的用法示例。
在下文中一共展示了NPPImage_8uC3.ResizeSqrPixel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btn_Resize_Click
private void btn_Resize_Click(object sender, EventArgs e)
{
if ((Bitmap)pic_Image.Image == null) return;
Bitmap bmp = (Bitmap)pic_Image.Image;
int w = bmp.Width;
int h = bmp.Height;
if ((w <= 16 || h <= 16) && trk_Size.Value < 100)
{
MessageBox.Show("Image is too small for resizing.");
return;
}
int newW = (int)(trk_Size.Value / 100.0f * w);
int newH = (int)(trk_Size.Value / 100.0f * h);
if (newW % 16 != 0)
{
newW = newW - (newW % 16);
}
if (newW < 16) newW = 16;
if (newH % 16 != 0)
{
newH = newH - (newH % 16);
}
if (newH < 16) newH = 16;
double ratioW = newW / (double)w;
double ratioH = newH / (double)h;
if (ratioW == 1 && ratioH == 1)
return;
if (bmp.PixelFormat != System.Drawing.Imaging.PixelFormat.Format24bppRgb)
{
MessageBox.Show("Only three channel color images are supported!");
return;
}
NPPImage_8uC3 imgIn = new NPPImage_8uC3(w, h);
NPPImage_8uC3 imgOut = new NPPImage_8uC3(newW, newH);
InterpolationMode interpol = InterpolationMode.SuperSampling;
if (ratioH >= 1 || ratioW >= 1)
interpol = InterpolationMode.Lanczos;
imgIn.CopyToDevice(bmp);
imgIn.ResizeSqrPixel(imgOut, ratioW, ratioH, 0, 0, interpol);
Bitmap bmpRes = new Bitmap(newW, newH, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
imgOut.CopyToHost(bmpRes);
pic_Image.Image = bmpRes;
imgIn.Dispose();
imgOut.Dispose();
}