public static void Run() { // ExStart:SpecifyTransparency // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); // Initialize variables to hold width & height values int width = 0; int height = 0; // Initialize an array of type Color to hold the pixel data Color[] pixels = null; // Create an instance of RasterImage and load a BMP image using (RasterImage raster = (RasterImage)Image.Load(dataDir + "aspose_logo.png")) { // Store the width & height in variables for later use width = raster.Width; height = raster.Height; // Load the pixels of RasterImage into the array of type Color pixels = raster.LoadPixels(new Rectangle(0, 0, width, height)); } // Create & initialize an instance of PngImage while specifying size and PngColorType using (PngImage png = new PngImage(width, height, PngColorType.TruecolorWithAlpha)) { // Save the previously loaded pixels on to the new PngImage and Set TransparentColor property to specify which color to be rendered as transparent png.SavePixels(new Rectangle(0, 0, width, height), pixels); png.TransparentColor = Color.Black; png.HasTransparentColor = true; png.Save(dataDir + "SpecifyTransparencyforPNGImages_out.jpg"); } // ExEnd:SpecifyTransparency }
public static void Run() { // ExStart:SpecifyTransparency // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); // Initialize variables to hold width & height values int width = 0; int height = 0; // Initialize an array of type Color to hold the pixel data Color[] pixels = null; // Create an instance of RasterImage and load a BMP image using (RasterImage raster = (RasterImage)Image.Load(dataDir + "aspose_logo.png")) { // Store the width & height in variables for later use width = raster.Width; height = raster.Height; // Load the pixels of RasterImage into the array of type Color pixels = raster.LoadPixels(new Rectangle(0, 0, width, height)); } // Create & initialize an instance of PngImage while specifying size and PngColorType using (PngImage png = new PngImage(width, height, PngColorType.TruecolorWithAlpha)) { // Save the previously loaded pixels on to the new PngImage and Set TransparentColor property to specify which color to be rendered as transparent png.SavePixels(new Rectangle(0, 0, width, height), pixels); png.TransparentColor = Color.Black; png.HasTransparentColor = true; png.Save(dataDir + "SpecifyTransparencyforPNGImages_out.jpg"); } // ExEnd:SpecifyTransparency }
public static void Run() { //ExStart:ImportImageToPSDLayer // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load a PSD file as an image and caste it into PsdImage using (PsdImage image = (PsdImage)Image.Load(dataDir + "sample.psd")) { //Extract a layer from PSDImage Layer layer = image.Layers[1]; // Create an image that is needed to be imported into the PSD file. using (PngImage drawImage = new PngImage(200, 200)) { // Fill image surface as needed. Graphics g = new Graphics(drawImage); g.Clear(Color.Yellow); // Call DrawImage method of the Layer class and pass the image instance. layer.DrawImage(new Point(10, 10), drawImage); } // Save the results to output path. image.Save(dataDir + "ImportImageToPSDLayer_out.psd"); } //ExEnd:ImportImageToPSDLayer }
public static void Run() { // ExStart:SupportForJPEGBITS // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); int bpp = 2; // Set 2 bits per sample to see the difference in size and quality // The origin PNG with 8 bits per sample string originPngFileName = System.IO.Path.Combine(dataDir, "lena_16g_lin.png"); // The output JPEG-LS with 2 bits per sample. string outputJpegFileName = "lena24b " + bpp + "-bit Gold.jls"; using (PngImage pngImage = (PngImage)Image.Load(originPngFileName)) { JpegOptions jpegOptions = new JpegOptions(); jpegOptions.BitsPerChannel = (byte)bpp; jpegOptions.CompressionType = JpegCompressionMode.JpegLs; pngImage.Save(outputJpegFileName, jpegOptions); } // The output PNG is produced from JPEG-LS to check image visually. string outputPngFileName = "lena24b " + bpp + "-bit Gold.png"; using (JpegImage jpegImage = (JpegImage)Image.Load(outputJpegFileName)) { jpegImage.Save(outputPngFileName, new PngOptions()); } }
public static void Run() { //ExStart:ChangeBackgroundColor // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load a PSD file as an image and cast it into PsdImage using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) { // Convert to PngImage based on PsdImage. using (PngImage pngImage = new PngImage(psdImage)) { int[] pixels = pngImage.LoadArgb32Pixels(pngImage.Bounds); // Iterate through the pixel array and Check the pixel information //that if it is a transparent color pixel and Change the pixel color to white int transparent = pngImage.TransparentColor.ToArgb(); int replacementColor = Color.Yellow.ToArgb(); for (int i = 0; i < pixels.Length; i++) { if (pixels[i] == transparent) { pixels[i] = replacementColor; } } // Replace the pixel array into the image. pngImage.SaveArgb32Pixels(pngImage.Bounds, pixels); pngImage.Save(dataDir + "ChangeBackground_out.png"); } } //ExEnd:ChangeBackgroundColor }
public static MeshGroup FromFbx(string filePath) { const float Scale = 1.0f; var assimp = new Assimp.AssimpContext(); var scene = assimp.ImportFile(filePath, Assimp.PostProcessSteps.PreTransformVertices); var baseFilePath = Path.GetDirectoryName(filePath); TexList = new List <string>(); TextureData = new List <Tm2>(); foreach (Assimp.Material mat in scene.Materials) { TexList.Add(Path.GetFileName(mat.TextureDiffuse.FilePath)); Stream str = File.OpenRead(TexList[TexList.Count - 1]); PngImage png = new PngImage(str); Tm2 tmImage = Tm2.Create(png); TextureData.Add(tmImage); } int childCount = scene.RootNode.ChildCount; return(new MeshGroup() { MeshDescriptors = scene.Meshes .Select(x => { var vertices = new PositionColoredTextured[x.Vertices.Count]; for (var i = 0; i < vertices.Length; i++) { vertices[i].X = x.Vertices[i].X * Scale; vertices[i].Y = x.Vertices[i].Y * Scale; vertices[i].Z = x.Vertices[i].Z * Scale; vertices[i].Tu = x.TextureCoordinateChannels[0][i].X; vertices[i].Tv = 1.0f - x.TextureCoordinateChannels[0][i].Y; vertices[i].R = 1.0f; vertices[i].G = 1.0f; vertices[i].B = 1.0f; vertices[i].A = 1.0f; } return new MeshDescriptor { Vertices = vertices, Indices = x.GetIndices(), IsOpaque = true, TextureIndex = x.MaterialIndex }; }).ToList() }); }
public static void Run() { //ExStart:ChangeWindowSize string dataDir = RunExamples.GetDataDir_PNG(); string sourceFile = @"test.png"; string outputFile = "result.png"; using (PngImage image = (PngImage)Image.Load(dataDir + sourceFile)) { image.BinarizeBradley(10, 20); image.Save(dataDir + outputFile); } //ExEnd:ChangeWindowSize }
public static void Run() { //ExStart:PNGtoPDF string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); using (PngImage image = (PngImage)Image.Load(dataDir + "test.png")) { Aspose.Imaging.ImageOptions.PdfOptions exportOptions = new Aspose.Imaging.ImageOptions.PdfOptions(); exportOptions.PdfDocumentInfo = new Aspose.Imaging.FileFormats.Pdf.PdfDocumentInfo(); image.Save(dataDir + "test.pdf", exportOptions); } //ExEnd:PNGtoPDF }
public static void Run() { Console.WriteLine("Running example PNGtoPDF"); string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); using (PngImage image = (PngImage)Image.Load(dataDir + "sample.png")) { Aspose.Imaging.ImageOptions.PdfOptions exportOptions = new Aspose.Imaging.ImageOptions.PdfOptions(); exportOptions.PdfDocumentInfo = new Aspose.Imaging.FileFormats.Pdf.PdfDocumentInfo(); image.Save(dataDir + "test.pdf", exportOptions); } Console.WriteLine("Finished example PNGtoPDF"); }
static void Run() { var pngImage = new PngImage(File.ReadAllBytes("d:\\WImageTest\\test1.png")); var bmpImage = new BmpImage(pngImage.Width, pngImage.Height, BPP.ThirtyTwo); //pngImage.t(bmpImage.Data); //bmpImage.SaveToFile("output.bmp"); //var ddsTexture = new DdsTexture(File.ReadAllBytes("../Textures/Mob.dds")); //ddsTexture.SaveToFile("Mod.dds"); //var ddsTextureCompressed = new DdsTexture(File.ReadAllBytes("../Textures/Mob_dx3.dds")); //ddsTextureCompressed.SaveToFile("Mob_dx3.dds"); }
public static void Run() { // ExStart:ApplyFilterMethod // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); using (PngImage png = (PngImage)Image.Load(dataDir + "aspose_logo.png")) { // Create an instance of PngOptions, Set the PNG filter method and Save changes to the disc PngOptions options = new PngOptions(); options.FilterType = PngFilterType.Paeth; png.Save(dataDir + "ApplyFilterMethod_out.jpg", options); } // ExEnd:ApplyFilterMethod }
private static Imgd CreateImageImd(Context context, AssetFile source) { var srcFile = context.GetSourceModAssetPath(source.Name); using var srcStream = File.OpenRead(srcFile); if (PngImage.IsValid(srcStream)) { var png = PngImage.Read(srcStream); return(Imgd.Create(png.Size, png.PixelFormat, png.GetData(), png.GetClut(), source.IsSwizzled)); } else if (Imgd.IsValid(srcStream)) { return(Imgd.Read(srcStream)); } throw new Exception($"Image source '{source.Name}' not recognized"); }
public static void Run() { // ExStart:SpecifyBitDepth // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); // Load an existing PNG image using (PngImage png = (PngImage)Image.Load(dataDir + "aspose_logo.png")) { // Create an instance of PngOptions, Set the desired ColorType, BitDepth according to the specified ColorType and save image PngOptions options = new PngOptions(); options.ColorType = PngColorType.Grayscale; options.BitDepth = 1; png.Save(dataDir + "SpecifyBitDepth_out.jpg", options); } // ExEnd:SpecifyBitDepth }
public void GetAttributeByNameShouldRetrieveImage() { Image imageValue = new PngImage(Encoding.UTF8.GetBytes("Value")); var initialAttribute = new YotiAttribute <Image>( name: Constants.UserProfile.SelfieAttribute, value: imageValue, anchors: null); YotiProfile userProfile = new YotiProfile(); userProfile.Add(initialAttribute); YotiAttribute <Image> imageAttribute = userProfile.GetAttributeByName <Image>(Constants.UserProfile.SelfieAttribute); Assert.AreEqual(imageValue, imageAttribute.GetValue()); }
public static void Run() { // ExStart:Imagetransparency // The path to the documents directory. string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages(); string filePath = "Flower.png"; // specify your path using (PngImage image = (PngImage)Image.Load(filePath)) { float opacity = image.ImageOpacity; // opacity = 0,470798 Console.WriteLine(opacity); if (opacity == 0) { // The image is fully transparent. } } }
public override void init() { try { RustyGL.glViewport (0, 0, width, height); RustyGL.glEnable ((uint)RustyGL.GL_TEXTURE_2D); RustyGL.glEnable ((uint)RustyGL.GL_DEPTH_TEST); RustyGL.glEnable ((uint)RustyGL.GL_BLEND); RustyGL.glBlendFunc ((uint)RustyGL.GL_SRC_ALPHA, (uint)RustyGL.GL_ONE_MINUS_SRC_ALPHA); JupiterCSHARP.startJupiter (); File.setBase("/home/pavel/workspace/Jupiter/samples/Box"); var shader = new FileShader(new File("Resources/sprite.vs"), new File("Resources/sprite.fs")); var bgImage = new PngImage("Resources/bg.png"); var bg = new Transform (); bg.translate(0, 0, -1); bg.setScaleF(0.02f); bg.addNode(new Sprite(new ImageTexture(bgImage), new ImageShape(bgImage), shader)); var rootNode = new Node(); var cameraTrans = new Transform(0, 0, -20); var camera = new Camera(cameraTrans, new Perspective(45.0f, width * 1.0f / height * 1.0f, 1.0f, 1000.0f)); camera.addNode(cameraTrans); camera.addNode(bg); rootNode.addNode(camera); game = new Game(); game.setRootNode(rootNode); game.addVisitor(new RenderVisitor()); game.setWidth(width); game.setHeight(height); } catch (Exception ex) { Console.WriteLine ("init exception " + ex.Message); } }
public static void Run() { Console.WriteLine("Running example Imagetransparency"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); string filePath = System.IO.Path.Combine(dataDir, "sample.png"); // specify your path using (PngImage image = (PngImage)Image.Load(filePath)) { float opacity = image.ImageOpacity; // opacity = 0,470798 Console.WriteLine(opacity); if (opacity == 0) { // The image is fully transparent. } } Console.WriteLine("Finished example Imagetransparency"); }
public static void Run() { //ExStart:SpecifyTransparency // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load a PSD file as an image and cast it into PsdImage using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) { // Initialize PNG image with psd image pixel data. using (PngImage pngImage = new PngImage(psdImage)) { // specify the PNG image transparency options and save to file. pngImage.TransparentColor = Color.White; pngImage.HasTransparentColor = true; pngImage.Save(dataDir + "Specify_Transparency_result.png"); } } //ExEnd:SpecifyTransparency }
public static void Run() { Console.WriteLine("Running example SettingResolution"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); // Initialize variables to hold width & height values int width = 0; int height = 0; // Initialize an array of type Color to hold the pixel data Color[] pixels = null; // Create an instance of RasterImage and load a BMP image using (RasterImage raster = (RasterImage)Image.Load(dataDir + "aspose_logo.png")) { // Store the width & height in variables for later use width = raster.Width; height = raster.Height; // Load the pixels of RasterImage into the array of type Color pixels = raster.LoadPixels(new Rectangle(0, 0, width, height)); } // Create & initialize an instance of PngImage while specifying size and PngColorType using (PngImage png = new PngImage(width, height)) { // Save the previously loaded pixels on to the new PngImage png.SavePixels(new Rectangle(0, 0, width, height), pixels); // Create an instance of PngOptions, Set the horizontal & vertical resolutions and Save the result on disc PngOptions options = new PngOptions(); options.ResolutionSettings = new ResolutionSetting(72, 96); png.Save(dataDir + "SettingResolution_output.png", options); } Console.WriteLine("Finished example SettingResolution"); }
public static void Run() { // ExStart:SettingResolution // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); // Initialize variables to hold width & height values int width = 0; int height = 0; // Initialize an array of type Color to hold the pixel data Color[] pixels = null; // Create an instance of RasterImage and load a BMP image using (RasterImage raster = (RasterImage)Image.Load(dataDir + "aspose_logo.png")) { // Store the width & height in variables for later use width = raster.Width; height = raster.Height; // Load the pixels of RasterImage into the array of type Color pixels = raster.LoadPixels(new Rectangle(0, 0, width, height)); } // Create & initialize an instance of PngImage while specifying size and PngColorType using (PngImage png = new PngImage(width, height)) { // Save the previously loaded pixels on to the new PngImage png.SavePixels(new Rectangle(0, 0, width, height), pixels); // Create an instance of PngOptions, Set the horizontal & vertical resolutions and Save the result on disc PngOptions options = new PngOptions(); options.ResolutionSettings = new ResolutionSetting(72, 96); png.Save(dataDir + "SettingResolution_output.png", options); } // ExEnd:SettingResolution }
public static MeshGroup FromFbx(string filePath) { const float Scale = 1.0f; var assimp = new Assimp.AssimpContext(); var scene = assimp.ImportFile(filePath, Assimp.PostProcessSteps.PreTransformVertices); var BoneScene = assimp.ImportFile(filePath); var baseFilePath = Path.GetDirectoryName(filePath); TexList = new List <string>(); TextureData = new List <Tm2>(); BoneData = new List <Assimp.Bone>(); NodeData = new List <Assimp.Node>(); foreach (Assimp.Material mat in scene.Materials) { Stream str = null; var name = Path.GetFileName(mat.TextureDiffuse.FilePath); if (name != "" || name != null) { str = File.OpenRead(name); } if (str != null) { TexList.Add(Path.GetFileName(mat.TextureDiffuse.FilePath)); PngImage png = new PngImage(str); Tm2 tmImage = Tm2.Create(png); TextureData.Add(tmImage); } } Assimp.Bone rBone = new Assimp.Bone(); foreach (var m in BoneScene.Meshes) { foreach (var bn in m.Bones) { if (!BoneData.Contains(bn)) { BoneData.Add(bn); } } } NodeData.AddRange(BoneScene.RootNode.Children.ToList()); return(new MeshGroup() { MeshDescriptors = scene.Meshes .Select(x => { var vertices = new PositionColoredTextured[x.Vertices.Count]; for (var i = 0; i < vertices.Length; i++) { vertices[i].X = x.Vertices[i].X * Scale; vertices[i].Y = x.Vertices[i].Y * Scale; vertices[i].Z = x.Vertices[i].Z * Scale; vertices[i].Tu = x.TextureCoordinateChannels[0][i].X; vertices[i].Tv = 1.0f - x.TextureCoordinateChannels[0][i].Y; vertices[i].R = x.VertexColorChannels[0][i].R; vertices[i].G = x.VertexColorChannels[0][i].G; vertices[i].B = x.VertexColorChannels[0][i].B; vertices[i].A = x.VertexColorChannels[0][i].A; } return new MeshDescriptor { Vertices = vertices, Indices = x.GetIndices(), IsOpaque = true, TextureIndex = x.MaterialIndex }; }).ToList() }); }
public void Build(string fn, bool hiRez) { // TODO: HiRez, blockWidth and blockHeight should come from the RepoFile. MapInfoWithColorMap miwcm = ReadFromJson(fn); int maxIterations = miwcm.MapInfo.MaxIterations; ColorMap colorMap = miwcm.ColorMap; string repofilename = miwcm.MapInfo.Name; //ValueRecords<KPoint, MapSectionWorkResult> countsRepo = new ValueRecords<KPoint, MapSectionWorkResult>(repofilename, useHiRezFolder: hiRez); //int blockLength = BlockWidth * BlockHeight; //MapSectionWorkResult workResult = new MapSectionWorkResult(blockLength, hiRez: hiRez, includeZValuesOnRead: false); //CanvasSize imageSizeInBlocks = GetImageSizeInBlocks(countsRepo); int blockLength = BlockWidth * BlockHeight; CountsRepoReader countsRepoReader = new CountsRepoReader(repofilename, hiRez, BlockWidth, BlockHeight); CanvasSize imageSizeInBlocks = GetImageSizeInBlocks(countsRepoReader); int w = imageSizeInBlocks.Width; int h = imageSizeInBlocks.Height; CanvasSize imageSize = new CanvasSize(w * BlockWidth, h * BlockHeight); string imagePath = GetImageFilename(fn, imageSize.Width, hiRez, BasePath); KPoint key = new KPoint(0, 0); using (PngImage pngImage = new PngImage(imagePath, imageSize.Width, imageSize.Height)) { for (int vBPtr = 0; vBPtr < h; vBPtr++) { key.Y = vBPtr; for (int lPtr = 0; lPtr < 100; lPtr++) { ImageLine iLine = pngImage.ImageLine; int linePtr = vBPtr * BlockHeight + lPtr; for (int hBPtr = 0; hBPtr < w; hBPtr++) { key.X = hBPtr; //if (countsRepo.ReadParts(key, workResult)) //{ // int[] allCounts = workResult.Counts; // int[] countsForThisLine = GetOneLineFromCountsBlock(allCounts, lPtr); // BuildPngImageLineSegment(hBPtr * BlockWidth, countsForThisLine, iLine, maxIterations, colorMap); //} //else //{ // BuildBlankPngImageLineSegment(hBPtr * BlockWidth, BlockWidth, iLine); //} int[] countsForThisLine = countsRepoReader.GetCounts(key, lPtr); if (countsForThisLine != null) { BuildPngImageLineSegment(hBPtr * BlockWidth, countsForThisLine, iLine, maxIterations, colorMap); } else { BuildBlankPngImageLineSegment(hBPtr * BlockWidth, BlockWidth, iLine); } } pngImage.WriteLine(iLine); } } } }
public static List <MeshGroup> FromFbx(string filePath) { List <MeshGroup> group = new List <MeshGroup>(); const float Scale = 1.0f; var assimp = new Assimp.AssimpContext(); var scene = assimp.ImportFile(filePath, Assimp.PostProcessSteps.PreTransformVertices); var baseFilePath = Path.GetDirectoryName(filePath); TexList = new List <string>(); TextureData = new List <Tm2>(); foreach (Assimp.Material mat in scene.Materials) { TexList.Add(Path.GetFileName(mat.TextureDiffuse.FilePath)); Stream str = File.OpenRead(TexList[TexList.Count - 1]); PngImage png = new PngImage(str); Tm2 tmImage = Tm2.Create(png); TextureData.Add(tmImage); } for (int i = 0; i < scene.RootNode.ChildCount; i++) { Node child = scene.RootNode.Children[i]; MeshGroup currentMeshGroup = new MeshGroup(); currentMeshGroup.MeshDescriptors = new List <MeshDescriptor>(); // Get meshes by ID. foreach (int j in child.MeshIndices) { MeshDescriptor meshDescriptor = new MeshDescriptor(); Mesh x = scene.Meshes[j]; var vertices = new PositionColoredTextured[x.Vertices.Count]; for (var k = 0; k < vertices.Length; k++) { vertices[k].X = x.Vertices[k].X * Scale; vertices[k].Y = x.Vertices[k].Y * Scale; vertices[k].Z = x.Vertices[k].Z * Scale; vertices[k].Tu = x.TextureCoordinateChannels[0][k].X; vertices[k].Tv = 1.0f - x.TextureCoordinateChannels[0][k].Y; vertices[k].R = x.VertexColorChannels[0][i].R; vertices[k].G = x.VertexColorChannels[0][i].G; vertices[k].B = x.VertexColorChannels[0][i].B; vertices[k].A = x.VertexColorChannels[0][i].A; } meshDescriptor.Vertices = vertices; meshDescriptor.Indices = x.GetIndices(); meshDescriptor.IsOpaque = false; meshDescriptor.TextureIndex = x.MaterialIndex; currentMeshGroup.MeshDescriptors.Add(meshDescriptor); } group.Add(currentMeshGroup); } return(group); }