使用BitmapData实现图像的高速处理

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

namespace 浮雕
{
    public class PhotoEmboss
    {
        public Bitmap Emboss(Bitmap _bmp, int pix, int angle)
        {
            Bitmap bmp = _bmp;
            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
            BitmapData bmd = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat);
            IntPtr ptr = bmd.Scan0;
            int w = bmd.Stride;
            int h = bmd.Height;
            int bytes = w * h;
            byte[] rgbValues = new byte[bytes];
            Marshal.Copy(ptr, rgbValues, 0, bytes);
            byte colorTemp;
            byte colorNext;
            for (int i = 0; i < w - 4; i += 3)
            {
                for (int j = 0; j < h - 1; j++)
                {
                    colorTemp = (byte)(rgbValues[j * w + i] * 0.299 + rgbValues[j * w + i + 1] * 0.587 + rgbValues[j * w + i + 2] * 0.114);
                    colorNext = (byte)(rgbValues[(j + 1) * w + i + 3] * 0.299 + rgbValues[(j + 1) * w + i + 4] * 0.587 + rgbValues[(j + 1) * w + i + 5] * 0.114);
                    int colorDif = colorTemp - colorNext + 128;
                    colorDif = (colorDif < 0 || colorDif > 255) ? 0 : colorDif;
                    rgbValues[j * w + i] = (byte)colorDif;
                    rgbValues[j * w + i + 1] = (byte)colorDif;
                    rgbValues[j * w + i + 2] = (byte)colorDif;
                }
            }
            Marshal.Copy(rgbValues, 0, ptr, bytes);
            bmp.UnlockBits(bmd);
            return bmp;
        }

        public Bitmap Emboss(Bitmap _bmp)
        {
            return Emboss(_bmp, 1, 135);
        }
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于Javascript的bitmap处理,并且将位图输出为base64编码以便于浏览器进行显示。   一、Bitmap.create(width, height, bgcolor)     创建一个width x height像素大小的位图,底色为bgcolor所代表的颜色。     如:bitmap.create(10, 10, 0xff0000); // 创建一个10 x 10像素的底色为红色的位图 二、Bitmap.toBase64()     将位图输出为base64编码的带datauri头(data:image/bmp;base64,)的字符串,以便于在浏览器里显示。     如:document.getElementById('img1').src = bitmap.toBase64(); 三、Bitmap.fromBase64()     自图像的BASE64编码中恢复位图数据,目前只支持24位色的BMP位图数据。     如:bitmap.fromBase64('Qk06AAAAAAAAADYAAAAoAAAAAQAAAAEAAAABABgAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=='); 四、Bitmap.setBitmapBytes(val, idx, length)     修改bitmap位图数据的第idx位置起的length字节为val值。 五、Bitmap.getBitmapBytes(idx, length)     获取bitmap位图数据的第idx位置起的length个字节的值,返回值为数组。 六、Bitmap.setHeaderValue(attribute, headerValue)     设置attribute头属性的值为headerValue,attribute必须为BitMapFormat的成员属性,需要提供offset、length等属性值。     如:bitmap.setHeaderValue(BitmapFormat.biWidth, 500); // 设置位图的宽度为500像素值 七、Bitmap.getHeaderValue(attribute)     获取位图attribute头属性的值,attribute必须为BitmapFormat的成员属性,需要提供offset、length等属性值,返回的是经过Endian转换后的实际整数值。 八、Bitmap.setPixel(x, y, color)     设置位图的(x, y)位置的像素值为color。 九、Bitmap.getPixel(x, y)     获取位图的(x, y)位置的RGB值,返回的内容为[ rr, gg, bb ]的数组内容 标签:jsBitmap
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值