public void Dispose() { if (sceneThumb != null) { sceneThumb.Dispose(); sceneThumb = null; } }
/// <summary> /// Creates a standard color profile for the color space of the given /// <paramref name="freeImageBitmap"/>. /// </summary> /// <param name="freeImageBitmap">FreeImageBitmap for whose color space /// to create a profile.</param> /// <returns>Handle to a standard profile, or zero if no standard profile /// could be created.</returns> private cmsHProfile CreateStandardProfile(FreeImageAPI.FreeImageBitmap freeImageBitmap) { switch (freeImageBitmap.ColorType) { case FreeImageAPI.FREE_IMAGE_COLOR_TYPE.FIC_RGB: return(cmsCreate_sRGBProfile()); case FreeImageAPI.FREE_IMAGE_COLOR_TYPE.FIC_RGBALPHA: return(cmsCreate_sRGBProfile()); default: return(cmsHProfile.Zero); } }
public static Bitmap TextureFromGameFile(String path, FileManager fileManager) { byte[] imageFile = fileManager.GetFileBytes(path); Stream stream = new MemoryStream(imageFile); FreeImageAPI.FreeImageBitmap bmp = new FreeImageAPI.FreeImageBitmap(stream); stream.Close(); Bitmap image = bmp.ToBitmap(); bmp.Dispose(); return(image); }
/// <summary> /// Converts a FreeImage color type to an LCMS formatter constant, as defined /// in <see cref="XLToolbox.Export.Lcms.Formatters"/>. /// </summary> /// <param name="freeImageBitmap">FreeImageBitmap whose color type to convert.</param> /// <returns>Resulting LCMS formatter constant.</returns> /// <exception cref="InvalidOperationException">if no predefined formatter /// constant exists for the color type of the given FreeImageBitmap.</exception> private cmsUInt32Number GetLcmsPixelFormat(FreeImageAPI.FreeImageBitmap freeImageBitmap) { switch (freeImageBitmap.ColorType) { case FreeImageAPI.FREE_IMAGE_COLOR_TYPE.FIC_CMYK: return(Lcms.Formatters.TYPE_CMYK); case FreeImageAPI.FREE_IMAGE_COLOR_TYPE.FIC_RGBALPHA: return(Lcms.Formatters.TYPE_BGRA_8); // on Windows: BGRA, not RGBA! case FreeImageAPI.FREE_IMAGE_COLOR_TYPE.FIC_RGB: return(Lcms.Formatters.TYPE_BGR_8); // on Windows: BGR, not RGB! default: throw new InvalidOperationException( "No LCMS formatter defined for " + freeImageBitmap.ColorType.ToString()); } }
private Bitmap LoadImage(string imagePath, string extension) { string path = string.Empty; try { path = Path.Combine(@"data\units\items", imagePath + extension); byte[] image = fileManager.GetFileBytes(path); fileManager.EndAllDatAccess(); Stream stream = new MemoryStream(image); FreeImageAPI.FreeImageBitmap bmp = FreeImageAPI.FreeImageBitmap.FromStream(stream); return(bmp.ToBitmap()); } catch (Exception) { MessageBox.Show(string.Format("Item image not found at {0}!", path)); return(null); } }
private static DMIImageData MakeGreyscaleSquare(DMIImageData image) { FreeImageAPI.FreeImageBitmap bit = new FreeImageAPI.FreeImageBitmap(image.Bitmap); bit.ConvertColorDepth(FreeImageAPI.FREE_IMAGE_COLOR_DEPTH.FICD_32_BPP); Color grey = new Color(); grey = bit.GetPixel(2, 2); for (int i = 0; i < bit.Height; i++) { for (int j = 0; j < bit.Width; j++) { grey = Color.FromArgb(255, j, i, 0); bit.SetPixel(j, i, grey); } } image.Bitmap = bit.ToBitmap(); return(image); }
private Bitmap LoadImage(string folder, string imagePath, string extension) { //return DevIL.DevIL.LoadBitmap(filePath); string path = Path.Combine(folder, imagePath) + extension; FreeImageAPI.FreeImageBitmap bmp = FreeImageAPI.FreeImageBitmap.FromFile(path); return(bmp.ToBitmap()); //string path = Path.Combine(@"data\units\items", filePath); //string path = @"data\units\items\misc\dye_kit\low\dye_kit_diffuse.dds"; //if (_fileExplorer.GetFileExists(path)) //{ // byte[] imageBytes = _fileExplorer.GetFileBytes(path); // MemoryStream imageStream = new MemoryStream(imageBytes, false); // FreeImageAPI.FreeImageBitmap bmp = FreeImageAPI.FreeImageBitmap.FromStream(imageStream); // return bmp.ToBitmap(); //} //return null; }
/// <summary> /// Transforms the pixels of a FreeImageBitmap using a standard color profile /// for the bitmap's color space and the current color profile. /// </summary> /// <param name="freeImageBitmap">FreeImageBitmap whose pixels to convert.</param> /// <remarks> /// Since Excel does not support color management at all, conversions are done /// using standard color profiles that LittleCMS provides. /// </remarks> public void TransformFromStandardProfile(FreeImageAPI.FreeImageBitmap freeImageBitmap) { cmsHProfile standardProfile = CreateStandardProfile(freeImageBitmap); if (standardProfile == cmsHProfile.Zero) { throw new InvalidOperationException( "Unable to create standard profile for " + freeImageBitmap.ColorType.ToString()); } cmsHProfile targetProfile = cmsOpenProfileFromFile(GetPathFromName(), "r"); if (targetProfile == cmsHProfile.Zero) { throw new InvalidOperationException( "Unable to open desired color profile: " + Name); } // Create transform with perceptual intent (0) and no special options (0) cmsHTransform t = cmsCreateTransform( standardProfile, Lcms.Formatters.TYPE_BGRA_8, targetProfile, GetLcmsPixelFormat(ColorSpace), 0, 0); if (t == cmsHTransform.Zero) { throw new InvalidOperationException("Unable to create CMS transform."); } UInt32 numPixels = (UInt32)freeImageBitmap.Size.Width * (UInt32)freeImageBitmap.Size.Height; cmsDoTransform(t, freeImageBitmap.Bits, freeImageBitmap.Bits, numPixels); freeImageBitmap.CreateICCProfile(GetIccBytes()); cmsDeleteTransform(t); cmsCloseProfile(standardProfile); cmsCloseProfile(targetProfile); }
/// <summary> /// Transform a given image using a direction specific template /// </summary> /// <param name="image"></param> /// <returns>Uses pass by reference, no return</returns> private static void MakeImageTransform(DMIImageData image) { FreeImageAPI.FreeImageBitmap inMap = new FreeImageAPI.FreeImageBitmap(image.Bitmap); FreeImageAPI.FreeImageBitmap transMap = new FreeImageAPI.FreeImageBitmap("./in/Templates/UnathiUnder" + image.Dir + ".png"); // FreeImageAPI.FreeImageBitmap transMap = new FreeImageAPI.FreeImageBitmap("./in/Templates/UnathiHatGlass.png"); // FreeImageAPI.FreeImageBitmap transMap = new FreeImageAPI.FreeImageBitmap("./in/Templates/TallGreySquare.png"); inMap.ConvertColorDepth(FreeImageAPI.FREE_IMAGE_COLOR_DEPTH.FICD_32_BPP); transMap.ConvertColorDepth(FreeImageAPI.FREE_IMAGE_COLOR_DEPTH.FICD_32_BPP); Color inCol = new Color(); Color transCol = new Color(); Color clearRead = Color.FromArgb(0, 192, 192, 192); Color clearWrite = inMap.GetPixel(0, 0); int[, ][] transStore = new int[transMap.Width, transMap.Height][]; if (image.Dir == 4) { inMap.RotateFlip(RotateFlipType.RotateNoneFlipX); } // Get the original tranformation map's colours and store in 2D jagged array for manipulation for (int i = 0; i < transMap.Height; i++) { for (int j = 0; j < transMap.Width; j++) { transCol = transMap.GetPixel(j, i); transStore[j, i] = new int[4] { transCol.A, transCol.R, transCol.G, transCol.B }; } } // Iterate through the image pixel by pixel, taking the colour from the original and applying it to // all members of the transform array with a colour that matches the location based on i and j. // Ex: if i is 10 and j is 20, all places in the array with the ARGB colour (255, 10, 20, 0) // will be replaced with the new colour. for (int i = 0; i < inMap.Height; i++) { for (int j = 0; j < inMap.Width; j++) { inCol = inMap.GetPixel(j, i); transCol = Color.FromArgb(255, j, i, 0); // transStore = StoreColReplace(transStore, transCol, inCol, transMap.Width, transMap.Height); } } // Takes the array and writes the new pixels onto the template for (int i = 0; i < transMap.Height; i++) { for (int j = 0; j < transMap.Width; j++) { Color tempCol = Color.FromArgb(transStore[j, i][0], transStore[j, i][1], transStore[j, i][2], transStore[j, i][3]); if (tempCol.Equals(clearWrite)) { tempCol = Color.FromArgb(transStore[31, 15][0], transStore[31, 15][1], transStore[31, 15][2], transStore[31, 15][3]); } transMap.SetPixel(j, i, tempCol); } } transMap.PreMultiplyWithAlpha(); if (image.Dir == 4) { transMap.RotateFlip(RotateFlipType.RotateNoneFlipX); } image.Bitmap = transMap.ToBitmap(); }
public BitmapCreatedEventArgs(FreeImageAPI.FreeImageBitmap freeImageBitmap) { FreeImageBitmap = freeImageBitmap; }