I have been working on my AI for a while now, but i can't seem to get my AI to display a random GIF image into my Picture Box from this location.
C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\
Example of what's needed.
string[] imagePaths1 = Directory.GetFiles(#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\images", "*.gif", SearchOption.AllDirectories);
But instead of Audio files I need GIF images.
This is a sample of the code I have been using.
case "test":
int image1;
Random randim = new Random();
image1 = randim.Next(0, 4);
switch (image1)
{
case 0:
pictureBox2.Image = Image.FromFile(#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\giphy.gif");
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
break;
case 1:
pictureBox2.Image = Image.FromFile(#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\Party!.gif");
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
break;
case 2:
pictureBox2.Image = Image.FromFile(#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\Staredown.gif");
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
break;
case 3:
pictureBox2.Image = Image.FromFile(#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\tenor.gif");
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
break;
case 4:
pictureBox2.Image = Image.FromFile(#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\idgaf-obama.gif");
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
break;
case 5:
pictureBox2.Image = Image.FromFile(#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\homealone.gif");
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
break;
case 6:
pictureBox2.Image = Image.FromFile(#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\giphy.gif");
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
break;
case 7:
pictureBox2.Image = Image.FromFile(#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\fastsoccer.gif");
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
break;
case 8:
pictureBox2.Image = Image.FromFile(#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\wallstreet.gif");
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
break;
case 9:
pictureBox2.Image = Image.FromFile(#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\DYjbX.gif");
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
break;
}
This code may get you started:
var random = new Random();
var folder = #"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\images";
var fileNames = Directory.EnumerateFiles(folder, "*.gif", SearchOption.AllDirectories)
.Select((file, index) => new {file, index})
.ToDictionary(z => z.index, y => y.file);
var randomPic = fileNames[random.Next(0, fileNames.Count)];
pictureBox2.Image = MediaTypeNames.Image.FromFile(Path.Combine(folder, randomPic));
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
The main thing is getting the filenames into a data structure. I use a Dictionary - you could just as easily use a List using:
var random = new Random();
var folder = #"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\images";
var fileNames = Directory.EnumerateFiles(folder, "*.gif", SearchOption.AllDirectories).ToList();
var randomPic = fileNames[random.Next(0, fileNames.Count)];
pictureBox2.Image = MediaTypeNames.Image.FromFile(Path.Combine(folder, randomPic));
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
Then randomly choose a filename and populate pictureBox2 with that filename.
You should also strongly consider moving random to be a static field.
you can use the following :-
var basePath =
#"C:\Users\scatt\Desktop\Marvel-J.A.R.V.I.S-Personal-Assistant-Winform-C--master\Marvel J.A.R.V.I.S Personal Assistant\Resources\AIPICS\";
var pics = System.IO.Directory.EnumerateFiles(basePath, "*.gif").ToArray();
var randomPic = pics.OrderBy(p => Guid.NewGuid()).First();
pictureBox2.Image = MediaTypeNames.Image.FromFile(randomPic);
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.CancelAsync();
Related
I'm working on a speech recognizer but every time I say a word it puts it in a loop and keeps saying:
hi my name is Jarvis how can I help you?
What should I do?
I've also tried RecognizeAsyncCancel() but it didn't work!
My code is below:
using System;
using System.IO;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Windows.Forms;
namespace Jarvis
{
public partial class Form1 : Form
{
SpeechRecognitionEngine RecEngine = new SpeechRecognitionEngine();
SpeechSynthesizer speech = new SpeechSynthesizer();
public Form1()
{
InitializeComponent();
Choices choices = new Choices();
string[] text = File.ReadAllLines(Environment.CurrentDirectory + "//grammer.txt");
choices.Add(text);
Grammar grammar = new Grammar(new GrammarBuilder(choices));
RecEngine.LoadGrammar(grammar);
RecEngine.SetInputToDefaultAudioDevice();
RecEngine.RecognizeAsync(RecognizeMode.Multiple);
RecEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(RecEngine_SpeechRecognized);
speech.SelectVoiceByHints(VoiceGender.Male);
}
private void RecEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
string result = e.Result.Text;
if (result == "Hello")
{
result = "";
result = "Hi, my name is Jarvis, how can I help you";
}
if (result == "Hi")
{
result = "";
result = "It is currently " + DateTime.Now.ToLongTimeString();
}
speech.SpeakAsync(result);
lblresult.Text = result;
result = "";
MessageBox.Show("a");
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
For starters, the setup you are using, is creating your problems, due mostly from arrangement of your code. You should also be incorporating a switch case statement in your recEngine Sub. Also, you are using SpeechSynthesizer speech in your declaration and your SpeechSynthesizer should compliment that and be: speech.Speak("Hi, my name is Jarvis, how can I help you") NOT result = "Hi, my name is Jarvis, how can I help you";.
You don't need this either: result = ""; You can still use If Statements within Case Statements if you want. With that said, here is an example from one of my old projects. I am leaving you with a link to the full project of the code. It will get you on the right path: Just scroll down to the Form1.cs at my repository.
https://github.com/DeadReport77/Scarlett-Speech-Recognition-Final-Production/commit/20f4db5d3b75b03d601d39c6fe54e8261c7976f0
I am the creator of Scarlett Witch Speech Recognition surfacing the net on YouTube and other places. This is the YouTube link: https://www.youtube.com/watch?v=39S10FoCbIA
The code will solve all your problems as well (switch case example):
private void RecEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.Text)
{
case "scarlett mute volume":
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_VOLUME_MUTE);
break;
case "scarlett volume up":
int repeat = 10;
for (int i = 0; i < repeat; i++)
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_VOLUME_UP);
break;
case "scarlett volume down":
for (int iter = 0; iter < 10; iter++)
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_VOLUME_DOWN);
break;
case "show commands":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\list.wav").Play();
Process.Start(#"C:\\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\Commands.txt");
break;
case "tell me who you are":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\info.wav").Play();
break;
case "scarlett open youtube":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\youtube.wav").Play();
Process.Start("chrome", "Http://www.youtube.com");
break;
case "scarlett movies":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\movie.wav").Play();
Process.Start("chrome", "http://www.tubitv.com");
break;
case "scarlett open github":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\github.wav").Play();
Process.Start("chrome", "Http://www.github.com");
break;
case "open wiki":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\wiki.wav").Play();
Process.Start("http://www.wikipedia.org/");
break;
case "scarlett microsoft office":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\word.wav").Play();
Process.Start("winword");
break;
case "stop listening":
recEngine.RecognizeAsyncStop();
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\mic.wav").Play();
break;
case "open command":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\prompt.wav").Play();
System.Diagnostics.Process.Start("cmd");
break;
case "scarlett run system scan":
Scanning f = new Scanning();
f.Show();
break;
case "commit to memory":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\storing.wav").Play();
break;
case "scarlett close":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\shuttingdown.wav").Play();
Sleep(TimeSpan.FromSeconds(2));
Application.Exit();
break;
case "scarlett what day is it":
Scarlett.Speak(DateTime.Today.ToString("dd-MM-yyyy"));
break;
case "scarlett out of the way":
if (WindowState == FormWindowState.Normal)
{
WindowState = FormWindowState.Minimized;
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\standby.wav").Play();
}
break;
case "scarlett come back":
if (WindowState == FormWindowState.Minimized)
{
WindowState = FormWindowState.Normal;
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\comeback.wav").Play();
}
break;
case "disparta":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\closingapp.wav").Play();
SendKeys.Send("%{F4}");
break;
case "scarlett play rammstein":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\video.wav").Play();
Process.Start("chrome", "https://www.youtube.com/watch?v=3b4szXcRFcs?autoplay=1&mute=1");
break;
case "page up":
SendKeys.Send("{PGUP}");
break;
case "page down":
SendKeys.Send("{PGDN}");
break;
case "new tab":
SendKeys.Send("^{t}");
break;
case "switch tab":
SendKeys.Send("^{TAB}");
break;
case "magnify":
SendKeys.Send("^{+}");
break;
case "less":
SendKeys.Send("^{-}");
break;
case "scarlett notepad":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\notepad.wav").Play();
Process.Start("notepad");
break;
case "scarlett visual studios":
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\visual.wav").Play();
Process.Start("devenv.exe");
break;
default:
new SoundPlayer(#"C:\Users\Leeraoy.Jenkins\source\repos\Scarlett\Resources\unknown.wav").Play();
break;
}
}
Im using the following code to fix the orientation of image taking into account the EXIF Orientation Tag
static void FixImageOrientation(Image srce)
{
const int ExifOrientationId = 0x112;
// Read orientation tag
if (!srce.PropertyIdList.Contains(ExifOrientationId)) return;
var prop = srce.GetPropertyItem(ExifOrientationId);
var orient = BitConverter.ToInt16(prop.Value, 0);
// Force value to 1
prop.Value = BitConverter.GetBytes((short)1);
srce.SetPropertyItem(prop);
// Rotate/flip image according to <orient>
switch (orient)
{
case 1:
srce.RotateFlip(RotateFlipType.RotateNoneFlipNone);
break;
case 2:
srce.RotateFlip(RotateFlipType.RotateNoneFlipX);
break;
case 3:
srce.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case 4:
srce.RotateFlip( RotateFlipType.Rotate180FlipX);
break;
case 5:
srce.RotateFlip(RotateFlipType.Rotate90FlipX);
break;
case 6:
srce.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
case 7:
srce.RotateFlip(RotateFlipType.Rotate270FlipX);
break;
case 8:
srce.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
default:
srce.RotateFlip(RotateFlipType.RotateNoneFlipNone);
break;
}
}
This code removes the EXIF Orientation Tag properly.
And saving the image works is i simply use img.save
But the app provides user the ability to select the format of the image.For that i use the following code
private void saveJpeg(string path, Bitmap img, long quality)
{
EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
ImageCodecInfo Codec = this.getEncoderInfo(imgformat);
if (Codec == null)
return;
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;
img.Save(path + ext, Codec, encoderParams);
}
public string getimgext(string ccodec)
{
if (ccodec.Equals("image/png"))
{
return ".png";
}
else if (ccodec.Equals("image/jpeg"))
{
return ".jpg";
}
else if (ccodec.Equals("image/tiff"))
{
return ".tif";
}
else if (ccodec.Equals("image/bmp"))
{
return ".bmp";
}
else if (ccodec.Equals("image/gif"))
{
return ".gif";
}
else
{
return null;
}
}
private ImageCodecInfo getEncoderInfo(string mimeType)
{
// Get image codecs for all image formats
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
// Find the correct image codec
for (int i = 0; i < codecs.Length; i++)
if (codecs[i].MimeType == mimeType)
return codecs[i];
return null;
}
When i save the image with SaveJpeg the image gets saved with wrong orientation.What im i doing wrong? Please help.
UPDATE:
I have modified the method so that i dont need to create a new instance of the bitmap as the loop processes many files.But this does not work unless i create a new instance of the bitmap.This process consumes an additional of 10+ seconds of the processing time when compared to the old version.
Im using the code like this
image = (Bitmap)FixImageOrientation(Bitmap.FromFile(path));
Image FixImageOrientation(Image srce)
{
const int ExifOrientationId = 0x112;
// Read orientation tag
if (!srce.PropertyIdList.Contains(ExifOrientationId)) return srce;
var prop = srce.GetPropertyItem(ExifOrientationId);
var orient = BitConverter.ToInt16(prop.Value, 0);
// Force value to 1
prop.Value = BitConverter.GetBytes((short)1);
srce.SetPropertyItem(prop);
// Rotate/flip image according to <orient>
switch (orient)
{
case 1:
srce.RotateFlip(RotateFlipType.RotateNoneFlipNone);
return srce;
case 2:
srce.RotateFlip(RotateFlipType.RotateNoneFlipX);
return srce;
case 3:
srce.RotateFlip(RotateFlipType.Rotate180FlipNone);
return srce;
case 4:
srce.RotateFlip(RotateFlipType.Rotate180FlipX);
return srce;
case 5:
srce.RotateFlip(RotateFlipType.Rotate90FlipX);
return srce;
case 6:
srce.RotateFlip(RotateFlipType.Rotate90FlipNone);
return srce;
case 7:
srce.RotateFlip(RotateFlipType.Rotate270FlipX);
return srce;
case 8:
srce.RotateFlip(RotateFlipType.Rotate270FlipNone);
return srce;
default:
srce.RotateFlip(RotateFlipType.RotateNoneFlipNone);
return srce;
}
}
In one method you have argument of type Image but in other Bitmap. So I'm guessing that you convert source JPEG image to Bitmap before call FixImageOrientation.
This will work:
var jpeg = Image.FromFile("original.jpg");
FixImageOrientation(jpeg);
var bitmap = new Bitmap(jpeg);
saveJpeg("new",bitmap,1);
This won't:
var jpeg = Image.FromFile("original.jpg");
var bitmap = new Bitmap(jpeg);
FixImageOrientation(bitmap);
saveJpeg("new", bitmap, 1);
I have made a loading screen (splash screen) just like the old C64.
I have used a series of picture boxes and just change the coloured image using a timer and a case statement.
switch (a)
{
case 1:
pictureBox1.Image = Properties.Resources.image1;
pictureBox8.Image = Properties.Resources.image1;
pictureBox10.Image = Properties.Resources.image1;
pictureBox2.Image = Properties.Resources.image1;
pictureBox11.Image = Properties.Resources.image1;
pictureBox9.Image = Properties.Resources.image1;
break;
case 2:
pictureBox1.Image = Properties.Resources.image2;
pictureBox8.Image = Properties.Resources.image2;
pictureBox10.Image = Properties.Resources.image2;
break;
case 3:
pictureBox1.Image = Properties.Resources.image3;
pictureBox8.Image = Properties.Resources.image3;
pictureBox10.Image = Properties.Resources.image3;
break;
case 4:
pictureBox1.Image = Properties.Resources.image4;
pictureBox8.Image = Properties.Resources.image4;
break;
case 5:
pictureBox1.Image = Properties.Resources.image5;
pictureBox8.Image = Properties.Resources.image5;
break;
case 6:
pictureBox1.Image = Properties.Resources.image6;
pictureBox8.Image = Properties.Resources.image6;
break;
case 7:
pictureBox1.Image = Properties.Resources.image7;
pictureBox8.Image = Properties.Resources.image7;
break;
case 8:
pictureBox1.Image = Properties.Resources.image8;
pictureBox8.Image = Properties.Resources.image8;
break;
}
its a bit nasty looking, how could I improve my code?
You could have a look at the Iterator design pattern. You could create a class that represents a single stage, that class would have properties for each of the picture boxes and you would set the value of those properties to the relevant item in your resources file.
You then create instances of that object for each loading stage, put them in a collection and write an iterator to loop that collection.
There are a two things I'd improve:
Store your images in an array, so you don't have to repeat case X/imageX every time.
Handle the common stuff first, then concentrate on the special cases.
You can declare the array in your form as a "fake" constant, since it won't change:
private readonly static Image[] myImages = new[] {
Properties.Resources.image1,
Properties.Resources.image2,
Properties.Resources.image3,
Properties.Resources.image4,
Properties.Resources.image5,
Properties.Resources.image6,
Properties.Resources.image7,
Properties.Resources.image8
}
and then use the following code in your Timer hander:
Image image = myImages[a-1];
pictureBox1.Image = image;
pictureBox8.Image = image;
// special cases
if (a == 1)
{
pictureBox2.Image = image;
pictureBox11.Image = image;
pictureBox9.Image = image;
}
if (a >= 1 && a <= 3)
{
pictureBox10.Image = image;
}
I am new to c# and I'm wanting to create a game that it has three button with different colors , I want to turn on and off each of them in random state for 1000 milisecond .. what should I do ? can anyone help me ? :)
there are three buttons including Red , Blue and Green colors , after click the "start" button they begin to blink randomly ... I want set 1000 millisecond for this blink !
switch (colorNum)
{
case 1:
btnRed.BackColor = Color.Red;
Thread.Sleep(milisecond);
//if (btn == btnRed)
//{
count++;
break;
//}
case 2:
btnBlue.BackColor = Color.Blue;
//{
count++;
break;
//}
case 3:
btnYellow.BackColor = Color.Yellow;
//{
count++;
break;
//}
}
private void Blink_Button()
{
Random rnd = new Random();
int colorNum = rnd.Next(1, 4);
switch (colorNum)
{
case 1:
btnRed.BackColor = Color.Red;
btnBlue.BackColor = Color.LightGray;
btnYellow.BackColor = Color.LightGray;
break;
case 2:
btnBlue.BackColor = Color.Blue;
btnRed.BackColor = Color.LightGray;
btnYellow.BackColor = Color.LightGray;
break;
case 3:
btnYellow.BackColor = Color.Yellow;
btnRed.BackColor = Color.LightGray;
btnBlue.BackColor = Color.LightGray;
break;
}
}
Call this method in the Timer tick event
Im trying to make an app that can scan documents using C# and WIA. But I have come across a problem when setting up the page size property. When I run the scanning process my app throws an error:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in DigiKnjiga.exe
Additional information: Exception from HRESULT: 0x80210067
I have tried this using these properties: PageSize(3097), PageWidth(3098) & PageHeight(3099), HorizontalExtent(6151) & VerticalExtent(6152). But setting any of these values throws the before mentioned exception.
Here is the event that starts the scanning process:
private void scanNew_Click(object sender, EventArgs e)
{
if (Scanner.ChosenDevice > 0)
{
Device = deviceManager.DeviceInfos[Scanner.ChosenDevice].Connect();
switch (Scanner.ColorCode)
{
case 0://color
Device.Items[1].Properties["6146"].set_Value(1);
break;
case 1://grayscale
Device.Items[1].Properties["6146"].set_Value(2);
break;
case 2://black and white
Device.Items[1].Properties["6146"].set_Value(4);
break;
}
//(DPI)
Device.Items[1].Properties["6147"].set_Value(Scanner.DPI);
Device.Items[1].Properties["6148"].set_Value(Scanner.DPI);
//brightness
Device.Items[1].Properties["Brightness"].set_Value(Scanner.Brightness);
//contrast
Device.Items[1].Properties["Contrast"].set_Value(Scanner.Contrast);
switch (Scanner.Format)
{
case 0://A3
Device.Items[1].Properties["3097"].set_Value(10);
//Device.Items[1].Properties["6151"].set_Value(11692);
//Device.Items[1].Properties["6152"].set_Value(16535);
break;
case 1://A4
Device.Items[1].Properties["3097"].set_Value(0);
//Device.Items[1].Properties["6156"].set_Value(1);
//Device.Items[1].Properties["3098"].set_Value(8267);
//Device.Items[1].Properties["3099"].set_Value(11692);
////Device.Items[1].Properties["6151"].set_Value(1165 * 2);
////Device.Items[1].Properties["6152"].set_Value(1653 * 2);
////Device.Items[1].Properties["3097"].set_Value("0");
break;
case 2://A5
Device.Items[1].Properties["3097"].set_Value(11);
//Device.Items[1].Properties["6151"].set_Value(1165);
//Device.Items[1].Properties["6152"].set_Value(1653);
break;
}
switch (Scanner.FileType)
{
case 0://JPEG
image = (WIA.ImageFile)Device.Items[1].Transfer(WIA.FormatID.wiaFormatJPEG);
break;
case 1://PNG
image = (WIA.ImageFile)Device.Items[1].Transfer(WIA.FormatID.wiaFormatPNG);
break;
case 2://BMP
image = (WIA.ImageFile)Device.Items[1].Transfer(WIA.FormatID.wiaFormatBMP);
break;
case 3://TIFF
image = (WIA.ImageFile)Device.Items[1].Transfer(WIA.FormatID.wiaFormatTIFF);
break;
}
byte[] imageBytes = (byte[])image.FileData.get_BinaryData();
MemoryStream ms = new MemoryStream(imageBytes);
Image image2 = Image.FromStream(ms);
Bitmap smaller= new Bitmap(image2 , new Size(prikazZbirke.Width, prikazZbirke.Height));
prikazStrani.Size = new System.Drawing.Size(image2 .Width, image2 .Height);
prikazStrani.Location = new Point(0, 0);
prikazStrani.Image = image2 ;
image2 .Save("test.jpg");
}
}
I wonder if anyone knows the solution to the this problem and I thank you in advance for your answers. And at the same time apologise for any spelling mistakes as I am not english.
cahnge switch case as following, it could work(but be sure this property(3097) is supported in your scaner)
switch (Scanner.Format)
{
case 0://A3
Device.Properties["3097"].set_Value(10);
break;
case 1://A4
Device.Properties["3097"].set_Value(0);
break;
case 2://A5
Device.Properties["3097"].set_Value(11);
break;
}