指向图像的指针 [英] pointer refrence to images

查看:95
本文介绍了指向图像的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我想使用位图,指针和不安全的方法编写计算距离变换算法",但是当指针指向不属于我的图像的像素时,我不知道如何实现.
这是我的一些代码;在运行时,出现下划线的异常:访问冲突异常".如何解决?另一方面,如何控制指针? BitmapData bmdata = bm.LockBits(新Rectangle(0,0,bm.Width,bm.Height),ImageLockMode.ReadWrite,PixelFormat.Format24bppRgb);

Hello,
I want to write "calculating distance transform algorithm" by using bitmap, pointers and unsafe method, but I don''t know how to realize when the pointer refers to the pixel not belonging to my image.
Here is some of my codes; when running,I got the exception: ''Access Violation Exception'' on the underlined line.how can I solve it? On the other hand, how can I control the pointer? BitmapData bmdata = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

BitmapData bmdata = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
           IntPtr scan0 = bmdata.Scan0;
           int stride = bmdata.Stride;
           unsafe
           {
               byte* p = (byte*)(void*)scan0;
               byte*t=null;
               int g;
               int offset = stride - (bm.Width * 3);
               for (i = 0; i < bm.Height; i++)
               {
                   for (j = 0; j < bm.Width; j++)
                   {


                          t = p - n3 - (stride * (n - 1));
                          if(t[0]=255)                          {

                          g++;
                          }

                       p += 3;
                   }
                   p += offset;
               }
           }
           bm.UnlockBits(bmdata);
            return bm;

推荐答案

我不知道如何实现当指针指向不属于我的图像的像素时.

您需要某种方式来获取图像的位置和大小.首先,您从哪里获取指针,以及指针到底指向什么.
I don''t know how to realize when the pointer refers to the pixel not belonging to my image.

You need some way of obtaining the position and size of the image. Where are you getting the pointer from in the first place, and exactly what is it pointing at.


这篇关于指向图像的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆