public ImagesController(IHostingEnvironment host, IMovieReviewUow uow, IOptionsSnapshot <ImageSettings> options) { _host = host; _uow = uow; _options = options.Value; }
public void Save(Stream input) { ImageSettings modSettings = settings; modSettings.Width = Image.Width; modSettings.Height = Image.Height; byte[] data = Common.Save(Image, modSettings); using (BinaryWriterX br = new BinaryWriterX(new MemoryStream())) { header.width = (ushort)Image.Width; header.height = (ushort)Image.Height; br.WriteStruct <Header>(header); br.BaseStream.Position = header.dataStart; br.Write(data); br.BaseStream.Position = 0; if (lz11_compressed) { byte[] comp = LZ11.Compress(br.BaseStream); input.Write(comp, 0, comp.Length); } else { input.Write(new BinaryReaderX(br.BaseStream).ReadBytes((int)br.BaseStream.Length), 0, (int)br.BaseStream.Length); } input.Close(); } }
public CTXB(Stream input) { using (var br = new BinaryReaderX(input)) { //Header header = br.ReadStruct <Header>(); //Chunks for (int i = 0; i < header.chunkCount; i++) { chunks.Add(new Chunk(br.BaseStream)); } br.BaseStream.Position = header.texDataOffset; for (int i = 0; i < header.chunkCount; i++) { for (int j = 0; j < chunks[i].texCount; j++) { var settings = new ImageSettings { Width = chunks[i].textures[j].width, Height = chunks[i].textures[j].height, Format = Support.Format[(uint)((chunks[i].textures[j].dataType << 16) | chunks[i].textures[j].imageFormat)], Swizzle = new CTRSwizzle(chunks[i].textures[j].width, chunks[i].textures[j].height) }; settingsList.Add(settings); bmps.Add(Kontract.Image.Common.Load(br.ReadBytes(chunks[i].textures[j].dataLength), settings)); } } } }
public CTGD(Stream input) { using (var br = new BinaryReaderX(input)) { var width = br.ReadInt16(); var height = br.ReadUInt16(); while (br.BaseStream.Position < br.BaseStream.Length) { var magic = br.ReadString(8); var size = br.ReadInt32(); entries.Add(new NNSEntry { magic = magic, nnsSize = size, data = br.ReadBytes(size - 12) }); } format = new Palette(entries.Find(e => e.magic == "nns_pcol").data, new RGBA(5, 5, 5), 8); settings = new ImageSettings { Width = width, Height = height, Format = format }; bmps.Add(Kontract.Image.Common.Load(entries.Find(e => e.magic == "nns_txel").data, settings)); } }
public async Task <bool> Encode(BitmapInfo bitmapInfo, FormatInfo formatInfo, IProgress <ProgressReport> progress) { if (bitmapInfo.Image == null) { return(await Task.Factory.StartNew(() => false)); } return(await Task.Factory.StartNew(() => { progress.Report(new ProgressReport { Percentage = 0, Message = "Begin encoding..." }); Thread.Sleep(100); var kbi = bitmapInfo as KsltBitmapInfo; var settings = new ImageSettings(ImageFormats.Formats[formatInfo.FormatIndex], kbi.Image.Width, kbi.Image.Height); kbi.ImageData = Common.Save(kbi.Image, settings); progress.Report(new ProgressReport { Percentage = 50, Message = "Encoding complete." }); Thread.Sleep(100); bitmapInfo.Image = Common.Load(kbi.ImageData, settings); progress.Report(new ProgressReport { Percentage = 100, Message = "Reload complete." }); return true; })); }
/// <summary> /// Converts a given bitmap, modified by given settings, in binary data. /// </summary> /// <param name="bmp">The bitmap, which will be converted.</param> /// <param name="settings">Settings like encoding, dimensions and swizzles.</param> /// <returns>Saved byte array.</returns> public static byte[] Save(Bitmap bmp, ImageSettings settings) { int width = settings.Width, height = settings.Height; if (settings.Encoding is IColorEncodingKnownDimensions ifkd) { ifkd.Width = width; ifkd.Height = height; } var colors = new List <Color>(); var points = GetPointSequence(settings.Swizzle, settings.Width, settings.Height, settings.PadWidth, settings.PadHeight); foreach (var point in points) { int x = Clamp(point.X, 0, bmp.Width); int y = Clamp(point.Y, 0, bmp.Height); var color = bmp.GetPixel(x, y); if (settings.PixelShader != null) { color = settings.PixelShader(color); } colors.Add(color); } return(settings.Encoding.Save(colors)); }
/// <summary> /// /// </summary> /// <param name="input"></param> public KSLT(Stream input) { using (var br = new BinaryReaderX(input, true)) { _header = br.ReadType <FileHeader>(); br.BaseStream.Position = 0x40; _padding = br.ReadMultiple <UnkPadding>(_header.FileCount); var offsets = br.ReadMultiple <OffsetEntry>(_header.FileCount); var fileNames = new List <string>(); for (int i = 0; i < _header.FileCount; i++) { fileNames.Add(br.ReadCStringASCII()); } foreach (var o in offsets) { br.BaseStream.Position = o.Offset; var imgHeader = br.ReadType <ImageHeader>(); var texture = br.ReadBytes(imgHeader.DataSize); var settings = new ImageSettings(ImageFormats.Formats[0x0], imgHeader.Width, imgHeader.Height); Bitmaps.Add(new KsltBitmapInfo(Common.Load(texture, settings), new FormatInfo(0x0, ImageFormats.Formats[0x0].FormatName)) { Name = fileNames[offsets.IndexOf(o)], Header = imgHeader, ImageData = texture }); } } }
private void btnSaveRaw_Click(object sender, EventArgs e) { var sfd = new SaveFileDialog { InitialDirectory = Settings.Default.LastDirectory, FileName = Path.Combine(Path.GetDirectoryName(_filename), Path.GetFileNameWithoutExtension(_filename) + ".raw"), Filter = "Raw Image Data (*.raw)|*.raw" }; if (sfd.ShowDialog() != DialogResult.OK) { return; } var settings = new ImageSettings { Width = (int)numWidth.Value, Height = (int)numHeight.Value, Format = (Format)Enum.Parse(typeof(Format), cmbFormat.SelectedValue.ToString()), ZOrder = chkZOrder.Checked, PadToPowerOf2 = false, TileSize = (int)tileSize.Value, Orientation = (Cetera.Image.Orientation)Enum.Parse(typeof(Cetera.Image.Orientation), cmbOrientation.SelectedValue.ToString()) }; var imgSave = Common.Save((Bitmap)imbPreview.Image, settings); using (var bw = new BinaryWriterX(File.Create(sfd.FileName))) bw.Write(imgSave); }
public static ImageSettings getInstance() { if (instance != null) return instance; instance = new ImageSettings(); instance.parse(); return instance; }
public void Save(Stream output) { using (BinaryWriterX bw = new BinaryWriterX(output)) { //check for oringinal size //if (JTEXRawHeader.width != Image.Width || JTEXRawHeader.height != Image.Height) // throw new System.Exception($"Image has to be {JTEXRawHeader.width}x{JTEXRawHeader.height}px!"); //get texture settings = new ImageSettings { Width = Image.Width, Height = Image.Height, Format = Support.Format[JTEXRawHeader.format], Swizzle = new CTRSwizzle(Image.Width, Image.Height) }; byte[] resBmp = Kontract.Image.Common.Save(Image, settings); //Header JTEXRawHeader.width = NextPowerOfTwo(Image.Width); JTEXRawHeader.height = NextPowerOfTwo(Image.Height); JTEXRawHeader.virWidth = Image.Width; JTEXRawHeader.virHeight = Image.Height; bw.WriteStruct(JTEXRawHeader); //Image bw.BaseStream.Position = JTEXRawHeader.dataStart; bw.Write(resBmp); } }
public void Save(string filename) { //check original sizes for (int i = 0; i < TxObs.Count; i++) { if (bmps[i].Width != TxObs[i].width || bmps[i].Height != TxObs[i].height) { throw new Exception($"Image {i:00} has to be {TxObs[i].width}x{TxObs[i].height}px!"); } } using (var bw = new BinaryWriterX(File.OpenWrite(filename))) { bw.Write(list); for (int i = 0; i < TxObs.Count; i++) { bw.BaseStream.Position = TxObs[i].texDataOffset; var settings = new ImageSettings { Width = (int)TxObs[i].width, Height = (int)TxObs[i].height, Format = ImageSettings.ConvertFormat(TxObs[i].format), PadToPowerOf2 = false }; bw.Write(Common.Save(bmps[i], settings)); } } }
public TEXI(Stream input, Stream texi) { using (var br = new BinaryReaderX(input)) { seri = (SERIList) new XmlSerializer(typeof(SERIList)).Deserialize(XmlReader.Create(texi)); var width = (Integer)seri.Parameters.Find(x => x.Name == "w"); var height = (Integer)seri.Parameters.Find(x => x.Name == "h"); var mipMapCount = (Integer)seri.Parameters.Find(x => x.Name == "mipmap"); var format = (Integer)seri.Parameters.Find(x => x.Name == "format"); for (int i = 1; i <= ((mipMapCount.Value == 0) ? 1 : mipMapCount.Value); i++) { var settings = new ImageSettings { Width = width.Value, Height = height.Value, Format = ImageSettings.ConvertFormat((Format)format.Value), PadToPowerOf2 = false }; bmps.Add(Common.Load(br.ReadBytes(width.Value * height.Value * Common.GetBitDepth(ImageSettings.ConvertFormat((Format)format.Value)) / 8), settings)); width.Value /= 2; height.Value /= 2; } } }
// private IImageSettingsProvider imageSettingsProvider; public ImageSettingsAction(IImageHolder imageHolder, ImageSettings imageSettings, SettingsManager manager) { this.imageHolder = imageHolder; this.imageSettings = imageSettings; this.manager = manager; // this.imageSettingsProvider = provider; }
public void Save(string filename) { for (int i = 0; i < bmps.Count(); i++) { if (origValues[i].width != bmps[i].Width || origValues[i].height != bmps[i].Height) { throw new Exception("All BCH textures have to be the same size as the original!"); } } using (BinaryWriterX bw = new BinaryWriterX(File.Create(filename))) { bw.Write(_file); bw.BaseStream.Position = header.dataOffset; for (int i = 0; i < bmps.Count(); i++) { var settings = new ImageSettings { Width = bmps[i].Width, Height = bmps[i].Height, Format = Support.CTRFormat[origValues[i].format], Swizzle = new CTRSwizzle(bmps[i].Width, bmps[i].Height) }; bw.Write(Common.Save(bmps[i], settings)); bw.WriteAlignment(0x80); } } }
public static Bitmap Load(Stream input) { using (var br = new BinaryReaderX(input)) { //Header header = br.ReadStruct <Header>(); header.checkFormat(); //get tile table br.BaseStream.Position = header.tableDataOffset; byte[] table = Level5.Decompress(new MemoryStream(br.ReadBytes(header.tableSize1))); //get image data br.BaseStream.Position = header.tableDataOffset + header.tableSize2; byte[] tex = Level5.Decompress(new MemoryStream(br.ReadBytes(header.imgDataSize))); //order pic blocks by table byte[] pic = Order(new MemoryStream(table), new MemoryStream(tex)); //return finished image var settings = new ImageSettings { Width = header.width, Height = header.height, Format = ImageSettings.ConvertFormat(header.imageFormat), PadToPowerOf2 = false, ZOrder = false }; return(Common.Load(pic, settings)); } }
public SMDH(Stream input) { using (var br = new BinaryReaderX(input)) { //Header header = br.ReadStruct <Header>(); //Application Titles for (int i = 0; i < 0x10; i++) { shortDesc.Add(Encoding.GetEncoding("UTF-16").GetString(br.ReadBytes(0x80))); longDesc.Add(Encoding.GetEncoding("UTF-16").GetString(br.ReadBytes(0x100))); publisher.Add(Encoding.GetEncoding("UTF-16").GetString(br.ReadBytes(0x80))); } //Application Settings appSettings = new AppSettings(br.BaseStream); br.BaseStream.Position += 0x8; settings = new ImageSettings { Width = 24, Height = 24, Format = Format.RGB565, PadToPowerOf2 = false }; bmp = Common.Load(br.ReadBytes(0x480), settings); } }
public void RGBA8888_ZOrder() { var settings = new ImageSettings { Width = 4, Height = 4, Format = new RGBA(8, 8, 8, 8), TileSize = 4, InnerSwizzle = new ZOrder(), OuterSwizzle = new ZOrder() }; var tex = new byte[] { 255, 0xff, 0xff, 0xff, 255, 0xff, 0xff, 0xff, 255, 0xff, 0xff, 0xff, 255, 0xff, 0xff, 0xff, 255, 0x30, 0x30, 0x30, 255, 0x30, 0x30, 0x30, 255, 0x30, 0x30, 0x30, 255, 0x30, 0x30, 0x30, 255, 0x80, 0x80, 0x80, 255, 0x80, 0x80, 0x80, 255, 0x80, 0x80, 0x80, 255, 0x80, 0x80, 0x80, 255, 0x00, 0x00, 0x00, 255, 0x00, 0x00, 0x00, 255, 0x00, 0x00, 0x00, 255, 0x00, 0x00, 0x00, }; var bmp = Kontract.Image.Image.Load(tex, settings); }
public TagCloudVisualizer(ImageBox imageBox, ImageSettings imageSettings, List <Tag> tags) { ImageBox = imageBox; ImageSettings = imageSettings; this.tags = tags; Rectangles = tags.Select(tag => tag.Rectangle); }
private void btnRestoreImages_Click(object sender, EventArgs e) { Bitmap logo = Properties.Resources.logoalfresco; Bitmap img = Properties.Resources.logoalfrescosmall; Bitmap icon = Properties.Resources.alfresco; pictureBoxLogoConfig.Image = logo; pictureBoxImageConfig.Image = img; pictureBoxIconConfig.Image = icon; ImageSettings imageSettings = new ImageSettings(); imageSettings.Logo = null; imageSettings.HeadImage = null; imageSettings.Icon = null; currentIcon = null; currentImage = null; currentlogo = null; Option.SaveImageSettings(imageSettings); MessageBox.Show(UserInterfaceStrings.ImageSettingsRestored, UserInterfaceStrings.Settings, MessageBoxButtons.OK); ReloadSettings(); }
public IMGC(Stream input) { using (var br = new BinaryReaderX(input, true)) { //Header header = br.ReadType <IMGCHeader>(); if (header.imageFormat == 28 && header.bitDepth == 8) { editMode = true; header.imageFormat = 29; } //get tile table br.BaseStream.Position = header.tableDataOffset; var tableC = br.ReadBytes(header.tableSize1); tableComp = (CompressionMethod)(tableC[0] & 0x7); byte[] table = Compressor.Decompress(new MemoryStream(tableC)); //get image data br.BaseStream.Position = header.tableDataOffset + header.tableSize2; var texC = br.ReadBytes(header.imgDataSize); picComp = (CompressionMethod)(texC[0] & 0x7); byte[] tex = Compressor.Decompress(new MemoryStream(texC)); //order pic blocks by table byte[] pic = Order(new MemoryStream(table), new MemoryStream(tex)); //return finished image settings = new ImageSettings(Support.Format[header.imageFormat], header.width, header.height) { Swizzle = new ImgcSwizzle(header.width, header.height) }; Image = Kolors.Load(pic, settings); } }
public void Save(Stream output) { using (var bw = new BinaryWriterX(output)) { Header.Block1 = (uint)(HeaderInfo.Version | (HeaderInfo.Unknown1 << 12) | (HeaderInfo.Unused1 << 24) | ((int)HeaderInfo.AlphaChannelFlags << 28)); Header.Block2 = (uint)(HeaderInfo.MipMapCount | (HeaderInfo.Width << 6) | (HeaderInfo.Height << 19)); Header.Block3 = (uint)(HeaderInfo.Unknown2 | ((int)HeaderInfo.Format << 8) | (HeaderInfo.Unknown3 << 16)); bw.WriteStruct(Header); Settings.Format = ImageSettings.ConvertFormat(HeaderInfo.Format); var bitmaps = Bitmaps.Select(bmp => Common.Save(bmp, Settings)).ToList(); var offset = 0; foreach (var bitmap in bitmaps) { bw.Write(offset); offset += bitmap.Length; } foreach (var bitmap in bitmaps) { bw.Write(bitmap); } } }
public static Bitmap Load(Stream input) { using (var br = new BinaryReaderX(input)) { //check header header = br.ReadStruct <Header>(); header.checkConst(); //decompress table br.BaseStream.Position = header.tableDataOffset; tableComp = (Compression)(br.ReadUInt32() % 8); br.BaseStream.Position = header.tableDataOffset; byte[] table = CriWare.GetDecompressedBytes(new MemoryStream(br.ReadBytes(header.tableSize1))); //get decompressed picture data br.BaseStream.Position = header.tableDataOffset + header.tableSize2; picComp = (Compression)(br.ReadUInt32() % 8); br.BaseStream.Position = header.tableDataOffset + header.tableSize2; byte[] tex = CriWare.GetDecompressedBytes(new MemoryStream(br.ReadBytes(header.imgDataSize))); //order pic blocks by table byte[] pic = Order(new BinaryReaderX(new MemoryStream(table)), table.Length, new BinaryReaderX(new MemoryStream(tex)), header.width, header.height, header.bitDepth); //return decompressed picture data var settings = new ImageSettings { Width = header.width, Height = header.height, Orientation = Orientation.TransposeTile, Format = ImageSettings.ConvertFormat(header.imageFormat), PadToPowerOf2 = false }; return(Common.Load(pic, settings)); } }
public TEXI(Stream input, Stream texi) { using (var br = new BinaryReaderX(input)) { seri = (SERIList) new XmlSerializer(typeof(SERIList)).Deserialize(XmlReader.Create(texi)); var width = (Integer)seri.Parameters.Find(x => x.Name == "w"); var height = (Integer)seri.Parameters.Find(x => x.Name == "h"); var mipMapCount = (Integer)seri.Parameters.Find(x => x.Name == "mipmap"); var format = (Integer)seri.Parameters.Find(x => x.Name == "format"); for (int i = 1; i <= ((mipMapCount.Value == 0) ? 1 : mipMapCount.Value); i++) { settings = new ImageSettings { Width = width.Value, Height = height.Value, Format = Support.Format[format.Value], Swizzle = new CTRSwizzle(width.Value, height.Value) }; bmps.Add(Common.Load(br.ReadBytes(width.Value * height.Value * Support.Format[format.Value].BitDepth / 8), settings)); width.Value /= 2; height.Value /= 2; } } }
public void Save(Stream output) { using (BinaryWriterX bw = new BinaryWriterX(output)) { //check for oringinal size if (JTEXRawHeader.width != Image.Width || JTEXRawHeader.height != Image.Height) { throw new System.Exception($"Image has to be {JTEXRawHeader.width}x{JTEXRawHeader.height}px!"); } //get texture var settings = new ImageSettings { Width = Image.Width, Height = Image.Height, Format = ImageSettings.ConvertFormat(JTEXRawHeader.format), PadToPowerOf2 = false }; byte[] resBmp = Common.Save(Image, settings); //Header JTEXRawHeader.width = Image.Width; JTEXRawHeader.height = Image.Height; bw.WriteStruct(JTEXRawHeader); //Image bw.BaseStream.Position = JTEXRawHeader.dataStart; bw.Write(resBmp); } }
internal static void Load() { TomletMain.RegisterMapper(WriteColor, ReadColor); FilePath = Path.Combine(Core.FolderPath, "Config.cfg"); General = CreateCat <cGeneral>(FilePath, nameof(General)); bool UseDefault = true; if (!string.IsNullOrEmpty(General.Theme) && !General.Theme.Equals("Default") && !General.Theme.Equals("Random")) { try { // To-Do: Sanatize themeName General.Theme = General.Theme .Replace("\\", "") .Replace("/", ""); ThemePath = Path.Combine(Core.ThemesFolderPath, General.Theme); if (Directory.Exists(ThemePath)) { UseDefault = false; } else { throw new DirectoryNotFoundException(ThemePath); } } catch (Exception ex) { MelonLogger.Error($"Failed to find Start Screen Theme: {ex}"); } } if (General.Theme.Equals("Random")) { ThemePath = UIUtils.RandomFolder(Core.ThemesFolderPath); UseDefault = false; } if (UseDefault) { General.Theme = "Default"; ThemePath = Path.Combine(Core.ThemesFolderPath, General.Theme); if (!Directory.Exists(ThemePath)) { Directory.CreateDirectory(ThemePath); } } MelonLogger.Msg($"Using Start Screen Theme: \"{General.Theme}\""); Background = CreateCat <cBackground>(nameof(Background), true); LogoImage = CreateCat <LogoImageSettings>(nameof(LogoImage), true); LoadingImage = CreateCat <LoadingImageSettings>(nameof(LoadingImage), true); VersionText = CreateCat <VersionTextSettings>(nameof(VersionText), true); ProgressText = CreateCat <ProgressTextSettings>(nameof(ProgressText), true); ProgressBar = CreateCat <cProgressBar>(nameof(ProgressBar), true); MelonPreferences.SaveCategory <cGeneral>(nameof(General), false); }
public MTTEX(Stream input) { using (var br = new BinaryReaderX(input)) { Header = br.ReadStruct <Header>(); HeaderInfo = new HeaderInfo { // Block 1 Version = (int)(Header.Block1 & 0xFFF), Unknown1 = (int)((Header.Block1 >> 12) & 0xFFF), Unused1 = (int)((Header.Block1 >> 24) & 0xF), AlphaChannelFlags = (AlphaChannelFlags)((Header.Block1 >> 28) & 0xF), // Block 2 MipMapCount = (int)(Header.Block2 & 0x3F), Width = (int)((Header.Block2 >> 6) & 0x1FFF), Height = (int)((Header.Block2 >> 19) & 0x1FFF), // Block 3 Unknown2 = (int)(Header.Block3 & 0xFF), Format = (Format)((Header.Block3 >> 8) & 0xFF), Unknown3 = (int)((Header.Block3 >> 16) & 0xFFFF) }; var mipMaps = br.ReadMultiple <int>(HeaderInfo.MipMapCount); Settings.Format = ImageSettings.ConvertFormat(HeaderInfo.Format); for (var i = 0; i < mipMaps.Count; i++) { var texDataSize = (i + 1 < mipMaps.Count ? mipMaps[i + 1] : (int)br.BaseStream.Length) - mipMaps[i]; Settings.Width = HeaderInfo.Width >> i; Settings.Height = Math.Max(HeaderInfo.Height >> i, MinHeight); Bitmaps.Add(Common.Load(br.ReadBytes(texDataSize), Settings)); } } }
private static IClient CreateClient() { var builder = new ContainerBuilder(); builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(Program))).AsImplementedInterfaces(); builder.RegisterType <BoringWordsStorage>().AsSelf().SingleInstance(); builder.RegisterType <KeywordsStorage>().AsSelf().SingleInstance(); builder.RegisterType <Canvas>().AsSelf().SingleInstance(); builder.RegisterType <ApplicationWindow>().AsSelf(); builder.RegisterType <Preprocessor>().AsSelf(); builder.RegisterType <CloudPainter>().AsSelf(); var imageSettings = new ImageSettings { Height = 500, Width = 500, TextColor = Color.Crimson, BackdgoundColor = Color.Lavender }; builder.RegisterInstance(imageSettings).AsSelf().SingleInstance(); var fontSettings = new FontSettings(FontFamily.GenericSerif, 18, 40); builder.RegisterInstance(fontSettings).As <FontSettings>().SingleInstance(); builder.Register <Func <Canvas, ImageSettings, CloudPainter> >(c => { return((canvas, settings) => new CloudPainter(canvas, settings)); }); var container = builder.Build(); return(container.Resolve <IClient>()); }
public void Save(string filename) { for (int i = 0; i < bmps.Count(); i++) { if (origValues[i].width != bmps[i].Width || origValues[i].height != bmps[i].Height) { throw new Exception("All BCH textures have to be the same size as the original!"); } } using (BinaryWriterX bw = new BinaryWriterX(File.Create(filename))) { _stream.Position = 0; _stream.CopyTo(bw.BaseStream); bw.BaseStream.Position = header.dataOffset; for (int i = 0; i < bmps.Count(); i++) { var settings = new ImageSettings { Width = bmps[i].Width, Height = bmps[i].Height, Format = origValues[i].format, PadToPowerOf2 = false }; bw.Write(Common.Save(bmps[i], settings)); bw.WriteAlignment(0x80); } } }
public void GetImageSettingsError_WhenWidthOrHeightNotPositive( [Values(-100, -1, 0)] int dimension1, [Values(-100, -1, 0, 1, 100)] int dimension2) { ImageSettings.GetImageSettings("RosyBrown", dimension1, dimension2).IsSuccess.Should().BeFalse(); ImageSettings.GetImageSettings("RosyBrown", dimension2, dimension1).IsSuccess.Should().BeFalse(); }
public void Save(string filename) { using (var bw = new BinaryWriterX(File.Create(filename))) { List <byte> result = new List <byte>(); var settings = new ImageSettings { Width = 32, Height = 32, BitPerIndex = BitLength.Bit4 }; var palette = Common.CreatePalette(bmps[0]); var paletteB = Common.EncodePalette(palette, Format.BGR555); var tileData = Common.Save(bmps[0], settings, palette); result.AddRange(tileData); result.AddRange(paletteB); result.AddRange(titleInfo); var crc16 = Crc16.Create(result.ToArray()); header.crc16 = (ushort)crc16; bw.WriteStruct(header); bw.WritePadding(0x1c); bw.Write(result.ToArray()); } }
/// <summary> /// /// </summary> /// <param name="output"></param> public void Save(Stream output) { using (var bw = new BinaryWriterX(output, true)) { // Updates Header.Width = (short)Texture.Width; Header.Height = (short)Texture.Height; // Header bw.WriteType(Header); bw.WriteAlignment(); bw.WriteString(FileName, Encoding.ASCII, false); bw.WriteAlignment(); // Setup if (Header.Format == ImageFormat.Palette_8) { var settings = new PaletteImageSettings(Formats[ImageFormat.RGBA8888], PaletteFormats[ImageFormat.Palette_8], Header.Width, Header.Height); var data = Common.Save(Texture, Palette, settings); bw.Write(data.indexData); bw.Write(data.paletteData); } else { var settings = new ImageSettings(Formats[ImageFormat.RGBA8888], Header.Width, Header.Height); var data = Common.Save(Texture, settings); bw.Write(data); } } }
public PictureView() { InitializeComponent(); this.zoomFactor = 1; this.mainForm = mainForm as MainForm; this.currentFrame = 0; this.annotationManager = new AnnotationManager(); this.BorderStyle = BorderStyle.Fixed3D; this.imageSettings = new ImageSettings(); this.columnHeader1.Width = -2; this.annotationManager.AnnotationAdded += new AnnotationManager.CollectionChanged(annotationManager_AnnotationAdded); this.annotationManager.AnnotationDeleted += new AnnotationManager.CollectionChanged(annotationManager_AnnotationDeleted); this.annotationManager.AnnotationCleared += new AnnotationManager.CollectionCleared(annotationManager_AnnotationCleared); }
public ImageOptions(object[] attributes, string entityName) { var imageAttribute = attributes.OfType<ImageAttribute>().FirstOrDefault(); var imageSettingsAttributes = attributes.OfType<ImageSettingsAttribute>().ToList(); if (imageAttribute != null) { AllowedFileExtensions = imageAttribute.AllowedFileExtensions; MaxFileSize = imageAttribute.MaxFileSize; NameCreation = imageAttribute.NameCreation; IsMultiple = imageAttribute.IsMulti; Settings = new List<ImageSettings>(); } else { AllowedFileExtensions = FileUploadDefault.ImageExtensions; MaxFileSize = FileUploadDefault.MaxFileSize; NameCreation = NameCreation.OriginalFileName; Settings = new List<ImageSettings>(); } if (imageSettingsAttributes.Any()) { var length = imageSettingsAttributes.Count; Settings = new ImageSettings[length]; for (var i = 0; i < length; i++) { var settings = imageSettingsAttributes[i].Settings; settings.IsBig = imageSettingsAttributes[i].IsBig; settings.IsMiniature = imageSettingsAttributes[i].IsMiniature; Settings[i] = settings; } } else { Settings = new[] { new ImageSettings("Content/" + entityName) }; } }
static void Main(string[] args) { // TODO: Parse settings from commandline args // TODO: Delay parameter so the image doesn't render faster than the screen can handle. ImageSettings settings = new ImageSettings { //ImageLeft = 50, //ImageTop = 60, ImageMaxSize = new Size { Height = 30, Width = 30 }, //ImageCropStart = new Point { // X = 10, // Y = 10 //}, ImageCropSize = new Size { Height = 500, Width = 400 }, //ConsoleStart = new Point //{ // X = 10, // Y = 5 //}, //Converter = new GreyscalePixelConverterB() TransparencyColor = ConsoleColor.White, RenderStrategy = new ProgressiveRenderStrategy() }; Bitmap bitmap = (Bitmap)System.Drawing.Image.FromFile(args[0]); ConsoleImage.DrawAnimate(bitmap, () => Console.KeyAvailable, settings); Console.ReadKey(); }
public ImageSettingsAttribute(string subPath) { Settings = new ImageSettings(subPath, null, null); }
internal void ResetImageSettins() { imageSettings = new ImageSettings(); }
internal void IncreaseContrast() { if (this.currentDicomElement != null) { ImageSettings oldImageSettings = imageSettings; imageSettings = imageSettings.IncreaseContrast(); commandManager.Execute( new ChangeImageCommand(this, oldImageSettings, imageSettings)); } }
internal void DecreaseBrightness() { if (this.currentDicomElement != null) { ImageSettings oldImageSettings = imageSettings; imageSettings = imageSettings.DecreaseBrightness(); commandManager.Execute( new ChangeImageCommand(this, oldImageSettings, imageSettings)); } }
public ImageSettingsAttribute(string subPath, int width, int height) { Settings = new ImageSettings(subPath, width, height); }
private static void RegisterImageParts(IAppBuilder app, ContainerBuilder builder) { AmazonS3Settings amazonSettings = AmazonS3Settings.FromConfig(); ICommonLogger logger = new NLogLogger(); IFileStorage fileStorage = new AmazonFileStorage(logger, amazonSettings); var avatarImageSettings = new AvatarImageSettings() { DefaultImages = new List<string>() { "3ysYtgscfkekTqi5bS6XHw", "5eJ-trR5WUGEQZ49rzj2Kw", "cnGYOdKfX0iUKv1fmkB6KA" , "dC-HU2RSiUSEliqP_5HmwA", "EFgYkW-LTkSAxLvAE3DsvA", "Gi3Xoqq_4k2ZZy-Aa5vsyw" , "HwFfWSqQgUu5FMrrFvGiag", "Kyc0FjFlI0uQ2QyczDGvrg" , "Oh7YIBQofkubrcY7bs8RBw", "OsHpSXSr6EamPZzL0iwx0g", "pfP-ZQinnkOyZHpKzl-wBg" , "qBCQhTdEtECK559zxocntg", "QcvLm8Mdr0uLCVQv752V9g", "R0T754HITEuKho19rdnGXg" , "SiHl9pLsjUGLau9JZxEY_g", "tQ4JINIZAkq4lR2r3EVjhg", "VUqjCVsxAEmz9Yfcv24Q6A" , "vvt1gG9n30WHhiPhF2KttA", "YEVzYN1iZEKgOqi2LUsHCw", "_PIYJMjqLEShFOuWTAaCwA" }, TempDeleteAge = TimeSpan.FromDays(1), SizeLimit = 1124000, Targets = new List<ImageTargetParameters>() { new ImageTargetParameters() { TargetFormat = ImageFormat.Jpeg, ResizeType = ImageResizeType.FitAndFill, RoundCorners = false, Height = 100, Width = 100, PathCreator = new PathCreator() { UrlBase = fileStorage.GetBaseUrl(), TempRootFolder = Constants.IMAGE_TEMP_FOLDER_AVATAR, TempFolderFormat = null, TempNameFormat = "{0}{1}.jpeg", StaticRootFolder = Constants.IMAGE_STATIC_FOLDER_AVATAR, StaticFolderFormat = null, StaticNameFormat = "{0}.jpeg" } } } }; var previewImageSettings = new ImageSettings() { Name = Constants.IMAGE_SETTINGS_NAME_PREVIEW, TempDeleteAge = TimeSpan.FromDays(1), SizeLimit = 5124000, Targets = new List<ImageTargetParameters>() { new ImageTargetParameters() { TargetFormat = ImageFormat.Jpeg, ResizeType = ImageResizeType.FitAndFill, RoundCorners = false, Width = 750, Height = 420, PathCreator = new PathCreator() { UrlBase = fileStorage.GetBaseUrl(), TempRootFolder = Constants.IMAGE_TEMP_FOLDER_PREVIEW, TempFolderFormat = null, TempNameFormat = "{0}{1}.jpeg", StaticRootFolder = Constants.IMAGE_STATIC_FOLDER_PREVIEW, StaticFolderFormat = null, StaticNameFormat = "{0}.jpeg" } } } }; var contentImageSettings = new ImageSettings() { Name = Constants.IMAGE_SETTINGS_NAME_CONTENT, TempDeleteAge = TimeSpan.FromDays(1), SizeLimit = 1124000, Targets = new List<ImageTargetParameters>() { new ImageTargetParameters() { TargetFormat = ImageFormat.Jpeg, ResizeType = ImageResizeType.FitRatio, RoundCorners = false, Width = 600, Height = 600, PathCreator = new PathCreator() { UrlBase = fileStorage.GetBaseUrl(), TempRootFolder = Constants.IMAGE_TEMP_FOLDER_CONTENT, TempFolderFormat = null, TempNameFormat = "{0}{1}.jpeg", StaticRootFolder = Constants.IMAGE_STATIC_FOLDER_CONTENT, StaticFolderFormat = "{0}", StaticNameFormat = "{0}.jpeg" } } } }; var commentImageSettings = new ImageSettings() { Name = Constants.IMAGE_SETTINGS_NAME_COMMENT, TempDeleteAge = TimeSpan.FromDays(1), SizeLimit = 5124000, Targets = new List<ImageTargetParameters>() { new ImageTargetParameters() { TargetFormat = ImageFormat.Jpeg, ResizeType = ImageResizeType.FitRatio, Width = 600, Height = 600, RoundCorners = false, PathCreator = new PathCreator() { UrlBase = fileStorage.GetBaseUrl(), TempRootFolder = Constants.IMAGE_TEMP_FOLDER_COMMENT, TempFolderFormat = null, TempNameFormat = "{0}{1}.jpeg", StaticRootFolder = Constants.IMAGE_STATIC_FOLDER_COMMENT, StaticFolderFormat = "{0}", StaticNameFormat = "{0}.jpeg" } } } }; builder.RegisterInstance(fileStorage).As<IFileStorage>(); builder.RegisterType<ImageSettingsFactory>().As<IImageSettingsFactory>(); builder.RegisterInstance(avatarImageSettings).AsSelf(); builder.RegisterInstance(previewImageSettings).AsSelf(); builder.RegisterInstance(contentImageSettings).AsSelf().PreserveExistingDefaults(); builder.RegisterInstance(commentImageSettings).AsSelf().PreserveExistingDefaults(); builder.RegisterType<ContentImageQueries>().AsSelf(); builder.RegisterType<PreviewImageQueries>().AsSelf(); builder.RegisterType<AvatarImageQueries>().AsSelf(); builder.RegisterType<CommentImageQueries>().AsSelf(); }
private static void GenerateSprite(string relativeUrl, string path, ImageSettings settings, int x, int y, int spriteNumber, List<Bitmap> images, TextWriter cssOutput) { // Create a drawing surface and add the images to it using (Bitmap sprite = new Bitmap(x, y)) { using (Graphics drawingSurface = Graphics.FromImage(sprite)) { // Set the background to the specs from the settings file drawingSurface.Clear(settings.BackgroundColor); // Make the final sprite and save it int xOffset = 0; int yOffset = 0; foreach (Bitmap image in images) { drawingSurface.DrawImage(image, new Rectangle(xOffset, yOffset, image.Width, image.Height)); // Add the CSS data GenerateCss(relativeUrl, xOffset, yOffset, spriteNumber, settings.Format, image, cssOutput); if (settings.TileInYAxis) { yOffset += image.Height; } else { xOffset += image.Width; } } // Set the encoder parameters and make the image try { using (EncoderParameters spriteEncoderParameters = new EncoderParameters(1)) { spriteEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, settings.Quality); // Attempt to save the image to disk with the specified encoder sprite.Save(Path.Combine(path, "sprite" + spriteNumber + "." + settings.Format), GetEncoderInfo(settings.Format), spriteEncoderParameters); } } catch (Exception) { // If errors occur, get the CLI to auto-choose an encoder. Unfortunately this means that the quality settings will be not used. try { sprite.Save(Path.Combine(path, "sprite" + spriteNumber + "." + settings.Format)); } catch (Exception) { // If errors occur again, try to save as a png sprite.Save(Path.Combine(path, "sprite" + spriteNumber + ".png")); } } } } }
private static ImageSettings ReadSettings(string path) { ImageSettings settings = new ImageSettings(); XmlTextReader settingsData; // Open the settings file. If it cannot be opened, or one cannot be found, use defaults try { using (settingsData = new XmlTextReader(Path.Combine(path, SettingsFileName))) { while (settingsData.Read()) { if (settingsData.NodeType == XmlNodeType.Element) { string nodeName = settingsData.Name; if (nodeName.Equals("FileFormat", StringComparison.OrdinalIgnoreCase)) { settings.Format = settingsData.ReadElementContentAsString().Trim('.'); } else if (nodeName.Equals("Quality", StringComparison.OrdinalIgnoreCase)) { settings.Quality = settingsData.ReadElementContentAsInt(); } else if (nodeName.Equals("MaxSize", StringComparison.OrdinalIgnoreCase)) { settings.MaxSize = settingsData.ReadElementContentAsInt(); } else if (nodeName.Equals("BackgroundColor", StringComparison.OrdinalIgnoreCase)) { string output = settingsData.ReadElementContentAsString(); int temp = Int32.Parse(output, System.Globalization.NumberStyles.HexNumber); settings.BackgroundColor = Color.FromArgb(temp); } else if (nodeName.Equals("TileInYAxis", StringComparison.OrdinalIgnoreCase)) { settings.TileInYAxis = settingsData.ReadElementContentAsBoolean(); } } } } return settings; } // If any other exceptions occur, use the default values catch (Exception) { return null; } }
public ChangeImageCommand(PictureView form1, ImageSettings oldValue, ImageSettings newValue) { this.oldValue = oldValue; this.newValue = newValue; this.pictureView = form1; }
private static void PerformOptimizations(string cssPath, string path, ImageSettings settings, TextWriter cssOutput, List<string> imageLocations) { // Create a list containing each image (in Bitmap format), and calculate the total size (in pixels) of final image int x = 0; int y = 0; int imageIndex = 0; long size = 0; int spriteNumber = 0; List<Bitmap> images = new List<Bitmap>(); string relativeUrl = path.Replace(cssPath, string.Empty).Replace(@"\", "/").TrimStart('/'); if (!string.IsNullOrEmpty(relativeUrl)) relativeUrl += "/"; try { foreach (string imagePath in imageLocations) { // If the image is growing above the specified max file size, make the sprite with the existing images // and add the new image to the next sprite list if ((imageIndex > 0) && IsSpriteOversized(settings.MaxSize, size, imagePath)) { GenerateSprite(relativeUrl, path, settings, x, y, spriteNumber, images, cssOutput); // Clear the existing images foreach (Bitmap image in images) { image.Dispose(); } // Reset variables to initial values, and increment the spriteNumber images.Clear(); x = 0; y = 0; imageIndex = 0; size = 0; spriteNumber++; } // Add the current image to the list of images that are to be processed images.Add(new Bitmap(imagePath)); // Use the image tag to store its name images[imageIndex].Tag = MakeCssClassName(imagePath); // Find the total pixel size of the sprite based on the tiling direction if (settings.TileInYAxis) { y += images[imageIndex].Height; if (x < images[imageIndex].Width) { x = images[imageIndex].Width; } } else { x += images[imageIndex].Width; if (y < images[imageIndex].Height) { y = images[imageIndex].Height; } } // Update the filesize size of the bitmap list size += (new FileInfo(imagePath)).Length; imageIndex++; } // Merge the final list of bitmaps into a sprite if (imageIndex != 0) GenerateSprite(relativeUrl, path, settings, x, y, spriteNumber, images, cssOutput); } finally // Close the CSS file and clear the images list { foreach (Bitmap image in images) { image.Dispose(); } images.Clear(); } }