简体   繁体   English

客户端图像处理

[英]Client-side image processing

We're building a web-based application that requires heavy image processing. 我们正在构建一个需要大量图像处理的基于Web的应用程序。 We'd like this processing load to be on the client as much as possible and we'd like to support as much platforms (even mobiles) as much as possible. 我们希望这个处理负载尽可能地在客户端上,我们希望尽可能多地支持平台(甚至是移动设备)。

Yeah, I know, wishful thinking 是的,我知道, 一厢情愿

Here's the info: 这是信息:

  1. Image processing is rasterization from some data. 图像处理是来自某些数据的光栅化。 Think like creating a PNG image from a PDF file. 想像从PDF文件创建PNG图像。

  2. We don't have a lot of server power. 我们没有很多服务器电源。 So client-side processing is a bit of a must. 所以客户端处理是必须的。

So, we're considering: 所以,我们正在考虑:

  1. Flash - most widespread, but from what i read has lackluster development tools. Flash - 最普遍,但从我读到的开发工具乏善可陈。 (and no iPhone/iPad support for now). (目前还没有iPhone / iPad支持)。

  2. Silverlight - allows us to use .NET CLR, so a big ++ (a lot of code is in .NET). Silverlight - 允许我们使用.NET CLR,因此是一个很大的++(很多代码都在.NET中)。 But is not supported for most mobiles ( rumored android support in the future) 但大多数手机都不支持(未来传闻的Android支持)

  3. HTML5 + Javascript - probably the most "portable" option. HTML5 + Javascript - 可能是最“便携”的选项。 The problem is having to rewrite all that image processing code in Javascript. 问题是必须在Javascript中重写所有图像处理代码。

Any thoughts or architectures that might help? 任何可能有帮助的想法或架构? Clarification: I don't need further ideas on what libraries are available for Silverlight and Javascript. 澄清:我不需要进一步了解哪些库可用于Silverlight和Javascript。 My dilemma is 我的困境是

  • choosing Silverlight means no support for most mobiles 选择Silverlight意味着不支持大多数手机
  • choosing Flash means we have to redevelop most of our code AND no iPhone/iPad support 选择Flash意味着我们必须重新开发大部分代码而不支持iPhone / iPad
  • HTML5 + Javascript we have to redevelop most of our code and not fully supported yet in all browsers HTML5 + Javascript我们必须重新开发大部分代码,并且尚未在所有浏览器中完全支持
  • choosing two (Silverlight + Flash) will be too costly 选择两个(Silverlight + Flash)将太昂贵

Any out-of-the-box or bright ideas / alternatives I might be missing? 我可能会缺少任何开箱即用或明智的想法/替代方案?

This is the sort of issue that software architects run up against all the time. 这是软件架构师一直遇到的问题。 As per usual, there is no ideal solution. 按照惯例,没有理想的解决方案。 You need to select which compromise is most acceptable to your business. 您需要选择最适合您业务的折衷方案。

To summarise your problem, most of your image processing software is written in .NET. 总结一下您的问题,您的大多数图像处理软件都是用.NET编写的。 You'd like to run it client-side on mobile devices, but there is limited .NET penetration on mobiles. 您希望在移动设备上运行客户端,但移动设备上的.NET渗透率有限。 The alternatives with higher penetration (eg. Flash) would require you to re-write your code, which you can't afford to do. 具有更高渗透率的替代方案(例如Flash)将要求您重新编写代码,这是您无法承担的。 In addition, these alternatives are not supported on the iPhone/iPad. 此外,iPhone / iPad不支持这些替代方案。

What you ideally want is a way to run all your .NET code on most existing platforms, including iPhone/iPad. 您理想的是在大多数现有平台(包括iPhone / iPad)上运行所有.NET代码的方法。 I can say with some confidence that no such solution currently exists - there is no "silver bullet" answer that you have overlooked. 我可以肯定地说,目前还没有这样的解决方案 - 没有你忽略的“银弹”答案。

So what will you need to compromise on? 那你需要妥协什么? It seems to me that even if you redevelop in flash, you are still going to miss out on a major market (iPhone). 在我看来,即使你在闪存中重新开发,你仍然会错过一个主要市场(iPhone)。 And redeveloping software is extremely costly anyway. 无论如何,重新开发软件的成本非常高。

Here is the best solution to your problem - you need to compromise on your "client side execution" constraint. 这是您问题的最佳解决方案 - 您需要在“客户端执行”约束上妥协。 If you execute server side, you get to keep your existing code, and also get to deploy to just about every mobile client, including the iPhone. 如果您执行服务器端,则可以保留现有代码,并且还可以部署到几乎所有移动客户端,包括iPhone。

You said your server power is limited, but server processing power is cheap when compared to software development costs. 您说您的服务器功率有限,但与软件开发成本相比,服务器处理能力便宜。 Indeed, it is not all that expensive to outsource your server component and just pay for what you use. 实际上,将服务器组件外包并且仅为您使用的内容付费并不是那么昂贵。 It's most likely that your application will only have low penetration to start off with. 最有可能的是,您的应用程序只有较低的渗透率才能开始。 As the business grows, you will be able to afford to upgrade your server capacity. 随着业务的增长,您将能够负担得起升级服务器容量。

I believe this is the best solution to your problem. 我相信这是解决您问题的最佳方案。

Host you image processing on Amazon E2C, Azure, or Google. 在Amazon E2C,Azure或Google上托管您的图像处理。 IIRC E2C has many common image processing problems packaged and all ready to go. IIRC E2C已经打包了许多常见的图像处理问题,并且随时可以使用。

Azure probably more familiar ground in term of sharing code as a web service 在将代码共享为Web服务方面,Azure可能更为熟悉

You just pay for CPU cycles and transfers/storage etc 您只需支付CPU周期和传输/存储等费用

I'm sure there will be Silverlight and JS people posting examples. 我相信会有Silverlight和JS人员发布示例。 Here are some image editors written in actionscript: 以下是一些用actionscript编写的图像编辑器:

  1. Phoenix 凤凰
  2. PhotoshopExpress PhotoshopExpress

There is an ImageProcessing library to start with. 有一个ImageProcessing库可以开始。 Plus PixelBender is available in Flash Player 10, it's fast, it runs in a separate thread and people do some pretty mad things with it. 另外PixelBender在Flash Player 10中可用,速度很快,它在一个单独的线程中运行, 人们用它做了一些相当疯狂的事情。

HTH HTH

Some help for the Silverlight part: Silverlight部分的一些帮助:

There is an Silverlight image editor called Thumba . 有一个名为Thumba的Silverlight图像编辑器。 And Nokola recently made one called EasyPainter and he will also provide the source code in the furure. Nokola最近制作了一款名为EasyPainter的产品 ,他还将提供源代码。

For the image conversion I would recommend the open source library ImageTools that also includes some basic effects. 对于图像转换,我会推荐开源库ImageTools ,它还包括一些基本效果。 Silverlight has a class for pixel manipulation of bitmaps called WriteableBitmap. Silverlight有一个名为WriteableBitmap的位图像素处理类。 The open source library WriteableBitmapEx is a collection of extension methods for Silverlight's WriteableBitmap. 开源库WriteableBitmapEx是Silverlight的WriteableBitmap的扩展方法的集合。 The WriteableBitmap API is very minimalistic and there's only the raw Pixels array for such operations. WriteableBitmap API非常简约,只有原始像素数组才能进行此类操作。 The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods. WriteableBitmapEx试图通过扩展方法来补偿它,这些方法像内置方法一样易于使用。 Pixel Shaders can also be used to make some fast and advanced effects. 像素着色器还可用于制作一些快速和高级效果。 Although they are limited by Shader Model 2 shaders can be used for fast bluring, tinting and such things. 虽然它们受Shader Model 2限制,但着色器可用于快速模糊,着色等。

DISCLAIMER: I consider myself as an advocate of the Flash platform. 免责声明:我认为自己是Flash平台的拥护者。 I admire Silverlights huge potential as a technology to deploy almost any .NET content through the browser, but it has low penetration, is horribly marketed and -although perceived as such by many (mostly people who don't know either Flash or Silverlight)- is no competitor of Flash, as much as Flash is no competitor of Sliverlight. 我很欣赏Silverlight作为一种通过浏览器部署几乎所有.NET内容的技术的巨大潜力,但它具有低渗透率,可怕的市场营销,并且很多人(大多数不知道Flash或Silverlight的人)都认为 - 不是Flash的竞争对手,因为Flash不是Sliverlight的竞争对手。 The idealist in me loves the idea of doing everything in HTML+JS using a standard, instead of relying on 3rd party proprietary software. 我的理想主义者喜欢使用标准在HTML + JS中做所有事情,而不是依赖第三方专有软件。 But the truth is, JS is slow and the API is limited, and implementations of JS, HTML and CSS are terribly inconsistent accross browsers. 但事实是,JS很慢且API有限,并且JS,HTML和CSS的实现在浏览器中非常不一致。

If you really wanna stick to .NET and are so interested in targeting the iPhone and its siblings, then you might wanna check out MonoTouch . 如果你真的想坚持使用.NET并且对iPhone及其兄弟姐妹的目标感兴趣,那么你可能想看看MonoTouch

Still, even though this may surprise you, I am going to tell you to use Flash. 尽管如此,即使这可能让您大吃一惊,我还是会告诉您使用Flash。 :) :)

Why? 为什么? The image processing bit is the smallest part of your application. 图像处理位是应用程序的最小部分。 Whatever it is you are writing, I am very sure of that. 无论你在写什么,我都非常肯定。 I don't know about Silverlight, but in Flash the filters used by "Thumba" and "EasyPainter" can be created within a day, most of them simply using ConvolutionFilter , ColorMatrixFilter , DisplacementMapFilter and BitmapData::paletteMap or even simply by applying one of the other filters Flash offers out of the box . 我不知道Silverlight,但在Flash中,“Thumba”和“EasyPainter”使用的过滤器可以在一天内创建,大多数只使用ConvolutionFilterColorMatrixFilterDisplacementMapFilterBitmapData :: paletteMap ,甚至只需应用一个Flash提供其他过滤器开箱即用 Any additional things can be created using PixelBender, which was pointed out by George. 使用PixelBender可以创建任何其他内容,George指出了这一点。 The kernel language is a subset of C, so porting classic filters shouldn't be too time consuming. 内核语言是C的子集,因此移植经典过滤器不应该太耗时。 Also alchemy (an LLVM backend targeting Flash Player 10) would be an option worth investigating, although it's not very stable yet. 此外, alchemy (一个针对Flash Player 10的LLVM后端)将是一个值得研究的选项,尽管它还不是很稳定。

The biggest part of your app will be a lot of GUI design, GUI implementation, Business Logics etc. Flash is really great when it comes to simple, yet reasonably fast image manipulation and with the Flex framework and MXML you have a powerful tool to productively create the GUI of your app, that can interoperate very well with a multitude of server solutions for virtually any platform. 您的应用程序的最大部分将是大量的GUI设计,GUI实现,业务逻辑等。当涉及到简单但相当快速的图像处理时,Flash非常棒。使用Flex框架和MXML,您可以高效地使用它创建应用程序的GUI,可以与几乎任何平台的多种服务器解决方案很好地互操作。

Also, Flash has a great and active community, offering tons of tutorials, code snippets, libraries and frameworks, and a big ecosystem, with cross-compilation tools to deliver flash content to other platforms (including the upcoming Flash CS5 , or the mentioned Elips). 此外,Flash拥有一个强大而活跃的社区,提供大量的教程,代码片段,库和框架,以及一个庞大的生态系统,使用交叉编译工具将Flash内容提供给其他平台(包括即将推出的Flash CS5 ,或者提到的Elips )。 I don't understand, where you got the impression, that the Flash platform lacks developement tools. 我不明白,你得到的印象是,Flash平台缺乏开发工具。 The difference to the .NET suite is that they are provided by a multitude of vendors. .NET套件的不同之处在于它们是由众多供应商提供的。 The upcoming Flash Player 10.1 was already pointed out by George, but never the less, I wanted to stress, that this makes many of the cross-plattform considerations obsolete. 乔治已经指出即将推出的Flash Player 10.1,但我想强调的是,这使得许多跨平台的考虑因素过时了。

Last but not least, I'd like to point out Haxe . 最后但同样重要的是,我想指出Haxe It allows compiling to SWF, but also to C++, using the very same API provided by NME , to target the iPhone . 它允许编译为SWF,但也允许使用NME提供的相同API编译目标iPhone Also there's work in progress on an android backend. 还有一个Android后端的工作正在进行中。 If you're aren't playing to launch within the next 4-5 months, then this is definitely an option. 如果你不打算在接下来的4-5个月内推出,那么这绝对是一个选择。

Your issue is a perfect target for the Haxe programming language. 您的问题是Haxe编程语言的完美目标。 Haxe is written for the web and can compile to JavaScript, Flash and Objective-C (possibly Java/.NET soon). Haxe是为Web编写的,可以编译为JavaScript,Flash和Objective-C(很快可能是Java / .NET)。 So you do not choose which platform you are going to invest in but in which language. 因此,您不会选择要投资的平台,而是使用哪种语言。 Haxe is easily adoptable for an AcitonScript programmer. Haxe很容易被AcitonScript程序员采用。

It makes no sense to run your imageprocessing algorithms in a JavaScript sandbox when Flash is available because it will be much faster. 当Flash可用时,在JavaScript沙箱中运行图像处理算法是没有意义的,因为它会更快。 It makes also no sense to run heavy image processing algorithms on a mobile device like the iPhone with JavaScript. 使用JavaScript在iPhone等移动设备上运行繁重的图像处理算法也没有意义。 I would only support JavaScript as the worst fallback solution. 我只支持JavaScript作为最差的后备解决方案。

If you do not like to use Haxe I would go with Flash. 如果你不喜欢使用Haxe,我会使用Flash。 You can deploy your Flash application for the iPhone aswell if that is your problem. 如果这是您的问题,您可以为iPhone部署Flash应用程序。 This is also very great because you get native ARM code. 这也非常好,因为您获得了本机ARM代码。 There are actually great tools for professional Flash development available. 实际上有很多专业Flash开发工具可用。 FDT and IntelliJ IDEA are two of them. FDTIntelliJ IDEA是其中两个。 The best Haxe IDE is probably FlashDevelop at the moment of writing. 在写作的那一刻,最好的Haxe IDE可能就是FlashDevelop

So I would definitly not use JavaScript as the only solution. 所以我绝对不会使用JavaScript作为唯一的解决方案。 Haxe is perfect for what you try to achieve. Haxe非常适合您尝试实现的目标。 If you do not trust or do not want to invest in Haxe you can use Flash because of the iPhone/iPad export . 如果您不信任或不想投资Haxe,您可以使用Flash,因为iPhone / iPad导出

Depending on your usecase I would also encourage you to look at cloud hosting like Amazon EC2 and Google AppEngine for instance. 根据您的用例,我还鼓励您查看Amazon EC2和Google AppEngine等云托管。 Hosting costs are cheap and scaling will be easy for your task. 托管成本很便宜,并且您的任务可以轻松扩展。 The experience will be much better when it comes to complex operations that can take even a lot of time on a desktop system. 当涉及复杂的操作时,体验会更好,这可能会花费很多时间在桌面系统上。

In addition to other answers, another option may be a hybrid solution. 除了其他答案,另一种选择可能是混合解决方案。 For example, use Flash/Silverlight for the majority of your target audience and use server-side processing for those that don't support it (or you could create a native app for iP[hone|ad]) 例如,对大多数目标受众使用Flash / Silverlight,对不支持它的用户使用服务器端处理(或者您可以为iP [hone | ad]创建本机应用程序)

You may have to do something like this anyway as the mobiles you are targetting may have insufficient processing power depending how complex your image processing gets. 你可能不得不做这样的事情,因为你所针对的手机可能没有足够的处理能力,这取决于你的图像处理有多复杂。

Of course you still have the option of upgrading your server which, although you've currently discounted, is probably far cheaper than spending development time creating/deploying/testing a client-side solution. 当然,您仍然可以选择升级您的服务器,虽然您目前已经打折,但可能比花费开发时间创建/部署/测试客户端解决方案要便宜得多。

You can use Silverlight for all Silverlight enabled clients and for non Silverlight clients, do the image processing server side. 您可以将Silverlight用于所有启用Silverlight的客户端,对于非Silverlight客户端,可以使用图像处理服务器端。 Since the Silverlight code is C#, you can double compile it to make (mostly)the same code work as Silverlight and non-Silverlight (ie server). 由于Silverlight代码是C#,您可以对其进行双重编译以使(大部分)代码与Silverlight和非Silverlight(即服务器)相同。 This gets you the best of both worlds. 这将为您带来两全其美。

You don't say what language "all that code" you'd have to rewrite is in. Might a semiautomated translation to Javascript be practical? 你没有说你需要重写的“所有代码”是什么语言。对Javascript的半自动翻译是否可行?

Perhaps you could start out server-side, as CraigS suggests, and then move functions into the client over time instead of rewriting all at once. 也许你可以像CraigS建议的那样从服务器端开始,然后随着时间的推移将功能移到客户端而不是一次性重写所有功能。

Have you checked the editor of Pixlr.com ? 你检查过Pixlr.com编辑吗?
Take a look at their API as well.. 看看他们的API也是..

The best solution is to use silverlight (so you already have the code ready). 最好的解决方案是使用silverlight(因此您已准备好代码)。 If the client can't run it (mobile phones, etc) then process it server-side. 如果客户端无法运行它(手机等),则在服务器端处理它。

It's the best compromise. 这是最好的折衷方案。

Depends on the type of image processing and the end user experience you are targeting. 取决于您要定位的图像处理类型和最终用户体验。

As you are looking to target mobile phones your image processing will need to take into consideration the type of handset the user or the receipient has (if messaging via SMS/MMS), as different handsets have different resolution screens and handle different image formats for main images and thumbnails. 当您希望定位移动电话时,您的图像处理需要考虑用户或收件人的手机类型(如果通过短信/彩信发送),因为不同的手机具有不同的分辨率屏幕并处理不同的主要图像格式图像和缩略图。

I'd suggest that you consider a hybrid cloud architecture as was mentioned in the Microsoft PDC keynotes this year. 我建议你考虑今年微软PDC主题演讲中提到的混合云架构。 This would enable you to have your own server(s) to support your application, but if you require additional capacity due you scale out into the cloud using AppFabric. 这将使您拥有自己的服务器来支持您的应用程序,但如果您需要额外的容量,则可以使用AppFabric扩展到云端。

Additionally, to maximise the market availability of your product pulling the image processing to a common reusable infrastructure allows you to target different platforms, exploiting the positives in each. 此外,为了最大限度地提高产品的市场可用性,将图像处理功能扩展到通用的可重用基础架构,您可以针对不同的平台,利用每个平台的积极因素。

I have worked on a solution that hosted its image processing and delivery infrastructure server side and then built different UI offerings allowing sales via desktops, MNOs and AppStores. 我曾致力于一个托管其图像处理和交付基础设施服务器端的解决方案,然后构建了不同的UI产品,允许通过桌面,MNO和AppStore进行销售。 It can work and from a business perspective can offer economies of scale benefits. 它可以工作,从商业角度来看,可以提供规模经济效益。

Why not mention Java Applet ? 为什么不提Java Applet?

Good sides are: 好的方面是:

almost all browser support ? 几乎所有浏览器支持? need install JRE ? 需要安装JRE吗? all OS support Java provide Java Advanced Image kits, but if c++ dll can be called, that is best (JNI can call c++ dll ) 所有操作系统支持Java提供Java高级映像工具包,但如果可以调用c ++ dll,那就最好(JNI可以调用c ++ dll)

The way I see it, there's no one solution that meets all of your needs. 我认为,没有一种解决方案可以满足您的所有需求。 Your best option, imo, is to go with Flash and hope that Adobe sets an agreement with Apple to get Flash on the iPhone/iPad. 你最好的选择,imo,是与Flash一起使用,希望Adobe与Apple达成协议,在iPhone / iPad上安装Flash。 The major downside, of course, is you'll have to rewrite much of your code. 当然,主要的缺点是你必须重写大部分代码。

If the mobile sector isn't absolutely critical, then choose the Silverlight option for reasons you mentioned already. 如果移动扇区不是绝对关键,那么请选择Silverlight选项,原因就在于您提到的原因。 You could also use Silverlight in an out-of-browser mode to work as a desktop application. 您还可以在浏览器外模式下使用Silverlight作为桌面应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM