天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 132|回复: 0

[每日一码] 如何查询raster image的像素值

[复制链接]
  • TA的每日心情
    开心
    昨天 06:36
  • 签到天数: 15 天

    [LV.4]偶尔看看III

    105

    主题

    11

    回帖

    1308

    积分

    管理员

    积分
    1308
    QQ
    发表于 2024-3-14 20:23:09 | 显示全部楼层 |阅读模式
    1. void AsdkGetPixelValue()
    2. {
    3. ads采用name name;
    4. ads采用point pt;
    5. Acad::ErrorStatus es;
    6. if (acedEntSel(L"\nSelect a Raster Image : ", name, pt) != RTNORM)
    7. {
    8.   return;
    9. }
    10. AcDbObjectId objId;
    11. acdbGetObjectId(objId, name);
    12. AcDbEntity * pEnt;
    13. es = acdbOpenObject(pEnt, objId, AcDb::kForRead);
    14. AcDbRasterImage *pRaster = AcDbRasterImage::cast(pEnt);
    15. if (pRaster == NULL)
    16. {
    17. pEnt->close();
    18.   return;
    19. }
    20. // Get pixel value
    21. AcGeVector2d imgSize = pRaster->imageSize();
    22. AcGeMatrix3d mat;
    23. es = pRaster->getPixelToModelTransform(mat);
    24. AcGePoint3d modpt;
    25. if (acedGetPoint(NULL, L"\nSelect point in image : ", asDblArray(modpt)) != RTNORM)
    26. {
    27.   return;
    28. }
    29. AcGePoint3d pixpt(0,0,0);
    30. pixpt = mat.inverse() * modpt;
    31. int x = (int)pixpt[0];
    32. int y = (int)pixpt[1];
    33. if ((x > imgSize.x) || (x < 0) || (y > imgSize.y) || (y < 0))
    34. {
    35. acutPrintf(L"\n*** This point is not within the image ***\n");
    36. pRaster->close();
    37.   return;
    38. }
    39. else
    40. {
    41. acutPrintf(L"\nPixel Selected: (%d, %d)", x, y);
    42. }
    43. // Get a copy of the image from the rastier image def
    44. AcDbRasterImageDef * pDef;
    45. es = acdbOpenObject(pDef, pRaster->imageDefId(), AcDb::kForWrite);
    46. Atil::Image* pImg = pDef->imageCopy();
    47. pRaster->close();
    48. pDef->close();
    49. // Find out bits per pixel of image
    50. Atil::ImageContext* imgContext = pImg->createContext(Atil::ImageContext::kRead, pImg->size(), Atil::Offset(0,0));
    51. Atil::DataModelAttributes::BitsPerPixel bpp = pImg->dataModel().bitsPerPixel();
    52. // Show pixel value
    53. switch (bpp)
    54. {
    55. case Atil::DataModelAttributes::BitsPerPixel::k1:
    56. acutPrintf(L"\nPixel value = %u\n", imgContext->get1(x,y));
    57.   break;
    58. case Atil::DataModelAttributes::BitsPerPixel::k8:
    59. acutPrintf(L"\nPixel value = %u\n", imgContext->get8(x,y));
    60.   break;
    61. case Atil::DataModelAttributes::BitsPerPixel::k16:
    62. acutPrintf(L"\nPixel value = %u\n", imgContext->get16(x,y));
    63.   break;
    64. case Atil::DataModelAttributes::BitsPerPixel::k32:
    65. acutPrintf(L"\nPixel value = %u\n", imgContext->get32(x,y));
    66.   break;
    67. case Atil::DataModelAttributes::BitsPerPixel::k64:
    68. acutPrintf(L"\nPixel value = %u\n", imgContext->get64(x,y));
    69.   break;
    70. default:
    71. acutPrintf(L"\n*** This color scale is not supported. ***\n");
    72. }
    73. //Clean up
    74. delete imgContext;
    75. delete pImg;
    76. return;
    77. }
    复制代码

     

     

     

     

    [每日一码] 如何查询raster image的像素值
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-11-1 13:38 , Processed in 0.152914 second(s), 28 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表