将ImageSnapshot转换为Flex中的图像

时间:2023-01-15 22:56:10

Using Flex 3, I would like to take an image snapshot such as this:

使用Flex 3,我想拍摄如下图像快照:

var logoSnapshot:ImageSnapshot = ImageSnapshot.captureImage(logoContainer);

and turn it into something that the Image class can use. I see that there is a property called "data", that holds a byteArray, so I guess my question is: How do I take an image that gets stored as a byteArray and convert it to something the Image class can use to display?

并将其转换为Image类可以使用的内容。我看到有一个名为“data”的属性,它包含一个byteArray,所以我想我的问题是:如何将一个存储为byteArray的图像转换为Image类可用于显示的内容?

4 个解决方案

#1


Simpler implementation that should work:

应该更简单的实现:

var bm : Bitmap = new Bitmap(ImageSnapshot.captureBitmapData(logoContainer));

Set "bm" as the source of your Image object.

将“bm”设置为Image对象的源。

#2


The BitmapData class has:

BitmapData类具有:

public function setPixels(rect:Rectangle, inputByteArray:ByteArray):void

Set the rectangle to be the size of your image, and then send in the byteArray.

将矩形设置为图像的大小,然后发送byteArray。

You should then be able to draw the BitmapData to your screen.

然后,您应该能够将BitmapData绘制到屏幕上。

#3


It takes a few steps, but it isn't hard.

它需要几个步骤,但并不难。

  1. Draw your ByteArray to a BitmapData instance using setPixels().

    使用setPixels()将ByteArray绘制到BitmapData实例。

  2. Create a new BitmapAsset instance, and pass in your BitmapData.

    创建一个新的BitmapAsset实例,并传入您的BitmapData。

  3. Pass the BitmapAsset to your Image control's source property.

    将BitmapAsset传递给Image控件的source属性。

This assumes that your ByteArray is compatible with setPixels(). According to the docs, it needs to be a set of unsigned ints representing 32-bit ARGB values. If the ByteArray holds the image in another format, you'll have to find different way. If you're lucky, it'll be encoded as JPG, PNG, or GIF, and you'll be able to pass the ByteArray directly to source on the Image, and Flash Player will already know how to interpret it.

这假设您的ByteArray与setPixels()兼容。根据文档,它需要是一组代表32位ARGB值的无符号整数。如果ByteArray以另一种格式保存图像,则必须找到不同的方式。如果你很幸运,它将被编码为JPG,PNG或GIF,你将能够直接将ByteArray传递给Image上的源代码,而Flash Player已经知道如何解释它。

#4


You can actually just set the ByteArray directly as the source property of the Image class in the current Flex SDK.

实际上,您可以直接将ByteArray设置为当前Flex SDK中Image类的source属性。

#1


Simpler implementation that should work:

应该更简单的实现:

var bm : Bitmap = new Bitmap(ImageSnapshot.captureBitmapData(logoContainer));

Set "bm" as the source of your Image object.

将“bm”设置为Image对象的源。

#2


The BitmapData class has:

BitmapData类具有:

public function setPixels(rect:Rectangle, inputByteArray:ByteArray):void

Set the rectangle to be the size of your image, and then send in the byteArray.

将矩形设置为图像的大小,然后发送byteArray。

You should then be able to draw the BitmapData to your screen.

然后,您应该能够将BitmapData绘制到屏幕上。

#3


It takes a few steps, but it isn't hard.

它需要几个步骤,但并不难。

  1. Draw your ByteArray to a BitmapData instance using setPixels().

    使用setPixels()将ByteArray绘制到BitmapData实例。

  2. Create a new BitmapAsset instance, and pass in your BitmapData.

    创建一个新的BitmapAsset实例,并传入您的BitmapData。

  3. Pass the BitmapAsset to your Image control's source property.

    将BitmapAsset传递给Image控件的source属性。

This assumes that your ByteArray is compatible with setPixels(). According to the docs, it needs to be a set of unsigned ints representing 32-bit ARGB values. If the ByteArray holds the image in another format, you'll have to find different way. If you're lucky, it'll be encoded as JPG, PNG, or GIF, and you'll be able to pass the ByteArray directly to source on the Image, and Flash Player will already know how to interpret it.

这假设您的ByteArray与setPixels()兼容。根据文档,它需要是一组代表32位ARGB值的无符号整数。如果ByteArray以另一种格式保存图像,则必须找到不同的方式。如果你很幸运,它将被编码为JPG,PNG或GIF,你将能够直接将ByteArray传递给Image上的源代码,而Flash Player已经知道如何解释它。

#4


You can actually just set the ByteArray directly as the source property of the Image class in the current Flex SDK.

实际上,您可以直接将ByteArray设置为当前Flex SDK中Image类的source属性。