hallmat 0 Newbie Poster

as i cant edit my other post i have changed the code to this;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
     
             private void button1_Click(object sender, EventArgs e)
        {
            CompareImages(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "ffff"), 127.0, new string[] {"*.jpg", "*.png"});
        }

        //extension should be complete search strings like "*.png"
        //you might want to implement this in a second thread and display some progress
        //this will compare the images overall avg brightness and move the image, if the overall brightness
        //is smaller than the threshold
        private void CompareImages(string sourceFolder, string disposedImgFolder, double threshold, string[] extensions)
        {
            if (Directory.Exists(sourceFolder))
            {
                DirectoryInfo dir = new DirectoryInfo(sourceFolder);
                List<FileInfo> pictures = new List<FileInfo>();

                foreach (string ext in extensions)
                {
                    FileInfo[] fi = dir.GetFiles(ext);
                    pictures.AddRange(fi);
                }

                //throws no error if already exists
                Directory.CreateDirectory(disposedImgFolder);

                int j = 0;

                if (pictures.Count > 0)
                {
                    for (int i = 0; i < pictures.Count; i++)
                    {
                        Image img = null;
                        Bitmap bmp = null;

                        try
                        {
                            //load the image and make a copy, so that the file could be moved
                            img = Image.FromFile(pictures[i].FullName);
                            bmp = new Bitmap(img);
                            img.Dispose();

                            double avg = GetAveragePixelValue(bmp);

                            bmp.Dispose();

                            //compare
                            if (avg < threshold)
                            {
                                string dest = Path.Combine(disposedImgFolder, pictures[i].Name);

                                if (File.Exists(dest) == false)
                                {
                                    pictures[i].MoveTo(dest);
                                    j++;
                                }
                                else
                                {
                                    //do whatever you want to do, if the file already exists
                                }
                            }
                            else
                            {
                                //do whatever
                            }
                        }
                        catch
                        { …
hallmat 0 Newbie Poster

well here is the code i have at the moment

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
using System.Threading.Tasks;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e);
        private void CompareImages(string sourceFolder, string disposedImgFolder, double threshold, string[] extensions)
        {
            if (Directory.Exists(sourceFolder))
            {
                DirectoryInfo dir = new DirectoryInfo(sourceFolder);
                List<FileInfo> pictures = new List<FileInfo>();

                foreach (string ext in extensions)
                {
                    FileInfo[] fi = dir.GetFiles(ext);
                    pictures.AddRange(fi);
                }

               
                Directory.CreateDirectory(disposedImgFolder);

                int j = 0;

                if (pictures.Count > 0)
                {
                    int count = pictures.Count;
                    
                    Parallel.For(0, count, i =>
                    {
                        Image img = null;
                        Bitmap bmp = null;

                        try
                        {
                            
                            img = Image.FromFile(pictures[i].FullName);
                            bmp = new Bitmap(img);
                            img.Dispose();

                            double avg = GetAveragePixelValue(bmp);

                            bmp.Dispose();

                            if (avg < threshold)
                            {
                                string dest = Path.Combine(disposedImgFolder, pictures[i].Name);

                                if (File.Exists(dest) == false)
                                {
                                    pictures[i].MoveTo(dest);
                                    j++;
                                }
                                else
                                {
                                    
                                }
                            }
                            else
                            {

                            }
                        }
                        catch
                        {
                            if (img != null)
                                img.Dispose();
                            if (bmp != null)
                                bmp.Dispose();
                        }
                    });

                    MessageBox.Show("Done, " + j.ToString() + " files moved.");
                }
            }
        }

        private double GetAveragePixelValue(Bitmap bmp)
        {
            throw new NotImplementedException();
        }
    }
}

how do i define what the threashold is?

also i get an error

Error 1 'WindowsFormsApplication1.Form1.button1_Click(object, System.EventArgs)' must declare a body because it is not marked abstract, extern, or partial C:\Users\windows -7\AppData\Local\Temporary Projects\WindowsFormsApplication1\Form1.cs 23 22 WindowsFormsApplication1

any idea why?

hallmat 0 Newbie Poster

Hello,

im trying to make a program that opens up jpeg files one at a time and look at there brightness and then if its past a threashold moves the file to a "keep" folder if not moves it to a "varify" folder

im new to C# so im not sure where to start

sorry if this has been asked before

hallmat 0 Newbie Poster

i didnt think i could in C# can i use the same sort of code in c#?

and no its not my app im trying to hook into or i would just change the source of the app and edit my new code into it that would make things too easy

i was told that i couldnt do that in c# hence the delphi.

im new to programming in c# so i dont know too much in c# hence the stupid questions

hallmat 0 Newbie Poster

yeah its a ie browser so if i try to call the Twebbrowser hmm i will try that thanks for your advise as that is what i wanted to block really

here is my delphi code but need a little help

uses ActiveX;

procedure WBFindDialog(AWebBrowser: TWebbrowser) ;
const
  CGID_WebBrowser: TGUID = '{is this my Target?}';
  HTMLID_FIND = 1;

var
  CmdTarget : IOleCommandTarget;
  vaIn, vaOut: OleVariant;
  PtrGUID: PGUID;
begin
  New(PtrGUID) ;
  PtrGUID^ := CGID_WebBrowser;
  if AWebBrowser.Document <> nil then
    try
      AWebBrowser.Document.QueryInterface(IOleCommandTarget, CmdTarget) ;
      if CmdTarget <> nil then
        try
          CmdTarget.Exec(PtrGUID, HTMLID_FIND, 0, vaIn, vaOut) ;
        finally
          CmdTarget._Release;
        end;
    except
    end;
  Dispose(PtrGUID) ;
end;

procedure TForm1.FormCreate(Sender: TObject) ;
begin
  WebBrowser1.Navigate('http://www.web.com) ; 
end;

procedure TForm1.Button1Click(Sender: TObject) ;
begin
  WBFindDialog(WebBrowser1) ;
end;
hallmat 0 Newbie Poster

All i know is the Application was developed with Delphi

so if i can find the API call im might have a chance ?

thanks for you quick reply
it must have a API call as it has a browser in the middle of the application

i dont know if it can be done in C# or its a matter for unmanaged code i know a little about delphi if it needs to be done in that

hallmat 0 Newbie Poster

Hello wonderfull people of DaniWeb

i need a little question answered can i manipulate another aplication?

here is what i want to do

Put a message on the screen if a program is detected as running i know how to detect it but i dont know how to send a text to it i have heard of a few way but wasnt sure

i know this is a kinda newbi question

i am only learning it and i havent touched on this yet but want to make something

many thanks
Matthew