位图锁定位16bpp [英] Bitmap lockbits 16bpp

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

问题描述

大家好.我很难理解为什么这会在保存创建的位图时向我抛出错误.有人可以帮助以下代码吗?

Hello everybody. I struggle to understand why this is throwing me an error while saving created bitmap. Could anybody help with the following code?

Bitmap ^a=gcnew Bitmap(width,height,System::Drawing::Imaging::PixelFormat::Format16bppGrayScale);
    int i,j;
    BitmapData ^bitmapData=gcnew BitmapData();
    float value;
    System::Drawing::Rectangle b(0,0,width,height);
    a->LockBits(b, System::Drawing::Imaging::ImageLockMode::WriteOnly, a->PixelFormat, bitmapData);
    unsigned short int *ptr=(unsigned short int*)bitmapData->Scan0.ToPointer();
    int stride=bitmapData->Stride;

    for (i=0;i<height;i++)
    {
        unsigned short int * LinePtr = ptr + (i * height);
        for(j=0;j<width;j++)
        {
            //value=mat[j][i];
            LinePtr[j]=0;//65535*value/255;
        }
    }
    a->UnlockBits(bitmapData);
    return a;

推荐答案

Hmm才刚刚实现.高度为600的图像跨度为1600,而1600/600不是十进制数.16bpp应该产生的跨度600 * 2字节等于1200.对吗?所以我想位图类可能出于性能原因在每条扫描线的末尾放置了一些虚构"的像素数据?但是我仍然不知道该怎么办...
Hmm just now a realized something. Image stride for height 600 is 1600 while 1600/600 is not decimal number.And 16bpp should produce stride 600*2 in bytes equals 1200. Am i right ? So i guess bitmap class is putting some "imaginary" pixel data at the end of each scan line maybe for performance reasons? But I still dont know what to do with that ...


但是需要帮助,但是不是这样,当然,我的第一个猜测是LinePtr = ptr +(i *大步向前);但是跨度是一行字节,并且由于我的变量是short int类型的,而int具有3个字节,因此i * height似乎是正确的答案,两者都不起作用.我现在正在做的是,我有24 bpp rgb图像,并且我在每个颜色槽"中都放置了相同的数字,这并不是很优雅,并且需要时间.什么是更好的方法?
thanks for help however that''s not the case , of course my first guess was LinePtr = ptr + (i * stride); however stride is one row in bytes and since my variable is typed short int which have 3 bytes than for that purpose i*height seemed right answer neither is working. What i am doing now is that i have 24 bpp rgb image and i put same number in each "color slot" now thats not very elegant and it takes time. What would be the better way ?


否定的?我理解正确吗?以字节为单位的信息量如何为负.因此,我想没有比在每个Chanel中写入相同值的RGB更好的编码灰度的方法了.可惜...还是要谢谢
Negative ?? Do i understand it correctly? How can amount of information in bytes be negative. So i guess than there is no better way to code grayscale than to write to rgb same value in each Chanel. Pity ... thanks anyway


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

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