更改图像颜色
我正在开发一个项目,用户可以在购物车中为商品选择某种颜色。
问题是有大量的颜色可供选择,但制造商只提供了一张产品图片。现在我需要想出一种根据用户选择改变该产品颜色的方法。这与汽车制造商网站上的内容非常相似……当您单击某种颜色时,图像就会更新为该颜色。
有什么想法如何实现这一目标吗?
注意:我最初的想法是使用 Photoshop 生成一个透明图像,该图像仅具有产品的阴影细节(并且周围区域是实心/不透明的),然后以编程方式将此透明图像与具有所选颜色的另一个图像合并。理论上它是可以完成的...我只是想知道是否有人之前已经这样做过和/或是否有更好的方法...比如也许使用 Photoshop 滤镜等:)
I am working on a project where in the shopping cart a user can select a certain color for an item.
The problem is there are tons of color choices available but the manufacturer has only provided with one product image. Now I need to come up with a way to change the color of this product based on user selection. This is pretty similar to going on car manufacturers website ... when you click on a color the image is updated with that color.
Any ideas how to go about accomplishing this?
Note: My initial thought was to use photoshop to comeup with a tranparent image which only has shadow details of the produc (and the surrounding areas are solid/opaque) and then programatically merge this transparent image with another image with the selected color. Theoratically it can be done ... I am just wanting to know if someone has already done this before and/or if there is a better way ... like perhaps using photoshop filters etc :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在考虑的可能是最好的选择。并且不要在服务器端合并图像(假设它是 Asp.net 代码),而是使用 javascript 将图像放置在主图像上。最好的方法是加载所有彩色图像和主图像,并将彩色图像放置在主图像上。使用 PNG 格式可获得更好的透明图像。
当您知道有固定数量的颜色选项时,您不必每次每个用户更改颜色时都使用服务器资源。
The one you are thinking is probably best option to do. And instead of merging the image on server side (assuming it is Asp.net code) use javascript to place the image over main image. best way is to load all colored image and main image and place colored image over main impage. Use PNG format for better transparent images.
You dont have to use server resource everytime each user change the color when you know you have fixed number of color options.
如果需要着色的部分在色调方面在原件中是唯一的(并且您可以通过 Photoshop 或其他工具在源图像中更改它来使其唯一),那么这应该可以解决问题。它的工作原理是锁定输入位图(以便可以操纵每个像素),然后将每个像素转换为 HSB,以便可以调整像素的色调(“颜色”)如果落在某个范围内色调范围。这将产生很好的效果,因为诸如阴影和轻微差异之类的渐变也将被正确着色。
着色代码:
...
HSBColor.cs(来自 ZedGraph):
If the part that needs to be colored is unique in the original in terms of hue (and you could make it unique by changing it in the source image through Photoshop or something), this should do the trick. It works by locking an input bitmap (so each pixel can be manipulated) and then converting each pixel to HSB so that hue (the "color") of the pixel can be adjusted if it falls within a certain range of hues. This will have a nice effect because gradients such as shadow and slight variances will also be colorized correctly.
Colorizing code:
...
HSBColor.cs (from ZedGraph):
Scene7 可以为您完成此操作,但成本相当高。
Scene7 does this for you but it's pretty costly.
您可以使用
ColourMap[]
数组相当轻松地将一个图像中的颜色映射到一组新的颜色 - 问题在于源颜色和目标颜色。我使用这样的代码和具有各种 alpha 透明度级别的单色(黑色)贴图(尽管您可以以相同的方式使用灰度图像),然后将比例中的每种颜色映射到新比例:
这有效非常适合简单的图标,但您可能需要相当复杂的地图来处理任何照片质量的东西。
You can map the colours in one image to a new set of colours fairly easily with an array of
ColourMap[]
- the problem is the source colours and the destination colours.I use a code like this with a map of a single colour (black) with various alpha levels of transparency (though you could use a greyscale image in the same way), then map every colour in the scale to the new scale:
This works great with simple icons, but you may need quite a complicated map to deal with anything photo-quality.