I'm looking at creating a small program in C# that takes in an image, crops it and spits out the cropped image as a new image.
I'm just getting started with the program and I'm having some errors regarding System.Drawing and the Bitmap data type.
I've declared a Bitmap object in main() and receive this error:
So next thing I try is declaring using System.Drawing.Common;. Doing so gives me this error:
I am serious stumped with what to do as I can't seem to find anything online. Any help would be amazing!
If it helps, I'm using Visual Studio Code to write my code and my OS is MacOS Catalina. I've also attached the full code file. Its not much but that's all I've got.
Thanks in advance!
using System;
using System.Drawing;
using System.Drawing.Common;
namespace consoleproject
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Bitmap bitmap = new Bitmap();
}
}
}
It seems you are missing the System.Drawing.Common package. It is not added by default in .Net core projects. To add it:
dotnet add package System.Drawing.Common
Related
I've installed Splashkit SDK and .Net Core SDK following the instructions below.
https://splashkit.io/articles/installation/mac/step-2/
Im using C#.net framework by following the above instructions from the website.
Below is the code
using System;
using SplashKitSDK;
namespace test
{
public class Program
{
public static void Main()
{
Console.WriteLine("Hello, World!");
Window w = new Window("My First Program", 200, 100);
w.DrawText("Hello, World", Color.Black, 10, 45);
w.Refresh(60);
SplashKit.Delay(5000);
}
}
}
When I run the above code the Hello World prints to the console but the window object is not working. Screeshot attached with error code.
I tried adding as much information as I could, If theres anything i've missed please let me know.
I tried copying the shared library which is native to the usr/local/library but that did not work, I also tried what the error message has said, I'm not very expereinced so I might be doing it worng, I'm not sure.
I'm expecting a window to open with the hello world.
I am currently working on a small program, that loads an image file into the Console and print it out as an asci image. I am using the ".Net Console application framework 4". My Problem is, that I do not know how to create a Bitmap. After browsing for a while, I found many answers to my question, that suggested the "System.Drawing.Bitmap" class. When I try to refer to this class, visual studio does not even know System.Drawing.Bitmap. I have a class "AsciArt" which should convert the picture in the method ConvertToAsci. Does anybody know what my mistake is?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing.Bitmap;
namespace consoleGrafix
{
class AsciArt
{
private string ImgLink;
public AsciArt(string imageLocation)
{
this.ImgLink = imageLocation;
}
public void ConvertToAsci(string saveLocation)
{
var bm = Bitmap(saveLocation);
}
}
}
The solution was to set up my class by inheriting from image class. Also, in the ConvertTo Asci method, there was a "new". https://learn.microsoft.com/en-us/dotnet/api/system.drawing.bitmap?view=netframework-4.0 . This really helped. Thank you!
I'm following the next example from the Leadtools page
https://www.leadtools.com/help/leadtools/v19/dh/co/leadtools.codecs~leadtools.codecs.codecspngoptions.html
The version is the 19
But I'm getting this error in visual studio, {featured not supported}, I don't know what I'm doing wrong?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Leadtools;
using Leadtools.Codecs;
namespace DicomTest3
{
public class Program
{
public static void Main(string[] args)
{
const string LEAD_VARS = #"C:\Users\Public\Documents\LEADTOOLSImages";
RasterSupport.SetLicense(
#"C:\LEADTOOLS 19\Common\License\LEADTOOLS.LIC",
File.ReadAllText(#"C:\LEADTOOLS 19\Common\License\LEADTOOLS.LIC.KEY")
);
RasterCodecs codecs = new RasterCodecs();
string srcFileName = Path.Combine(LEAD_VARS, "IMAGE1.CMP");
RasterImage image = codecs.Load(srcFileName);
// save with maximum quality
codecs.Options.Png.Save.QualityFactor = 1;
codecs.Save(image, Path.Combine(LEAD_VARS, "quality.png"), RasterImageFormat.Png, image.BitsPerPixel);
// save with maximum compression
codecs.Options.Png.Save.QualityFactor = 9;
codecs.Save(image, Path.Combine(LEAD_VARS, "compression.png"), RasterImageFormat.Png, image.BitsPerPixel);
// Clean up
image.Dispose();
codecs.Dispose();
}
}
}
Error during debugging
The most likely cause for this error is failing to load the assembly (codec DLL) for the PNG file format, which is Leadtools.Codecs.Png.dll.
You can either add it as a reference in the .NET project, or copy it to the same folder that has your EXE and other LEADTOOLS assemblies such as Leadtools.Codecs.dll
Our demos avoid such problems because they're all built in the BIN sub-folder for the project's platform. For example, if you build a 32-bit .NET 4 demo, its EXE will be placed in this folder:
LEADTOOLS 19\Bin\Dotnet4\Win32
This folder contains all the LEADTOOLS Dotnet4 assemblies for Win32, including the codecs.
The help topic Files to be Included with Your Application details which assemblies are required for different toolkit features.
If this does not solve the problem for you, please provide more details here or open a support case by emailing LEADTOOLS support.
I have already referenced NAudio library in my project how ever when i run my code it tells me something along the lines of "Expression denotes a type, where a method group was expected.
Here is my code and the error is at the line of waveFile = WaveFileReader("somefile.wav");
using System;
using Gst;
using GLib;
using Gst.BasePlugins;
using NAudio;
using NAudio.Wave;
namespace record_audio_simple_test
{
class MainClass
{
//Define class variables
private NAudio.Wave.WaveFileReader waveFile = null;
private NAudio.Wave.DirectSoundOut output = null;
public static void Main (string[] args)
{
waveFile = WaveFileReader("somefile.wav");
}
}
}
I am using MonoDevelop, Ubuntu Linux, and NAudio, my target hardware is an embedded linux box but first I need to make it work before I try to port it to the embedded box I'm using NAudio becuase I assume that it will be cross-compatible as long as their are supported codecs installed on the target system(Like Gstreamer or w/e).
Taking a look at your code are you sure its not soposed to look like this?:
WaveFileReader waveFile = new WaveFileReader("somefile.wav");
Correct me if I am wrong. Hope I helped if i'm not wrong.
I want to write a simple hello world add in for Media Center on Windows 7, but I am having problems finding up to date functional documentation. I found this page: http://blogs.msdn.com/b/mcreasy/archive/2004/10/12/241449.aspx which looks to be exactly what I need. I implemented it and some of the interfaces it references are marked as obsolete, and even so when I try to launch it in media center is just pops up a dialog saying "unable to launch addin"
I updated the namespace interfaces from using Microsoft.MediaCenter.AddIn to using Microsoft.MediaCenter.Hosting which looks to be the up to date namespace according to the sdk docs, but I still have the same problem.
registering the assembly with the gac and with RegisterMCEApp both are successful, and I have unregistered and registered from both places in between builds.
I strongly signed the assembly with a .snk file and got the public key token to update the registration.xml
Can anyone either tell me what I am doing wrong or direct me to some up to date tutorial /docs?
Here is the little bit of code I have:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.MediaCenter.Hosting;
namespace MCPluginTakeTwo
{
public class HelloWorldAddIn: MarshalByRefObject, IAddInModule, IAddInEntryPoint
{
public void Initialize(Dictionary<string, object> appInfo, Dictionary<string, object> entryPointInfo)
{
}
public void Uninitialize()
{
}
public void Launch(AddInHost host)
{
}
}
}
Maybe looking at some open source mc plugins would help.
Here's another getting started tutorial, with some tips for getting started with Visual Studio 2010 (because the SDK only comes with VS 2008 templates).
http://david.gardiner.net.au/2010/10/writing-media-center-application-in.html