Как правильно сохранить изображение в корень проекта? - C#
Формулировка задачи:
подскажите пожалуйста как грамматически правильно будет прописать картинке путь в папку с проектом по умолчанию?
код :
и
организовать в корне проекта?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using AForge.Imaging.Filters;
using System.IO;
namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
string inputImagePath = @"D:\3\xxx.jpg";
string dirPath = Path.GetDirectoryName(inputImagePath);
string fileName = Path.GetFileNameWithoutExtension(inputImagePath);
string fileExt = Path.GetExtension(inputImagePath);
int origHeight = 0;
int origWidth = 0;
//*******************************************************
//Edge Detection - only works on grayscale images
//*******************************************************
//load the image from disk as a Bitmap
var bitmap = new Bitmap(inputImagePath);
origHeight = bitmap.Height;
origWidth = bitmap.Width;
//create grayscale filter (BT709)
Grayscale gfilter = new Grayscale(0.2125, 0.7154, 0.0721);
//apply the filter, so we can use the edge detectors
Bitmap grayImage = gfilter.Apply(bitmap);
// create canny filter
CannyEdgeDetector cannyFilter = new CannyEdgeDetector();
// You can use ApplyInPlace() to modify the input image or use
//Apply() to make a new copy of the image with the filter applied...
//cannyFilter.ApplyInPlace(grayImage);
Bitmap cannyImage = cannyFilter.Apply(grayImage);
//Save each of the four edge detection images we created.
cannyImage.Save(dirPath + "" + fileName + "_canny" + fileExt);
}
}
}
а если быть точнее как
//load the image from disk as a Bitmap
//Save ...
Решение задачи: «Как правильно сохранить изображение в корень проекта?»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using AForge.Imaging.Filters;
using System.IO;
namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
string pathToImage = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "77.jpg");
string dirPath = Path.GetDirectoryName(pathToImage);
string fileName = Path.GetFileNameWithoutExtension(pathToImage);
string fileExt = Path.GetExtension(pathToImage);
int origHeight = 0;
int origWidth = 0;
//*******************************************************
//Edge Detection - only works on grayscale images
//*******************************************************
//load the image from disk as a Bitmap
var bitmap = new Bitmap(pathToImage);
origHeight = bitmap.Height;
origWidth = bitmap.Width;
//create grayscale filter (BT709)
Grayscale gfilter = new Grayscale(0.2125, 0.7154, 0.0721);
//apply the filter, so we can use the edge detectors
Bitmap grayImage = gfilter.Apply(bitmap);
// create canny filter
CannyEdgeDetector cannyFilter = new CannyEdgeDetector();
// You can use ApplyInPlace() to modify the input image or use
//Apply() to make a new copy of the image with the filter applied...
//cannyFilter.ApplyInPlace(grayImage);
Bitmap cannyImage = cannyFilter.Apply(grayImage);
//Save each of the four edge detection images we created.
cannyImage.Save(dirPath + "" + fileName + "_canny" + fileExt);
}
}
}