没有合适的资源?快使用搜索试试~ 我知道了~
C#图片图像像素放大的一个方法
4星 · 超过85%的资源 需积分: 50 91 下载量 84 浏览量
2013-08-24
05:37:11
上传
评论
收藏 2KB TXT 举报
温馨提示
试读
2页
写了一个方法用于处理图片的直接放大(直接放大像素),类似photoshop的放大功能,这个放大用于图片放大后像素的定位和修改,由于使用了指针需要勾选允许不安全代码选项,做成方法是为了方便使用!
资源推荐
资源详情
资源评论
//需要using System.Drawing;using System.Drawing.Imaging;
//srcbitmap源图
//multiple放大倍数
//放回处理后的图片
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);
//srcbitmap源图
//multiple放大倍数
//放回处理后的图片
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);
码勒戈壁
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页