Rails Flex接口 保存Flex传来的bytearray

	   open( "path999801.png", 'wb' ) do |fo|
byteArray[:pngBytes].pack('c*').each do |byte|
logger.debug("Hello Tommie#{byte} ")
fo<<byte
end
end

dt=Time.now()
path=RAILS_ROOT+"/public/images/snapshot/#{"snapshot"+dt.strftime('%Y%m%d%H%M%S')}.png"
fout = File.open( path, 'wb' );
data = byteArray[:pngBytes].pack('c*');
fout.puts(data);
fout.close
snap=Livesnap.new()
snap.update_attributes(:path=>path,:create_dt=>dt)



其中,对应pack和unpack的含义如下:

[quote] a = [ "a", "b", "c" ]
n = [ 65, 66, 67 ]
a.pack("A3A3A3") #=> "a b c "
a.pack("a3a3a3") #=> "a\000\000b\000\000c\000\000"
n.pack("ccc") #=> "ABC"

Directives for pack.

Directive Meaning
---------------------------------------------------------------
@ | Moves to absolute position
A | ASCII string (space padded, count is width)
a | ASCII string (null padded, count is width)
B | Bit string (descending bit order)
b | Bit string (ascending bit order)
C | Unsigned char
c | Char
D, d | Double-precision float, native format
E | Double-precision float, little-endian byte order
e | Single-precision float, little-endian byte order
F, f | Single-precision float, native format
G | Double-precision float, network (big-endian) byte order
g | Single-precision float, network (big-endian) byte order
H | Hex string (high nibble first)
h | Hex string (low nibble first)
I | Unsigned integer
i | Integer
L | Unsigned long
l | Long
M | Quoted printable, MIME encoding (see RFC2045)
m | Base64 encoded string
N | Long, network (big-endian) byte order
n | Short, network (big-endian) byte-order
P | Pointer to a structure (fixed-length string)
p | Pointer to a null-terminated string
Q, q | 64-bit number
S | Unsigned short
s | Short
U | UTF-8
u | UU-encoded string
V | Long, little-endian byte order
v | Short, little-endian byte order
w | BER-compressed integer\fnm
X | Back up a byte
x | Null byte
Z | Same as ``a'', except that null is added with *[/quote]


private function onSnapshot():void
{
var snapshot:ImageSnapshot = ImageSnapshot.captureImage(_traceBox);

messageService.save_snapshot.send({image_buffer:_imageBuffer});
}

private function onSaveSnapshot(event:ResultEvent):void
{
if(event.result.hasOwnProperty("success"))
{
if(event.result.success == true)
{
if(event.result.hasOwnProperty("file"))
{
trace("Save file \"" + event.result.file + "\" successfully.");
}
}
}

trace("Save file failed");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值