微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

locking位跨越1bpp索引图像字节边界

我正在剪切和粘贴从一个1bpp索引图像到一个新的图像。

所有的效果都很好,直到起始像素是8的除数。在下面的代码中,stride等于一个相对于矩形宽度的值,直到我碰到一个字节边界。 然后步幅等于整个页面的宽度。

var croppedRect = new Rectangle((int)left,(int)top,(int)width,(int)height); BitmapData croppedSource = _bitmapImage.LockBits(croppedRect,ImageLockMode.ReadWrite,BitmapImage.PixelFormat); int stride = croppedSource.Stride;

这是一个问题,因为不是将我select的区域粘贴到新图像中,而是将整个页面宽度的横截面(选定区域的高度)复制。

int numBytes = stride * (int)height; var srcData = new byte[numBytes]; Marshal.copy(croppedSource.Scan0,srcData,numBytes); Marshal.copy(srcData,croppedDest.Scan0,numBytes); destBmp.UnlockBits(croppedDest);

ServicePoint.Expect100继续Windows商店应用程序

如何从C#中查询GetMonitorBrightness

将ETW事件发送到全局“应用程序”日志

如何从nt.sys和w32k.sys中的内存地址parsing符号

插入位置/位置在任何应用程序内

在JavaScript或PHP中打开Window Phone中的Window store App

高精度的睡眠/等待.net

ActiveX,安装不起作用

python os.popen在给定的认字符时失败

AWS Elastic Beanstalk – 使用eb将g​​it repo附加到现有的EB环境

这是我感兴趣的任何人的代码。 可能有一个更优化的解决方案,但是这个工作。 我正在用白色创建整个页面,并在新页面中复制所选区域。 感谢Bob Powell的SetIndexedPixel例程。

protected int GetIndexedPixel(int x,int y,BitmapData bmd) { var index = y * bmd.Stride + (x >> 3); var p = Marshal.ReadByte(bmd.Scan0,index); var mask = (byte)(0x80 >> (x & 0x7)); return p &= mask; } protected void SetIndexedPixel(int x,BitmapData bmd,bool pixel) { int index = y * bmd.Stride + (x >> 3); byte p = Marshal.ReadByte(bmd.Scan0,index); byte mask = (byte)(0x80 >> (x & 0x7)); if (pixel) p &= (byte)(mask ^ 0xff); else p |= mask; Marshal.WriteByte(bmd.Scan0,index,p); } public DocAppImage CutToNew(int left,int top,int width,int height,int pageWidth,int pageHeight) { var destBmp = new Bitmap(pageWidth,pageHeight,BitmapImage.PixelFormat); var pageRect = new Rectangle(0,pageWidth,pageHeight); var pageData = destBmp.LockBits(pageRect,ImageLockMode.writeonly,BitmapImage.PixelFormat); var croppedRect = new Rectangle(left,top,width,height); var croppedSource = BitmapImage.LockBits(croppedRect,BitmapImage.PixelFormat); for (var y = 0; y < pageHeight; y++) for (var x = 0; x < pageWidth; x++) { if (y >= top && y <= top + height && x >= left && x <= width + left) { SetIndexedPixel(x,y,pageData,GetIndexedPixel(x - left,y - top,croppedSource) == 0 ? true : false); SetIndexedPixel(x - left,croppedSource,false); //Blank area in original } else SetIndexedPixel(x,false); //Fill the remainder of the page with white. } destBmp.UnlockBits(pageData); var retVal = new DocAppImage { BitmapImage = destBmp }; destBmp.dispose(); BitmapImage.UnlockBits(croppedSource); SaveBitmapToFileImage(BitmapImage); return retVal; }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐