手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#实现图片放大功能的按照像素放大图像方法
C#实现图片放大功能的按照像素放大图像方法
摘要:本文实例讲述了基于VisualC#实现的图片放大功能代码。可以直接放大像素,类似photoshop的图片放大功能,可用于像素的定位及修改,由...

本文实例讲述了基于Visual C#实现的图片放大功能代码。可以直接放大像素,类似photoshop的图片放大功能,可用于像素的定位及修改,由于使用了指针需要勾选允许不安全代码选项,读者可将其用于自己的项目中!

关于几个参数说明:

srcbitmap源图片

multiple图像放大倍数

放大处理后的图片

注意:需要在头部引用:using System.Drawing;using System.Drawing.Imaging;

至于命名空间读者可以自己定义。

主要功能代码如下:

using System.Drawing;using System.Drawing.Imaging; public Bitmap Magnifier(Bitmap srcbitmap, int multiple) { if (multiple <= 0) { multiple = 0; return srcbitmap; } Bitmap bitmap = new Bitmap(srcbitmap.Size.Width * multiple, srcbitmap.Size.Height * multiple); BitmapData srcbitmapdata = srcbitmap.LockBits(new Rectangle(new Point(0, 0), srcbitmap.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); BitmapData bitmapdata = bitmap.LockBits(new Rectangle(new Point(0, 0), bitmap.Size), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); unsafe { byte* srcbyte = (byte*)(srcbitmapdata.Scan0.ToPointer()); byte* sourcebyte = (byte*)(bitmapdata.Scan0.ToPointer()); for (int y = 0; y < bitmapdata.Height; y++) { for (int x = 0; x < bitmapdata.Width; x++) { long index = (x / multiple) * 4 + (y / multiple) * srcbitmapdata.Stride; sourcebyte[0] = srcbyte[index]; sourcebyte[1] = srcbyte[index + 1]; sourcebyte[2] = srcbyte[index + 2]; sourcebyte[3] = srcbyte[index + 3]; sourcebyte += 4; } } } srcbitmap.UnlockBits(srcbitmapdata); bitmap.UnlockBits(bitmapdata); return bitmap; }

【C#实现图片放大功能的按照像素放大图像方法】相关文章:

C# SkinEngine控件 给窗体添加皮肤的方法

c# 对cookies(增、删、改、查)的操作方法

C#给picturebox控件加图片选中状态的2个方法

使用C#实现阿拉伯数字到大写中文的转换

C#计算代码执行时间的方法

winfrom 在业务层实现事务控制的小例子

.net C# 实现任意List的笛卡尔乘积算法代码

c#重写TabControl控件实现关闭按钮的方法

C# 语音功能的实现方法

C#.NET字符串比较中忽略符号的方法

精品推荐
分类导航