本文整理汇总了C#中FIBITMAP类的典型用法代码示例。如果您正苦于以下问题:C# FIBITMAP类的具体用法?C# FIBITMAP怎么用?C# FIBITMAP使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FIBITMAP类属于命名空间,在下文中一共展示了FIBITMAP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decode
public byte[] Decode(PdfObject decodedObject, byte[] inputData, DecodeParameters decodeParameters)
{
FIBITMAP myImage = new FIBITMAP();
using (MemoryStream stream = new MemoryStream(inputData))
{
myImage = FreeImage.LoadFromStream(stream);
}
Bitmap bitmap = FreeImage.GetBitmap(myImage);
decodedObject.ColorSpace = ColorSpace.RGB;
byte[] result = new byte[decodedObject.Width * decodedObject.Height * 3];
for (int i = 0; i < decodedObject.Width; i++)
{
for (int j = 0; j < decodedObject.Height; j++)
{
Color pixel = bitmap.GetPixel(i, j);
int index = j * decodedObject.Width + i;
result[index * 3] = pixel.R;
result[index * 3 + 1] = pixel.G;
result[index * 3 + 2] = pixel.B;
}
}
return result;
}
示例2: fiGetMetaData
public List<MetaSimple> fiGetMetaData(FIBITMAP bm)
{
List<MetaSimple> results = new List<MetaSimple>();
// Create a wrapper for all metadata the image contains
ImageMetadata iMetadata = new ImageMetadata(bm);
// Get each metadata model
foreach (MetadataModel metadataModel in iMetadata)
{
// Get each metadata tag and create a subnode for it
foreach (MetadataTag metadataTag in metadataModel)
{
MetaSimple tagValue = new MetaSimple();
tagValue.ModelName = metadataModel.ToString();
tagValue.ModelTag = metadataTag.Key;
tagValue.TagValue = metadataTag;
results.Add(tagValue);
}
}
return results;
}
示例3: MetadataModel
/// <summary>
/// Initializes a new instance of this class.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="dib"/> is null.</exception>
protected MetadataModel(FIBITMAP dib)
{
if (dib.IsNull)
{
throw new ArgumentNullException("dib");
}
this.dib = dib;
}
示例4: bLoad_Click
private void bLoad_Click(object sender, EventArgs e)
{
// Create variables
OpenFileDialog ofd = new OpenFileDialog();
FIBITMAP dib = new FIBITMAP();
try
{
// Apply settings
ofd.CheckFileExists = true;
ofd.CheckPathExists = true;
ofd.FileName = "";
ofd.Filter = "All files (*.*)|*.*";
ofd.Multiselect = false;
ofd.RestoreDirectory = true;
// Get image filename
if (ofd.ShowDialog() == DialogResult.OK)
{
// Load the image
dib = FreeImage.LoadEx(ofd.FileName);
// Check if image was loaded successfully
if (dib.IsNull) throw new Exception("Failed to load image.");
// Clear the treeview
tvMetadata.Nodes.Clear();
// Create a wrapper for all metadata the image contains
ImageMetadata iMetadata = new ImageMetadata(dib);
// Get each metadata model
foreach (MetadataModel metadataModel in iMetadata)
{
// Create a new node for each model
TreeNode modelNode = tvMetadata.Nodes.Add(metadataModel.ToString());
// Get each metadata tag and create a subnode for it
foreach (MetadataTag metadataTag in metadataModel)
{
modelNode.Nodes.Add(metadataTag.Key + ": " + metadataTag.ToString());
}
}
}
else
{
MessageBox.Show("Operation aborted.", "Aborted");
}
}
// Display error message
catch (Exception ex)
{
while (ex.InnerException != null)
ex = ex.InnerException;
MessageBox.Show(ex.ToString(), "Exception caught");
}
// Clean up
finally
{
ofd.Dispose();
FreeImage.UnloadEx(ref dib);
}
}
示例5: CleanUpResources
public static void CleanUpResources(FIBITMAP dib)
{
// The bitmap was saved to disk but is still allocated in memory, so the handle has to be freed.
if (!dib.IsNull) {
FreeImage.Unload(dib);
}
// Make sure to set the handle to null so that it is clear that the handle is not pointing to a bitmap.
dib = FIBITMAP.Zero;
}
示例6: buildFiBitmap
/// <summary>
/// Builds an FIBitmap from the stream and job.Settings
/// </summary>
/// <param name="s"></param>
/// <param name="job"></param>
/// <returns></returns>
protected FIBITMAP buildFiBitmap(ref FIBITMAP original, ImageJob job, bool supportsTransparency, bool mayUnloadOriginal)
{
ResizeSettings settings = job.Settings;
if (original.IsNull) return FIBITMAP.Zero;
FIBITMAP final = FIBITMAP.Zero;
//Find the image size
Size orig = new Size((int)FreeImage.GetWidth(original), (int)FreeImage.GetHeight(original));
//Calculate the new size of the image and the canvas.
ImageState state = new ImageState(settings, orig, true);
c.CurrentImageBuilder.Process(state);
RectangleF imageDest = PolygonMath.GetBoundingBox(state.layout["image"]);
if (imageDest.Width != orig.Width || imageDest.Height != orig.Height) {
//Rescale
bool temp;
final = FreeImage.Rescale(original, (int)imageDest.Width, (int)imageDest.Height, FreeImageScalingPlugin.ParseResizeAlgorithm(settings["fi.scale"], FREE_IMAGE_FILTER.FILTER_BOX, out temp));
if (mayUnloadOriginal) FreeImage.UnloadEx(ref original);
if (final.IsNull) return FIBITMAP.Zero;
} else {
final = original;
}
RGBQUAD bgcolor = default(RGBQUAD);
bgcolor.Color = settings.BackgroundColor;
if (settings.BackgroundColor == Color.Transparent && !supportsTransparency)
bgcolor.Color = Color.White;
//If we need to leave padding, do so.
BoxPadding outsideImage = new BoxPadding(imageDest.Left, imageDest.Top, state.destSize.Width - imageDest.Right, state.destSize.Height - imageDest.Bottom);
if (outsideImage.All != 0) {
var old = final;
//Extend canvas
final = FreeImage.EnlargeCanvas<RGBQUAD>(old,
(int)outsideImage.Left, (int)outsideImage.Top, (int)outsideImage.Right, (int)outsideImage.Bottom,
bgcolor.Color != Color.Transparent ? new Nullable<RGBQUAD>(bgcolor) : null,
FREE_IMAGE_COLOR_OPTIONS.FICO_RGBA);
if (old == original) {
if (mayUnloadOriginal) {
FreeImage.UnloadEx(ref original);
old = original;
}
} else {
FreeImage.UnloadEx(ref old); //'old' has the original value of 'final', which we allocated.
}
if (final.IsNull) return FIBITMAP.Zero;
}
return final;
}
示例7: bLoadUrl_Click
private void bLoadUrl_Click(object sender, EventArgs e)
{
// Verify url
if (String.IsNullOrEmpty(tbURL.Text))
{
MessageBox.Show("Please enter a valid URL.", "Error");
return;
}
FIBITMAP dib = new FIBITMAP();
Stream sourceStream = null;
try
{
// Build a stream to read from
WebRequest request = (WebRequest)HttpWebRequest.Create(tbURL.Text);
WebResponse response = request.GetResponse();
sourceStream = response.GetResponseStream();
if (sourceStream == null)
{
throw new Exception();
}
// Load the image from stream
dib = FreeImage.LoadFromStream(sourceStream);
// Check success
if (dib.IsNull)
{
throw new Exception();
}
// Convert the bitmap into a .NET bitmap
Bitmap bitmap = FreeImage.GetBitmap(dib);
if (bitmap == null)
{
throw new Exception();
}
// Show the bitmap
if (picBox.Image != null)
{
picBox.Image.Dispose();
}
picBox.Image = bitmap;
}
catch
{
// Error handling
MessageBox.Show("Error loading URL.", "Error");
}
finally
{
// Clean up memory
FreeImage.UnloadEx(ref dib);
if (sourceStream != null) sourceStream.Dispose();
}
}
示例8: FIICCPROFILE
/// <summary>
/// Creates a new ICC-Profile for <paramref name="dib"/>.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="data">The ICC-Profile data.</param>
/// <param name="size">Number of bytes to use from data.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="dib"/> is null.</exception>
public unsafe FIICCPROFILE(FIBITMAP dib, byte[] data, int size)
{
if (dib.IsNull)
{
throw new ArgumentNullException("dib");
}
FIICCPROFILE prof;
size = Math.Min(size, (int)data.Length);
prof = *(FIICCPROFILE*)FreeImage.CreateICCProfile(dib, data, size);
this.flags = prof.flags;
this.size = prof.size;
this.data = prof.data;
}
示例9: fiLoadImage
public FIBITMAP fiLoadImage(string fileName)
{
FIBITMAP bm = new FIBITMAP();
try
{
// Load the image
bm = FreeImage.LoadEx(fileName);
}
catch (Exception)
{
throw new Exception("Failed to load image.");
}
return bm;
}
示例10: MDM_EXIF_EXIF
/// <summary>
/// Initializes a new instance of this class.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
public MDM_EXIF_EXIF(FIBITMAP dib)
: base(dib)
{
}
示例11: FreeImageAlgorithmsBitmap
public FreeImageAlgorithmsBitmap(FIBITMAP dib)
: base(dib)
{
}
示例12: MDM_NODATA
/// <summary>
/// Initializes a new instance of this class.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
public MDM_NODATA(FIBITMAP dib)
: base(dib)
{
}
示例13: MDM_XMP
/// <summary>
/// Initializes a new instance of this class.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
public MDM_XMP(FIBITMAP dib)
: base(dib)
{
}
示例14: MDM_MAKERNOTE
/// <summary>
/// Initializes a new instance of this class.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
public MDM_MAKERNOTE(FIBITMAP dib)
: base(dib)
{
}
示例15: MDM_MAIN
/// <summary>
/// Initializes a new instance of this class.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
public MDM_MAIN(FIBITMAP dib)
: base(dib)
{
}