首页 \ 问答 \ 在Javascript中将对象转换为缓冲区(Converting an object to a buffer in Javascript)

在Javascript中将对象转换为缓冲区(Converting an object to a buffer in Javascript)

我没有使用节点,只是在浏览器中使用简单的Javascript

我需要有效地向网络工作者发送数据。 我已经设法弄清楚如何从数组创建缓冲区:

// assume it contains integers
var numbers = new Int8Array(10); 

// works
const data = {buffer: numbers.buffer};
worker.postMessage(data, [data.buffer]);

但是我们假设我有一个如下所示的对象:

var myObject = {'in': [0.123,-0,521], 'out' : [1.409]};

我如何将其转换为缓冲区? 我发现了许多类似的问题,但他们似乎使用Node ,我没有使用。


I'm not using node, just plain Javascript in the browser

I need to efficiently send data to webworkers. I've managed to figure out how to create buffers from arrays:

// assume it contains integers
var numbers = new Int8Array(10); 

// works
const data = {buffer: numbers.buffer};
worker.postMessage(data, [data.buffer]);

But let's assume I have an object that looks like the following:

var myObject = {'in': [0.123,-0,521], 'out' : [1.409]};

How would I convert that to a buffer? I've found numerous similar questions but they seem to use Node, which i'm not using.


原文:https://stackoverflow.com/questions/44824553
更新时间:2022-07-10 14:07

最满意答案

$config = array(
'source_image' => $upload_path.$image_data['file_name'],
'maintain_ratio' => FALSE,
'width' => 220,
'height' => 150,
'x_axis' => 350,
'y_axis' => 50
);
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->crop();

欲了解更多详情,请参阅此处了解更多信息查看此处


$config = array(
'source_image' => $upload_path.$image_data['file_name'],
'maintain_ratio' => FALSE,
'width' => 220,
'height' => 150,
'x_axis' => 350,
'y_axis' => 50
);
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->crop();

For more details Please See Here For More Info Check Here

相关问答

更多
  • 它看起来像你的目标图像与源图像大小相同。 如果你想旋转90度以上,你的宽度和高度应该交换: WriteableBitmap wb = new WriteableBitmap(destHeight, destWidth); 另外,如果您围绕原始图像的中心旋转,则其一部分会在边界之外结束。 您可以包含一些翻译转换,或者简单地将图像旋转到不同的点: rt.CenterX = rt.CenterY = Math.Min(width / 2, height / 2); 用一张长方形纸试一下,看看为什么这是有道理的 ...
  • 您的给定Codeigniter代码是正常的,除了一个逻辑:您正在操作并输出到同一图像文件两次,因此您的输出文件会被最后一次更改原始文件所覆盖。 我相信这是CI的Image_Lib类的限制,因为每个操作都是单独完成的 - 没有办法一次性“调整大小和裁剪”。 您必须在每个操作之间重新初始化Image_Lib类,以确保在上一个操作的输出文件上调用下一个操作。 $img_config = array( 'source_image' => $src, 'new_image' ...
  • 也许存在一个错误。 检查错误: if (!$this->image_lib->resize()){ echo $this->image_lib->display_errors(); } 注意:使用gd2作为库(默认值为gd2): $config['image_library'] = 'gd2'; Maybe exists an error. Check for errors: if (!$this->image_lib->resize()){ echo $this->image_lib- ...
  • $config = array( 'source_image' => $upload_path.$image_data['file_name'], 'maintain_ratio' => FALSE, 'width' => 220, 'height' => 150, 'x_axis' => 350, 'y_axis' => 50 ); $this->image_lib->clear(); $this->image_lib->initialize($config); $this->image_lib->cro ...
  • 此外,您可以在左上角尝试使用此代码进行硬裁剪 add_image_size( 'custom-size', 220, 220, array( 'left', 'top' ) ); Also, you can try this code for hard crop in left top add_image_size( 'custom-size', 220, 220, array( 'left', 'top' ) );
  • 我尝试使用您的代码并遇到了类似的问题。 使用https://rubyplus.com/articles/3951-Cropping-Images-using-jCrop-jQuery-plugin-in-Rails-5教程中的代码为我工作,它应该像下面的标准jQuery一样: var ImageCropper, bind = function(fn, me){ return function(){ return fn.apply(me,arguments); }; }; jQuery(function( ...
  • 为了记录的缘故 - Cocoa Controls上的现成组件 http://cocoacontrols.com/platforms/ios/controls/imagecropper For record's sake - A ready made component on Cocoa Controls http://cocoacontrols.com/platforms/ios/controls/imagecropper
  • 在你的情况下你使用了错误的功能。 imagecopyresampled可以改变图像的大小。 对于作物功能,最佳选择是图像imagecopy 试试改变这个 $result = @imagecopy($cropped, $image, 0, 0, $x1, $y1, $nw, $nh) or die("error imagecopy()"); 功能图像复制手册 In your case you used incorrect function. imagecopyresampled can chang ...
  • 创建一个UIImage类别并尝试添加它。 @implementation UIImage(Crop) - (UIImage *)crop:(CGRect)cropRect { cropRect = CGRectMake(cropRect.origin.x*self.scale, cropRect.origin.y*self.scale, cropRect.size.width*self.scale, ...
  • 使用以下设置: {dragCrop:true,multiple:true,movable:true} use following settings: {dragCrop:true, multiple:true, movable:true}

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的