本文整理汇总了C#中FIBITMAP.SetNull方法的典型用法代码示例。如果您正苦于以下问题:C# FIBITMAP.SetNull方法的具体用法?C# FIBITMAP.SetNull怎么用?C# FIBITMAP.SetNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FIBITMAP
的用法示例。
在下文中一共展示了FIBITMAP.SetNull方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Example01
public void Example01()
{
if (!File.Exists(fileName))
{
Console.WriteLine(fileName + " does not exist. Aborting.");
return;
}
// Try to unload the bitmap handle (in case it is not null).
// Always assert that a handle (like dib) is unloaded before it is reused, because
// on unmanaged side there is no garbage collector that will clean up unreferenced
// objects.
// The following code will produce a memory leak (in case the bitmap is loaded
// successfully) because the handle to the first bitmap is lost:
// dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE);
// dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE);
if (!dib.IsNull)
FreeImage.Unload(dib);
// Loading a sample bitmap. In this case it's a .jpg file. 'Load' requires the file
// format or the loading process will fail. An additional flag (the default value is
// 'DEFAULT') can be set to enable special loading options.
dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE);
// Check if the handle is null which means the bitmap could not be loaded.
if (dib.IsNull)
{
Console.WriteLine("Loading bitmap failed. Aborting.");
// Check whether there was an error message.
return;
}
// Try flipping the bitmap.
if (!FreeImage.FlipHorizontal(dib))
{
Console.WriteLine("Unable to flip bitmap.");
// Check whether there was an error message.
}
// Store the bitmap back to disk. Again the desired format is needed. In this case the format is 'TIFF'.
// An output filename has to be chosen (which will be overwritten without a warning).
// A flag can be provided to enable pluginfunctions (compression is this case).
FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, dib, outFileName, FREE_IMAGE_SAVE_FLAGS.TIFF_DEFLATE);
// 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.SetNull();
}
示例2: FreeImage_Unload
public void FreeImage_Unload()
{
Assert.That(dib.IsNull);
dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, iManager.baseDirectory + @"JPEG\Image.jpg", FREE_IMAGE_LOAD_FLAGS.DEFAULT);
Assert.IsNotNull(dib);
FreeImage.Unload(dib);
dib.SetNull();
}
示例3: FreeImage_MultiBitmap
public void FreeImage_MultiBitmap()
{
FIBITMAP temp;
FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmap(
FREE_IMAGE_FORMAT.FIF_TIFF,
@"test.tif",
true,
false,
true,
FREE_IMAGE_LOAD_FLAGS.DEFAULT);
Assert.AreNotEqual(0, mdib);
Assert.AreEqual(0, FreeImage.GetPageCount(mdib));
dib = FreeImage.Allocate(10, 10, 8, 0, 0, 0);
FreeImage.AppendPage(mdib, dib);
Assert.AreEqual(1, FreeImage.GetPageCount(mdib));
FreeImage.AppendPage(mdib, dib);
Assert.AreEqual(2, FreeImage.GetPageCount(mdib));
FreeImage.AppendPage(mdib, dib);
Assert.AreEqual(3, FreeImage.GetPageCount(mdib));
FreeImage.CloseMultiBitmapEx(ref mdib);
FreeImage.UnloadEx(ref dib);
mdib.SetNull();
mdib = FreeImage.OpenMultiBitmap(FREE_IMAGE_FORMAT.FIF_TIFF, @"test.tif", false, false, true, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
Assert.AreNotEqual(0, mdib);
Assert.AreEqual(3, FreeImage.GetPageCount(mdib));
dib = FreeImage.LockPage(mdib, 1);
temp = FreeImage.LockPage(mdib, 2);
int[] pages = null;
int count = 0;
FreeImage.GetLockedPageNumbers(mdib, pages, ref count);
Assert.AreEqual(2, count);
pages = new int[count];
FreeImage.GetLockedPageNumbers(mdib, pages, ref count);
Assert.AreEqual(2, pages.Length);
FreeImage.UnlockPage(mdib, dib, false);
FreeImage.UnlockPage(mdib, temp, true);
dib.SetNull();
Assert.IsTrue(FreeImage.MovePage(mdib, 0, 1));
FreeImage.CloseMultiBitmapEx(ref mdib);
Assert.IsTrue(System.IO.File.Exists("test.tif"));
System.IO.File.Delete("test.tif");
}
示例4: Save
public void Save(FIBITMAP dib, string fileName)
{
// Store the bitmap back to disk
// TARGA_SAVE_RLE = 2
FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TARGA, dib, fileName, FREE_IMAGE_SAVE_FLAGS.TARGA_SAVE_RLE);
// 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.SetNull();
}
示例5: LoadImages
public Bitmap[] LoadImages(string[] fileNames)
{
var bitmaps = new Bitmap[fileNames.Length];
FIBITMAP dib;
int i = 0;
foreach (var f in fileNames)
{
if (!File.Exists(f))
{
throw new Exception(f + " does not exist. Aborting.");
}
// load image
dib = new FIBITMAP();
dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_TARGA, f, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
if (dib.IsNull)
{
throw new Exception("Loading bitmap failed. Aborting.");
}
// convert to bitmap
bitmaps[i] = FreeImage.GetBitmap(dib);
i++;
// free resources
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.SetNull();
}
return bitmaps;
}
示例6: LoadImageFromCache
FIBITMAP LoadImageFromCache(string tileType, GMapTile g)
{
FIBITMAP image = new FIBITMAP();
image.SetNull();
while (image.IsNull)
{
bool useProxy;
string src_filename = td.BuildFileName(tileType, g);
if (src_filename != null && src_filename.Length > 0)
{
string url = td.BuildURL(tileType, g, out useProxy);
// using temp file if tiles_per_file != 1
if (Properties.Settings.Default.MGMapsTilesPerFile == 1)
{
if (!td.IsCached(src_filename, g))
td.DownloadImage(url, src_filename, useProxy);
}
else
{
// FIX check if the image exists
String tempfile = Path.GetTempFileName();
#if DEBUG
Console.WriteLine("Temp file: " + tempfile);
#endif
try
{
if (!td.IsCached(src_filename, g))
{
td.DownloadImage(url, tempfile, useProxy);
#if DEBUG
Console.WriteLine("Downloaded image from {0}", url);
#endif
td.SaveImage(tempfile, src_filename, g);
}
}
finally
{
try
{
File.Delete(tempfile);
}
catch (Exception)
{
}
}
}
}
if (worker.CancellationPending || Properties.Settings.Default.MGMapsTilesPerFile != 1)
{
break;
}
//gkl changes - added synchronization based upon filename
bool createdNew = false;
Mutex synchobj = new Mutex(true, Regex.Replace(src_filename, "\\\\", "_"), out createdNew);
if (synchobj != null)
{
try
{
if (!createdNew)
synchobj.WaitOne();
if (!File.Exists(src_filename))
{
//blank image white
image = FreeImage.Allocate(GMapTile.TILE_SIZE, GMapTile.TILE_SIZE, 24, 0, 0, 0);
if (image.IsNull)
{
throw new InvalidOperationException(Properties.Resources.ExceptionCannotBuildBlankImage);
}
if (!FreeImage.Invert(image))
{
throw new InvalidOperationException(Properties.Resources.ExceptionCannotBuildBlankImage);
}
if (Properties.Settings.Default.SaveBlankImageForMissingTiles)
{
if (tileType == "GoogleSat" || tileType == "GoogleSatH" ||
tileType == "GoogleTer" || tileType == "YahooMap" ||
tileType == "YahooInMap" || tileType == "YahooSat" ||
tileType == "YahooSatH" || tileType == "YahooSatH2" ||
tileType == "MicrosoftSat" || tileType == "OpenAerialMap" ||
tileType == "BrutMapSat" || tileType == "BrutMapSatH" ||
tileType == "BrutMapAndNavSat" || tileType == "BrutMapAndNavSatH")
{
if (!FreeImage.Save(
FREE_IMAGE_FORMAT.FIF_JPEG,
image, src_filename,
FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB))
{
throw new InvalidOperationException(Properties.Resources.ExceptionCannotBuildBlankImage);
}
}
else
{
if (!FreeImage.Save(
FREE_IMAGE_FORMAT.FIF_PNG,
image, src_filename,
FREE_IMAGE_SAVE_FLAGS.PNG_Z_DEFAULT_COMPRESSION))
//.........这里部分代码省略.........
示例7: BuildBigImage
//.........这里部分代码省略.........
break;
}
if (Properties.Settings.Default.OperatingMode == 3 || Properties.Settings.Default.OperatingMode == 4 || Properties.Settings.Default.OperatingMode == 5 || Properties.Settings.Default.OperatingMode == 6)
reportFunction("Image download completed (" + xx + "," + yy + ")", 100.0 / (double)wholeQuant);
if (worker.CancellationPending)
{
return;
}
if (imageFormat == FREE_IMAGE_FORMAT.FIF_UNKNOWN)
{
continue;
}
if (grayscale)
{
//uint image2 = FreeImage.ConvertPalette(bigImage, image);
FIBITMAP image3 = FreeImage.ConvertTo24Bits(image);
if (image3.IsNull)
{
throw new InvalidOperationException(Properties.Resources.ExceptionCannotConvert24bpp);
}
FIBITMAP image2 = FreeImage.ConvertTo8Bits(image3);
FreeImage.Unload(image3);
if (image2.IsNull)
{
throw new InvalidOperationException(Properties.Resources.ExceptionCannotConvertGrayscale);
}
FreeImage.Unload(image);
image = image2;
/* FIXME
* if (!paletteInit)
{
if (!FreeImage.PaletteCopy(image, bigImage))
{
throw new InvalidOperationException(Properties.Resources.ExceptionGrayscalePalette);
}
paletteInit = true;
}
*/
}
reportFunction("Pasting " + g.Quadtree, 0);
if (!FreeImage.Paste(bigImage, image, (xx - topleftx) * GMapTile.TILE_SIZE, (yy - toplefty) * GMapTile.TILE_SIZE, 256))
{
throw new InvalidOperationException(Properties.Resources.ExceptionPastingImage);
}
}
catch (Exception)
{
if (Properties.Settings.Default.OperatingMode == 3 || Properties.Settings.Default.OperatingMode == 4 || Properties.Settings.Default.OperatingMode == 5 || Properties.Settings.Default.OperatingMode == 6)
reportFunction("Image download failed (" + xx + "," + yy + ")", 100.0 / (double)wholeQuant);
}
finally
{
FreeImage.Unload(image);
image.SetNull();
}
}
}
if (worker.CancellationPending || (imageFormat == FREE_IMAGE_FORMAT.FIF_UNKNOWN))
{
return;
}
if (!grayscale && dither8bpp)
{
reportFunction("Converting image to 8bpp", 0.0);
FIBITMAP bigImage8 = FreeImage.ColorQuantize(bigImage, FREE_IMAGE_QUANTIZE.FIQ_WUQUANT);
if (bigImage8.IsNull)
{
throw new InvalidOperationException(Properties.Resources.ExceptionConversion24bpp8bpp);
}
FreeImage.Unload(bigImage);
bigImage = bigImage8;
reportFunction("Image converted", 50.0);
}
if (worker.CancellationPending)
{
return;
}
reportFunction("Saving image to " + Path.GetFileName(filename), 0.0);
if (!FreeImage.Save(imageFormat, bigImage, filename, saveflags))
{
throw new IOException(Properties.Resources.ExceptionCannotSaveFile);
}
reportFunction("Image saved", 50.0);
}
finally
{
FreeImage.Unload(bigImage);
}
}