Programmatically change PNG / PSD image colour in .Net - c#

I have a number of web controls, which are made up of png images. The simplest is a button.
I need to be able to generate these controls with different colours depending on the colour selected by the client.
The images are .PSD files, layered before exporting to png.
My idea was to allow the client to pick one colour and use a layer filter in the psd to change the overall colour of the image and programmatically export the .PSD to PNG on the server. I looked into using the Photoshop CS Interface via COM, but haven't got my head around it, has anyone else used it for a similar task?
Alternatively I could read the png into memory and perform colour replacement, but this seems really complex for what reads like a simple(ish) task.
Many thanks in advance

.PSD is quite complicated and poor documented file format, that is constantly receiving new features from Adobe, so editing them is no way an easy task.
One way is to use Photoshop batch processing, which means photoshop installed on server, but as long you you wished to make that through COM, it should not be a problem.
One of the starting points may be: http://www.webdesignerdepot.com/2008/11/photoshop-droplets-and-imagemagick/
Another way would be to try composite layers using c#, that means you would have some layers ready (textures/borders/etc), some would be created at runtime and all those layers would be merged at runtime using c#.

Related

Is it possible to programmatically manipulate a psd file's layers in WPF?

I have a Photoshop Document with a few layers that I can turn on and off to make the image display different data. Is it possible to place this image in a WPF page and use C# to turn on and off layers? I've been googling for a little while but there doesn't seem to be much information on this subject. I read that you might be able to use Expression Blend to do this, however I do not have any experience using it.
Any help would be greatly appreciated, thanks!
(Disclaimer: I'm a software engineer at Microsoft, I used to work on Expression Blend)
In short, no. There is no built-in support for loading Photoshop files in the .NET Framework nor WPF (this is despite Blend's support for loading PSD documents into a project - it has its own code for this - and it doesn't support all of the features present in the PSD file format either).
If you want to load a PSD file into your own program you'll need a PSD file reader - either write your own (a fool's errand considering how complicated the file format is) or obtain/license an existing library, there are open-source implementations available (see Paint.NET's).
A problem with PSD files is that individual layers are not necessarily simple rasters by themselves, and PSD documents don't always contain a full-resolution composite either. Consider effects-layers (Brightness, Levels, etc) or layer-effects (Outer Glow, Gradient Overlay, etc).
I suggest instead having Photoshop (via an Action or a Droplet program) convert your PSD's layers to individual PNG files (after applying any effects) and then loading those into your program and displaying them according to your requirements.

layering PDFs together and have ability to set the position

I'm being tasked to enhance the way we create custom brochures, the old way we had a legacy system create the needed pdfs and then I would download those and "glue" them into one big pdf.
the new one way we want to go about this is to skip the legacy system and build all of these things from our new system.
The biggest hurdle is the cover, which consists of the background layer, and then the logo layer which has the company logo, a shadowbox and an emblem. all of these objects are pdf documents.
my problem is after I build the logo portion, how will I be able to position the pdf exactly where I need it on the background layer?
this is all being done on the fly so I can't save anything to disk.
any help will be greatly appreciated.
There are several PDFsharp samples that show how to do it:
http://pdfsharp.net/wiki/XForms-sample.ashx
http://pdfsharp.net/wiki/Graphics-sample.ashx#Draw_a_form_XObject_a_page_from_an_external_PDF_file_27
http://pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx
You can draw pages from other PDF files like images on a newly created PDF page. You can specify the exact positions and sizes, you can even transform them (skew them, rotate them).

Removable Images in PDF

I'm writing a ASP.NET program that inserts PNG images into a PDF. Ideally, I'd like to give users the option to undo this action later on.
I'm currently using the PDFSharp library to add the images, which is working fine, but I can't find anyway to then remove them. I've looked into the annotation functionality a little bit, but as far as I can tell there's no way to use custom images.
Does anyone have any experience or insight into this issue? Thanks.
The PDF format is final presentation format not really designed for this kind of modifications, it is possible to do this with other libraries, but for your particular case I would recommend instead keeping a copy of the original file rather than trying to revert this kind of modifications.

Choosing a cross-platform library for PDF rendering and analysis app (preferably using C#)

I am planning to write an app that can open and display PDF documents, and perform OCR on vector graphic elements within the PDFs. The user must be able to select regions of the document and I need to draw real-time annotations on the document. I don't need to alter or save the document itself.
I have plenty of experience with C# and WPF; I have written a similar application already that does the above on XPS/XAML documents rather than PDF. However that app only runs on Windows and PDF documents must be converted to XPS first.
I have done quite a bit of research and there are many, many options available, none of which seem an obvious choice. There are many libraries that can open PDFs or create PDFs, but most don't seem to give you access to individual vector graphic elements in a format that lets you draw/manipulate them on the screen (similar to what I could do with WPF graphic elements extracted from XPS documents).
I am familiar with .Net and C# (including .Net 2 GDI+ graphics) and I am very keen to stick to what I know. I am also using EmguCV for image recognition which can be compiled in Mono or .Net. As such I am looking at Silverlight (running standalone) or Mono options, both of which should run on PC and Mac.
Performance (for both graphics and number crunching) is a strong consideration, though I am just as interested in getting this up and running quickly.
Does anyone have any experience with opening PDFs, extracting vector graphic elements (perhaps as SVG) and rendering them in a Mono app? Can individual elements be rendered to bitmap?
Alternatively, does anyone have experience with opening PDFs in Silverlight and converting them to XPS or XAML at runtime? I know that WPF and Silverlight graphics libraries are not 1:1, but I'm not sure how this affects XPS contents (generally composed of Canvas, Glyphs and StreamGeometry objects).
Thank you for any advice, tips or links you have to share.
look at this
http://silverpdf.codeplex.com/
it's client side pdf reading library. actually right now it can only read files, but you could play with it and make your own "display" functionality.
You might want to examine the internals of your PDFs so you understand what they actually contain better - you might be very surprised! For example, text can often be scanned pages or images and vecotr graphics do not exist as neat little packages. We wrote a whole load of general articles about what is inside a PDF and analysis tools at http://www.jpedal.org/PDFblog which are not specific to any tool or language.

.NET Tiff Issues C#

I'm having issues with TIFFs
Here is what I have to do, we have tiff images saved into the database, these images are CCITT4 compressed with a number of required tags, these include:
RowsPerStrip must be the ImageLength
Photometric Interpreation must be MinIsWhite
Multi-strip image format is not allowed
My problem is, I'm using the built in System.Drawing.Bitmap/Image objects, which happen to change the values of these when I put it into the object, I've tested this by saving the byte[] to a tiff directly from the database, checked the tags, they are fine.. but when i put the bytes into an Image object then save to file, they are modified.
To make things worse, I'm needing to add a text to the image before saving it.
So I need a component that will allow me more control with TIFF (and they must be tiff), and be able to add text to an image or be able to use the Graphics object.
I've tried using LibTiff but I have yet to see any examples on how to use this component,
any suggestions?
You can use our free and open-source LibTiff.Net library for this. It is freely available for all uses under a BSD license. The just released version 2.0 contains good documentation and number of samples.
There are samples that show how to convert any non-tiled TIFF image to the TIFF image which have all data written in a single strip and how to convert a System.Drawing.Bitmap to 1-bit CCITT single strip TIFF image.
I have never used the built int System.Drawing.Bitmap objects to do this. I personally use LeadTools, but it isn't free. It is however a robust and fairly straightforward API. I primarily use it for GEOTiff which contain specific data tags for image location data.
There is a 60 day evaluation if you would like to try it out.
I use FreeImage. There's a C# .NET wrapper available too.
The IEvolution component set from HiComponents is now totally free (no source) - http://www.hicomponents.com. A very powerful .NET imaging toolkit.

Categories

Resources