作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
为了规避 Windows 8 系统上 Actionscript Camera API 的一些(很多)问题,我决定创建一个本地扩展来处理相机。
现在,相机部分和所有与 AIR Runtime 通信的胶水实际上都在工作,因此在 AIR 中单击一个按钮将打开一个新的 Windows 窗口,该窗口将返回一个 System::Drawing::Bitmap。
我现在的任务是
a) 创建一个 FREBitmapData 对象并
b) 从 Windows 位图中填写位图数据。
应该很容易,我想,很多天前......因为我不太熟悉 C++,所以我根本没有让它工作。
到目前为止,这是我尝试过的:
bmp = form1->bitmap; // bmp is a handle to the System::Drawing::Bitmap returned from the external window
// Lock the bitmap's bits.
Rectangle rect = Rectangle(0, 0, bmp->Width, bmp->Height);
System::Drawing::Imaging::BitmapData^ bmpData = bmp->LockBits(rect, System::Drawing::Imaging::ImageLockMode::ReadWrite, bmp->PixelFormat);
// Get the address of the first line.
IntPtr ptr = bmpData->Scan0;
// Declare an array to hold the bytes of the bitmap.
// This code is specific to a bitmap with 24 bits per pixels.
int inputLength = Math::Abs(bmpData->Stride) * bmp->Height;
array<Byte>^ input = gcnew array<Byte>(inputLength);
// Copy the RGB values into the array.
System::Runtime::InteropServices::Marshal::Copy(ptr, input, 0, inputLength);
// Unlock the bits.
bmp->UnlockBits(bmpData);
// Create a FREByteArray to hold the data.
// Don't know, if this is necessary
FREObject* outputObject;
FREByteArray* outputBytes = new FREByteArray;
outputBytes->length = inputLength;
outputBytes->bytes = (uint8_t *) &input;
FREAcquireByteArray(outputObject, outputBytes);
// now copy it over
memcpy(outputBytes->bytes, &input, inputLength);
FREReleaseByteArray(outputObject);
// we create a new instance of BitmapData here,
// as we cannot simply pass it over in the args,
// because we don't know it's correct size at extension creation
FREObject* width;
FRENewObjectFromUint32(bmp->Width, width);
FREObject* height;
FRENewObjectFromUint32(bmp->Height, height);
FREObject* transparent;
FRENewObjectFromBool(uint32_t(0), transparent);
FREObject* fillColor;
FRENewObjectFromUint32(uint32_t(0xFFFFFF), fillColor);
FREObject obs[4] = { width, height, transparent, fillColor };
// we create some Actionscript Intsances here, we want to send back
FREObject* asBmpObj;
FRENewObject("BitmapData", 4, obs, asBmpObj, NULL);
// Now we have our AS bitmap data, copy bytes over
FREBitmapData* asData;
FREAcquireBitmapData(asBmpObj, asData);
// Now what? asData->bits32 won't accept array<Bytes> or any other value I've tried.
return asBmpObj;
基本思路是:
a) 找出原始 Win Bitmap 的大小和位深度(大小由在 Camera 窗口中选择的 cam 分辨率决定)
b) 将它的字节写入一个数组。根据需要转换为 32 位。 (仍然缺少任何想法。)
c) 创建相同大小的 AS 位图。位深度必须始终为 32。
d) 将数组复制到 AS 位图。
但我就是做不到这一点。有什么建议吗?谢谢!
最佳答案
我认为下面的直接复制行不通。
// Copy the RGB values into the array.
System::Runtime::InteropServices::Marshal::Copy(ptr, input, 0, inputLength);
您必须逐个像素地转换。我不知道如何将它转换为 FREBitmapData。以下是您可以关注的示例 on msdn
关于c++ - 如何在 C++ 中将 Windows 位图转换为 Actionscript 位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26400984/
我是一名优秀的程序员,十分优秀!