C# Класс Bloom.ImageProcessing.ImageUtils

Показать файл Открыть проект

Открытые методы

Метод Описание
AppearsToBeJpeg ( SIL.Windows.Forms.ImageToolbox.PalasoImage imageInfo ) : bool
GetImageFromFile ( string path ) : Image

Read a bitmap image from a file. The file must be known to exist before calling this method.

Image.FromFile and Image.FromStream lock the file until the image is disposed of. Therefore, we copy the image and dispose of the original. On Windows, Image.FromFile leaks file handles, so we use FromStream instead. For details, see the last answer to http://stackoverflow.com/questions/16055667/graphics-drawimage-out-of-memory-exception

ProcessAndSaveImageIntoFolder ( SIL.Windows.Forms.ImageToolbox.PalasoImage imageInfo, string bookFolderPath, bool isSameFile ) : string

Makes the image a png if it's not a jpg and saves in the book's folder. If the image has a filename, replaces any file with the same name. WARNING: imageInfo.Image could be replaced (causing the original to be disposed)

RemoveTransparencyOfImagesInFolder ( string folderPath, IProgress progress ) : void
SaveAsTopQualityJpeg ( Image image, string destinationPath ) : void

Save the image (of any format) to a jpeg file with 100 quality Note that this is still going to introduce some errors if the input is a bitmap.

Will throw if the destination is locked and the user tells us to give up.

ShouldChangeFormatToJpeg ( Image image ) : bool

When images are copied from LibreOffice, images that were jpegs there are converted to bitmaps for the clipboard. So when we just saved them as bitmaps (pngs), we dramatically inflated the size of user's image files (and this then led to memory problems). So the idea here is just to try and detect that we should would be better off saving the image as a jpeg. Note that even at 100%, we're still going to lose some quality. So this method is only going to recommend doing that if the size would be at least 50% less.

Приватные методы

Метод Описание
CreateImageWithoutTransparentBackground ( Image image ) : Image
DrawImageWithWhiteBackground ( Image source, Bitmap target ) : void
GetFileNameToUseForSavingImage ( string bookFolderPath, SIL.Windows.Forms.ImageToolbox.PalasoImage imageInfo, bool isJpeg ) : string
LogMemoryUsage ( ) : void
RemoveTransparency ( Image original, string path, IProgress progress ) : void

Описание методов

AppearsToBeJpeg() публичный статический Метод

public static AppearsToBeJpeg ( SIL.Windows.Forms.ImageToolbox.PalasoImage imageInfo ) : bool
imageInfo SIL.Windows.Forms.ImageToolbox.PalasoImage
Результат bool

GetImageFromFile() публичный статический Метод

Read a bitmap image from a file. The file must be known to exist before calling this method.
Image.FromFile and Image.FromStream lock the file until the image is disposed of. Therefore, we copy the image and dispose of the original. On Windows, Image.FromFile leaks file handles, so we use FromStream instead. For details, see the last answer to http://stackoverflow.com/questions/16055667/graphics-drawimage-out-of-memory-exception
public static GetImageFromFile ( string path ) : Image
path string
Результат Image

ProcessAndSaveImageIntoFolder() публичный статический Метод

Makes the image a png if it's not a jpg and saves in the book's folder. If the image has a filename, replaces any file with the same name. WARNING: imageInfo.Image could be replaced (causing the original to be disposed)
public static ProcessAndSaveImageIntoFolder ( SIL.Windows.Forms.ImageToolbox.PalasoImage imageInfo, string bookFolderPath, bool isSameFile ) : string
imageInfo SIL.Windows.Forms.ImageToolbox.PalasoImage
bookFolderPath string
isSameFile bool
Результат string

RemoveTransparencyOfImagesInFolder() публичный статический Метод

public static RemoveTransparencyOfImagesInFolder ( string folderPath, IProgress progress ) : void
folderPath string
progress IProgress
Результат void

SaveAsTopQualityJpeg() публичный статический Метод

Save the image (of any format) to a jpeg file with 100 quality Note that this is still going to introduce some errors if the input is a bitmap.
Will throw if the destination is locked and the user tells us to give up.
public static SaveAsTopQualityJpeg ( Image image, string destinationPath ) : void
image Image
destinationPath string
Результат void

ShouldChangeFormatToJpeg() публичный статический Метод

When images are copied from LibreOffice, images that were jpegs there are converted to bitmaps for the clipboard. So when we just saved them as bitmaps (pngs), we dramatically inflated the size of user's image files (and this then led to memory problems). So the idea here is just to try and detect that we should would be better off saving the image as a jpeg. Note that even at 100%, we're still going to lose some quality. So this method is only going to recommend doing that if the size would be at least 50% less.
public static ShouldChangeFormatToJpeg ( Image image ) : bool
image Image
Результат bool