Skia Sharp Basic Cover

SkiaSharp basics

Getting Started With SkiaSharp Requirements Visual Studio Code (VS Code) Polyglot Notebook Extension A little bit of experience in C# Quick Setup This guide will walk you through the basic setup and usage of SkiaSharp in VS Code. Step 1: Create a Notebook File Open VS Code. Create a new file and name it Basic.ipynb or any name with the extension .ipynb or .dib. Step 2: Install SkiaSharp Library In the first cell of your notebook, type the following command to download the SkiaSharp library from the NuGet package repository: ...

June 14, 2024 · 2 min · 313 words · PrashantUnity
Google Drive Logo

Drive folder IDs

Overview Suppose you want to extract the ID of all items that reside in a folder of Google Drive. There are many ways to do this, like manually copying from each file or programmatically. I will guide you on how to do this using a program in C# Requirements Shared Google Drive Folder id /URL 1 https://drive.google.com/drive/u/4/folders/1759s8Jule46RCPypiQ5y3wLh5aCPlrK6 IDE like VS Code or Visual Studio preferred. Latest .NET SDK installed. You can get it from here Steps 1 Open IDE or code editor. Create a new console app using IDE or through this command in terminal ...

June 13, 2024 · 4 min · 707 words · PrashantUnity
Image TO PDF Basic Cover

Images to PDF

Steps Requirements Visual Studio Code (VS Code) Polyglot Notebook Extension Basic Setup Knowledge Visit Basic Setup for initial setup instructions. Install .NET SDK If not Installed From Official Website File Setup Install Visual Studio Code If not already installed, download and install VS Code. Open the Folder with Your Image Files Navigate to the folder where your image files are located. Open Terminal in the Folder For Windows: Right-click in the folder, select “Show More Options,” and then “Open in Terminal.” Alternatively, type cmd in the folder path and press Enter. In the terminal, type code . (code followed by a space and a period) to open VS Code in that folder. If the above methods don’t work, search for VS Code in your PC’s start menu and open it, then follow the live video for an alternative method: ...

June 10, 2024 · 3 min · 629 words · PrashantUnity
Download Logo

Install SDK & IDE (Ch. 1)

For PC/Mac/Linux Users Install the Software Development Kit (SDK) Download the official SDK from here. 1 https://dotnet.microsoft.com/en-us/download/visual-studio-sdks Choose the appropriate SDK based on your operating system. Follow the on-screen instructions to complete the installation. Download an Integrated Development Environment (IDE) or Code Editor of Your Choice Visual Studio Community Version: Download it here and click on “Free Download”. 1 https://visualstudio.microsoft.com/downloads/ Visual Studio Code: Download it here. 1 https://code.visualstudio.com/?wt.mc_id=vscom_downloads JetBrains Rider: Download it here. 1 https://www.jetbrains.com/rider/ Many more IDEs are available, like Eclipse, etc. Installation Instructions Open the downloaded file. Follow the on-screen instructions to complete the installation. For Users Without a PC or Those Who Don’t Want to Download Software Use an Online IDE SharpLab Paiza.io Dotnet Fiddle Programiz One Compiler W3Schools OnlineGDB For Visual Studio Code Users Install the Polyglot extension for enhanced language support.

June 15, 2024 · 1 min · 136 words · PrashantUnity
Generate Thumbnail

Cover art in SkiaSharp

Creating Cover Images with SkiaSharp Cover on this website is generated using SkiaSharp Only Requirements Visual Studio Code (VS Code) Polyglot Notebook Extension A little bit of experience in C# For Basic/Installation please visit Basic Setup Code Install SkiaSharp 1 #r "nuget:SkiaSharp" Import SkiaSharp Library 1 using SkiaSharp; Code To Generate Cover Or Thumbnail 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 int width = 640; int height = 220; int marginY = -10; int marginX = -10; string Numbering ="1"; string mainText ="SKIA SHARP"; string subText = "Generate Thumbnail | Polyglot Notebook"; string backGroundColor ="#003366"; string textColor = "#ffffff"; string boderColor = "#ffffff"; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse(backGroundColor)); using (var paint = new SKPaint()) { paint.TextSize = width/ 10.0f; paint.IsAntialias = true; paint.Color = SKColor.Parse(textColor); paint.IsStroke = false; paint.StrokeWidth = 3; paint.TextAlign = SKTextAlign.Center; canvas.DrawText(mainText, width / 2f, height / 2f, paint); paint.TextSize = width/ 25.0f; paint.TextAlign = SKTextAlign.Right; canvas.DrawText(subText, width+marginX, height+marginY, paint); paint.TextSize = width/ 20.0f; canvas.DrawText(Numbering, (width/ 20.0f)*Numbering.Length,(width/ 20.0f)*1.25f, paint); paint.IsStroke = true; paint.TextAlign = SKTextAlign.Center; paint.Color = SKColor.Parse(textColor); } SKFileWStream fs = new("cover.jpg"); bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 50); bmp.Display();

June 14, 2024 · 2 min · 215 words · PrashantUnity
Generate Thumbnail

Images on a Skia canvas

Requirements VS Code with Polyglot Notebook .Net Installed Open VS Code create new File Image.ipynb Import SkiaSharp Library Open Image.ipynb File select .Net Interactive as Kernel Create cell inside File 1 2 3 #r "nuget:SkiaSharp" using SkiaSharp; using System.IO; Image Drawer Function Create New Cell and Paste below code 1 2 3 4 5 6 7 8 9 10 11 void DrawImage(string path, SKCanvas canvas, float x = 0, float y = 0) { using (var inputStream = File.OpenRead(path)) { using (var inputBitmap = SKBitmap.Decode(inputStream)) { var imageInfo = new SKImageInfo(inputBitmap.Width, inputBitmap.Height); canvas.DrawBitmap(inputBitmap, x , y); } } } Skia SHarp Setup 1 2 3 4 5 6 7 8 9 10 11 12 int width = 1280; int height = 640; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true, StrokeWidth = 3, ColorF = SKColor.Parse("#003366") }; Uses of Function Created earlier for Importing Image 1 2 3 4 5 6 7 8 DrawImage("image.png", canvas,10, 10); // For saving the image as a file using (SKFileWStream fs = new("image.jpg")) { bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 50); } bmp.Display() That all needed to use image in SkiaSharp

July 20, 2024 · 1 min · 197 words · PrashantUnity
Generate Thumbnail

Triangle illusions

Setup 1 2 #r "nuget:SkiaSharp" using SkiaSharp; Triangle class 1 2 3 4 5 6 public class Triangle { public SKPoint A {get;set;} public SKPoint B {get;set;} public SKPoint C {get;set;} } Triangle Point Helper 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 List<Triangle> GetTrianglePoints(int count=10 ,float factor =0.25f,int baseLength=600) { float length= baseLength; var a = new SKPoint((float)Math.Cos(Math.PI/3)*length,0); var b = new SKPoint(0,(float)Math.Sin(Math.PI/3)*length); var c = new SKPoint(length,(float)Math.Sin(Math.PI/3)*length); if(factor>1 || factor<0) factor=0.5f; float m= count*factor; float n= count-m; var ls = new List<Triangle>(); ls.Add(new Triangle() { A=a,B=b,C=c }); for(var i=0; i<count;i++) { var aa = new SKPoint((m*a.X + n*b.X)/count , (m*a.Y + n*b.Y)/count ); var bb = new SKPoint((m*b.X + n*c.X)/count , (m*b.Y + n*c.Y)/count ); var cc = new SKPoint((m*c.X + n*a.X)/count , (m*c.Y + n*a.Y)/count ); var temp = new Triangle() { A = aa, B = bb, C = cc }; ls.Add(temp); a=aa; b=bb; c=cc; } return ls; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 // Create an image and fill it blue int width = 1200; int height = 700; int step =50; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); Random rand = new(); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true , StrokeWidth = 2, ColorF = SKColor.Parse("#003366") }; foreach(var item in GetTrianglePoints(10,.2f,700)) { //paint.ColorF = listOfColor[rand.Next(0,listOfColor.Count)]; canvas.DrawLine(item.A,item.B,paint); canvas.DrawLine(item.B,item.C,paint); canvas.DrawLine(item.C,item.A,paint); } SKFileWStream fs = new("triangleillusion.jpg"); bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 50); bmp.Display();

June 23, 2024 · 2 min · 283 words · PrashantUnity
Generate Thumbnail

Basic shapes

Setup 1 2 #r "nuget:SkiaSharp" using SkiaSharp; Circle 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 int width = 1200; int height = 250; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); Random rand = new(0); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true , StrokeWidth = 4, ColorF = SKColor.Parse("#003366"), Style = SKPaintStyle.Stroke }; canvas.DrawCircle(110,110,100,paint); // hollow Circle paint.Style = SKPaintStyle.StrokeAndFill; canvas.DrawCircle(410,110,100,paint); // Follow Circle bmp.Display(); Line 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 int width = 1200; int height = 20; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); Random rand = new(0); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true , StrokeWidth = 4, ColorF = SKColor.Parse("#003366") }; SKPoint pointOne = new (0,10); SKPoint pointTwo = new (width,10); canvas.DrawLine(pointOne,pointTwo,paint); bmp.Display(); ...

June 22, 2024 · 3 min · 600 words · PrashantUnity
Generate Thumbnail

Multishape patterns

Setup 1 2 #r "nuget:SkiaSharp" using SkiaSharp; Color Sets 1 2 3 4 5 6 7 8 9 10 11 12 var listOfColor = new List<SKColor> { SKColor.Parse("#86B6F6"), SKColor.Parse("#176B87"), SKColor.Parse("#00A9FF"), SKColor.Parse("#FF90BC"), SKColor.Parse("#8ACDD7"), SKColor.Parse("#F2AFEF"), SKColor.Parse("#C499F3"), SKColor.Parse("#33186B"), }; Generate point on circumference of circle of different radius 1 2 3 4 5 6 7 8 9 List<SKPoint> CirclePoints(int n,float radius=3,float x=0, float y=0 ) { float degree = (float)(2*Math.PI/n); return Enumerable .Range(1,n) .Select(i=>degree*i) .Select(i=>(new SKPoint(x+ radius *(float)Math.Cos(i), y+ radius *(float)Math.Sin(i)))) .ToList(); } Section formulae Classic Geometric Formula To Calculate division point on line 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 List<(SKPoint,SKPoint)> SectionFormulae(int times, List<SKPoint> points , float factor =0.25f) { var ls = new List<(SKPoint,SKPoint)>(); float m= times*factor; float n= times-m; for(var i=0; i<times;i++) { var templs = new List<SKPoint>(); for(var j=0;j<points.Count;j++) { if(j==points.Count-1) { var x = (m*points[j].X + n*points[0].X)/times; var y = (m*points[j].Y + n*points[0].Y)/times; templs.Add(new SKPoint(x,y)); } else { var x = (m*points[j].X + n*points[j+1].X)/times; var y = (m*points[j].Y + n*points[j+1].Y)/times; templs.Add(new SKPoint(x,y)); } } points = templs; for(var j=0;j<points.Count;j++) { if(j==points.Count-1) { ls.Add((points[j],points[0])); } else { ls.Add((points[j],points[j+1])); } } } return ls; } Granullar Function for more Control Over Shapes 1 2 3 4 public List<(SKPoint,SKPoint)> GetShape(int n=3, int times=6 ,float factor =0.25f,int baseLength=600,int centerX =0,int centerY=0) { return SectionFormulae(times,CirclePoints(n,baseLength,x:centerX,y:centerY),factor); } Skiasharp Codde to Use All above Function and Generate Shapes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 // Create an image and fill it blue int width = 2000; int height = 2000; int step =50; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); Random rand = new(); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true , StrokeWidth = 2, ColorF = SKColor.Parse("#003366") }; int seperation=4; for(var i=3;i<=15;i+=3) { paint.Color=listOfColor[rand.Next(0,listOfColor.Count)]; foreach(var item in GetShape(n:i,times:25, factor:0.08f, baseLength:seperation* i*i,centerX:width/2,centerY:height/2)) { canvas.DrawLine(item.Item1,item.Item2,paint); } } // Save the image to disk SKFileWStream fs = new("multishape.jpg"); bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 100); bmp.Display();

June 21, 2024 · 2 min · 375 words · PrashantUnity
Generate Thumbnail

Mosaic in SkiaSharp

Setup 1 2 #r "nuget:SkiaSharp" using SkiaSharp; Mosaic Generation Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 // Create an image and fill it blue int width = 1920; int height = 700; int step =50; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); Random rand = new(); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true , StrokeWidth = 2, ColorF = SKColor.Parse("#003366") }; for(var i=0; i<height;i+=step) { for(var j=0; j<width;j+=step) { if(rand.Next(0,100)>50) paint.ColorF =SKColor.Parse("#003366"); else paint.Color =SKColor.Parse("#000f"); canvas.DrawRect(i,j,step,step,paint); } } SKFileWStream fs = new("mosaic.jpg"); bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 50); bmp.Display();

June 20, 2024 · 1 min · 121 words · PrashantUnity