I have a lot of very large PDF files, which contains huge images (scans).
The goal is to open PDF , read all images , change dpi, resolution and compress it.
How to managed it with Itex7?
And generally ho to iterate through all images in PDF?
using (iText.Kernel.Pdf.PdfReader pdfReader = new iText.Kernel.Pdf.PdfReader(inputPdfFile))
{
using (iText.Kernel.Pdf.PdfDocument pdfDocument = new iText.Kernel.Pdf.PdfDocument(pdfReader))
{
//??
//foreach (var image in pdfDocumentImagesList)
//{
// //image.SetNewDPI()
//}
}
}
How to go through all the PDF's images?
https://github.com/itext/i7js-book/blob/develop/src/test/java/com/itextpdf/samples/book/part4/chapter15/Listing_15_30_ExtractImages.java
https://github.com/itext/i7js-book/blob/develop/src/test/java/com/itextpdf/samples/book/part4/chapter15/Listing_15_31_MyImageRenderListener.java
How to change the image's dpi and resolution?
That's not a part of iText functionality, since iText is a PDF- rather than an image-proccessing library. I advise you to process the extracted images with some other tools and then either put them into a new document or replace the image in the PDF. The latter is not very easy. Probably the next SO answer would shed some light on it: http://stackoverflow.com/questions/26580912/pdf-convert-to-black-and-white-pngs
(its code, but in iText7: https://github.com/itext/i7js-examples/blob/develop/src/test/java/com/itextpdf/samples/sandbox/images/ReplaceImage.java)
How to compress an image?
https://github.com/itext/i7js-book/blob/develop/src/test/java/com/itextpdf/samples/book/part3/chapter10/Listing_10_12_CompressImage.java
Hope that would be useful!
I'm struggling with FreeImage and the documentation is not helping me a lot!
I need to display a tif, an exr or an HDR image in a picturebox with C# and I'm not succeeding and I wonder how can I do it... I'm getting the error: Only bitmaps with type of FIT_BITMAP can be converted. ...
Can anyone help me with it ? I suppose I have to convert the tiff to a bitmap but I've tried but I don't know how I should do it yet ... Here is my code:
FIBITMAP imageToDisplay = new FIBITMAP();
imageToDisplay = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_TIFF, i, FREE_IMAGE_LOAD_FLAGS.TIFF_CMYK);
Bitmap bitmap = FreeImage.GetBitmap(imageToDisplay);
pictureBox.Image = (Image)new Bitmap(bitmap);
For displaying TIFFs, PictureBox.Image takes a System.Drawing.Image object - and System.Drawing.Image.FromFile() supports TIFF images.
I can't see any need to involve any third party dependencies here. It's all built in to the framework.
pictureBox.Image = Image.FromFile(someImage);
If your TIFF isn't a file (e.g. if it's just a byte array or a MemoryStream) - that's okay too - use Image.FromStream().
For unsupported file formats, your job is to convert them into a format supported by System.Drawing.Image. If this is not possible, you might not be able to use the PictureBox control for this job.
Perhaps the title of your question should be "Constructing Image objects from EXR files" or maybe "Displaying EXR files in Windows Forms" or similar.
I'm writing a piece of software for visualization of measurement data. For this I use System.Windows.Forms.DataVisualization.Charting.Chart and I do know that I can get the shown image by chartObj.SaveImage to store it to a file.
My software shall have a PDF export in which the picture should be included. For this, I'm using iTextSharp. Again, I do know how to put a picture which I have stored in a file into the PDF by iTextSharp.text.Image.GetInstance.
So by now I am able to take the picture of the chart, put it to a file (e.g. a .jpg file) and load this file again to put it in my PDF. Now I'm looking for a nice solution to get the picture into the PDF without storing it into a file, maybe through a Stream or something like that. I've tried quite some time, but until now I didn't succeed. I've thought of something like
Stream imageStream = image of chartObj;
iTextSharp.text.Image picture = iTextSharp.text.Image.GetInstance(imageStream);
As far as I understand, I fail in putting the picture from the chartObj into a Stream instead of a file. If I had this, I guess I could load the Stream via iTextSharp.text.Image.GetInstance.
Has anyone some help you could offer? Guess it's not that difficult, but I'm new to C# and also to iText, so I'm just a bit stucked here.
Thanks in advance for every thought you have about this!
Anna
SaveImage to a MemoryStream:
using (var chartimage = new MemoryStream())
{
chart.SaveImage(chartimage, ChartImageFormat.Png);
return chartimage.GetBuffer();
}
From:
Microsoft Chart Controls to PDF with iTextSharp and ASP.NET MVC
I wonder if this is even possible. I have an application that adds a context menu when you right click a file. It all works fine but here is what I'd like to do:
If the file is a PSD then I want the program to extract the image. Is this possible to do without having Photoshop installed?
Basically I want the user to right click and click "image" which would save a .jpg of the file for them.
edit: will be using c#
Thanks
The ImageMagick libraries (which provide bindings for C#) also support the PSD format. They might be easier to get started with than getting into the Paint.NET code and also come with a quite free (BSD-like) license.
A simple sample (found at http://midimick.com/magicknet/magickDoc.html) using MagickNet would look like this:
using System;
static void Main(string[] args)
{
MagickNet.Magick.Init();
MagicNet.Image img = new MagicNet.Image("file.psd");
img.Resize(System.Drawing.Size(100,100));
img.Write("newFile.png");
MagickNet.Magick.Term();
}
Note: MagickNet has moved to http://www.codeproject.com/KB/dotnet/ImageMagick_in_VBNET.aspx
Well, there's a PSD plugin for Paint.NET which I think is Open-Source which you might want to take a look at for starters:
http://frankblumenberg.de/doku/doku.php?id=paintnet:psdplugin#download
This guy do it easier:
http://www.codeproject.com/KB/graphics/simplepsd.aspx
With a C# library and a sample project.
I've tried with PS2 files and works ok.
I have written a PSD parser which extracts raster format layers from all versions of PSD and PSB. http://www.telegraphics.com.au/svn/psdparse/trunk
You can use GroupDocs.Viewer for .NET API to render your PSD files as images (JPG, PNG, BMP) in your application using a few lines of code.
C#
ViewerConfig config = new ViewerConfig();
config.StoragePath = "D:\\storage\\";
// Create handler
ViewerImageHandler imageHandler = new ViewerImageHandler(config);
// Guid implies that unique document name
string guid = "sample.psd";
// Get document pages as images
List<PageImage> pages = imageHandler.GetPages(guid);
foreach (PageImage page in pages)
{
// Access each image using page.Stream
}
For more details and sample code, please visit here.
Disclosure: I work as a Developer Evangelist at GroupDocs.
For people who are reading this now: the link from accepted answer doesn't seem to work anymore (at least for me). Would add a comment there, but not allowed to comment yet - hence I'm adding a new answer.
The working link where you can find the psdplugin code for Paint.Net: https://github.com/PsdPlugin/PsdPlugin
Here is my own psd parser and exporter:
http://papirosnik.info/psdsplit/.
It allows to correctly parse psd with rgb color 8, 16- and 32-bit for channel, process user masks, export selected layers into jpeg, png, jng, bmp, tiff; create xml layout of exported layers and groups and also create a texture atlas and animations set from given layers.
It's entirely written in C#. If you want its sources inform me via support link on About dialog in the application.
ImageMagick.NET - http://imagemagick.codeplex.com/ - is the later version of the link 0xA3 gave, with some slightly different syntax. (Note, this is untested):
using ImageMagickNET;
public void Test() {
MagickNet.InitializeMagick();
ImageMagickNET.Image img = new ImageMagickNET.Image("file.psd");
img.Resize(new Geometry(100, 100, 0, 0, false, false);
img.Write("newFile.png");
}
I got extraction from psd working. see my answer here
How to extract layers from a Photoshop file? C#
may help someone else.
FastStone does this pretty efficiently.
They do not have their libraries availaible, but I guess you can contact them and see if they can help.
Check out their website: http://www.faststone.org/download.htm
I've had great success with Aspose's Imaging component which can load and save PSD files without Photoshop: https://products.aspose.com/imaging/net
How to export pictures in Microsoft Word to TIFF file using Visual Studio Tools for Office? I can obtain a reference to the pictures as InlineShape object collection, the hard part now is how to save them as TIFF images.
OK guys, I got the problem solved. Here's the code snippet:
private void SaveToImage(Word.InlineShape picShape, string filePath)
{
picShape.Select();
theApp.Selection.CopyAsPicture();
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(typeof(Bitmap)))
{
Bitmap image = (Bitmap)data.GetData(typeof(Bitmap));
image.Save(filePath);
}
}
Hope it helps :)
Well. not sure if this is helpful, but you if you are okay with jpegs, then one really cool technique for extracting images from Word 2007 file is as follows:
Rename the .docx file to .zip.
Under the (now) zip file, go to the following path: word/media.
All the images in the document are found here as jpeg files.
Cheers.