Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
My task is to resize multiple images. I tried this code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Boyutlandir
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string dosyaYolu = string.Empty;
Bitmap bmp = null;
OpenFileDialog openFileDialogDosyaAc = new OpenFileDialog();
private void button1_Click(object sender, EventArgs e)
{
openFileDialogDosyaAc.Multiselect = true;
if (openFileDialogDosyaAc.ShowDialog() == DialogResult.OK)
{
dosyaYolu = openFileDialogDosyaAc.FileName;
bmp = new Bitmap(openFileDialogDosyaAc.FileNames.ToString());
pictureBox1.Image = bmp;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
}
private void button2_Click(object sender, EventArgs e)
{
Bitmap bmpKucuk = new Bitmap(pictureBox1.Image,Convert.ToInt32(textBox1.Text),Convert.ToInt32(textBox2.Text));
pictureBox1.Image = bmpKucuk;
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
}
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "jpeg dosyası(*.jpg)|*.jpg|Bitmap(*.bmp)|*.bmp";
DialogResult sonuc = sfd.ShowDialog();
if (sonuc == DialogResult.OK)
{
pictureBox1.Image.Save(sfd.FileName);
}
}
}
}
Ok, so you are using winforms and want to open multiple files? or a directory? and want to resize them. but there is nothing resized? or do I need more coffee? use http://nuget.org/packages/ImageResizer/ and I don't see a loop to loop over the files you want to resize.
Read more about the imageresizer component here: http://imageresizing.net/docs/managed
in your button1 click event, do something like this:
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr = this.openFileDialogDosyaAc.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
// Read the files
foreach (String file in openFileDialogDosyaAc.FileNames)
{
//resize and save
}
}
}
Related
I want to achieve almost something similar here. I want a control that supports both images or video. This will play for some duration.
I am able to show the video using WMP(Windows media player) object. But now I am trying to use DirectX to render the images or video.
Please help me on this. Suggestion are welcomed.
Here is what I tried.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;
using Microsoft.DirectX;
namespace WindowsPlayerDirectX
{
public partial class Form1 : Form
{
private Video video;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//int height = panel1.Height;
//int width = panel1.Width;
try
{
MessageBox.Show("Hi", "Test");
openFileDialog1.Filter = "Image Files(jpg,png,bmp,gif)|*.jpg;*.jpeg;*.png;*.bmp;*.gif|all files|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// video = new Video(openFileDialog1.FileName,false);
pictureBox1.Load(openFileDialog1.FileName);
}
}catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
//video = new Video("D:\\Wildlife.wmv", false);
//video.Owner = panel1;
//video.Stop();
//video.Dispose();
//if (!video.Playing)
// video.Play();
//else
// MessageBox.Show("File already playing D:\\Wildlife.wmv ", "Info");
//OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog1.ShowDialog();
openFileDialog1.Title = "Select video file..";
openFileDialog1.InitialDirectory = Application.StartupPath;
openFileDialog1.DefaultExt = ".avi";
openFileDialog1.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";
video = new Video(openFileDialog1.FileName);
video.Owner = panel1;
panel1.Width = 700;
panel1.Height = 390;
}
}}
I'm not by any means an expert in DirectX applications, but I've made one with OpenGL...
I guess what's missing is some kind of Surface to render the video into.
BTW, it seems that Microsoft DirectX in .Net is deprecated. I guess that you'll be better off using SharpDx.
you forgot to call video.Play();
or you can add autopaly in constructor like this:
video = new Video(openFileDialog1.FileName, true);
i made a screen capturing application.. i applied drawing(simple lines) on it..
when i capture the screen and perform editing and save it..only the capture screen is save not the editing..i want to save all these editing on picture.. i m stuck here..
here is the code..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
bool paint = false;
SolidBrush color;
private MessageBoxButtons buttonType;
public Form1()
{
InitializeComponent();
}
private void picture_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, System.EventArgs e)
{
this.Opacity = 0;
time.Enabled = true;
}
private void button3_Click_1(object sender, System.EventArgs e)
{
SaveFileDialog savefiledialog1 = new SaveFileDialog();
try
{
savefiledialog1.Title = "Save File";
savefiledialog1.FileName = "Capture Screen";
savefiledialog1.Filter = "JPEG |*.jpeg";
if (savefiledialog1.ShowDialog() == DialogResult.OK)
picture.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
Application.Exit();
}
catch (Exception ex)
{
}
}
private void time_Tick_1(object sender, System.EventArgs e)
{
Rectangle bounds = default(Rectangle);
System.Drawing.Bitmap screenshot = default(System.Drawing.Bitmap);
Graphics graph = default(Graphics);
bounds = Screen.PrimaryScreen.Bounds;
screenshot = new System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
graph = Graphics.FromImage(screenshot);
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
picture.Image = screenshot;
time.Enabled = false;
this.Opacity = 100;
}
private void picture_MouseUp(object sender, MouseEventArgs e)
{
paint = false;
}
private void picture_MouseDown(object sender, MouseEventArgs e)
{
paint = true;
}
private void picture_MouseMove(object sender, MouseEventArgs e)
{
if (paint)
{
Graphics g = picture.CreateGraphics();
color = new SolidBrush(Color.Blue);
g.FillEllipse(color, e.X, e.Y, 5, 5);
}
}
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am a beginner. I have code to read in a text file, and part of how to get the strings into a text box. The format of the text file is like DREC: 04HF; and then the next begins with that same format. I need to read that from the text file and split it into 2 separate text boxes (3,4) at a : or a ; . Thank you for the help.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog of = new OpenFileDialog();
of.ShowDialog();
textBox1.Text = of.FileName;
}
private void button2_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(textBox1.Text);
textBox2.Text = sr.ReadToEnd();
sr.Close();
}
private void button3_Click(object sender, EventArgs e)
{
int lcount;
string s;
int i;
lcount = textBox2.Lines.Length;
s = textBox2.Lines[0];
for (i = 0; i < lcount; i++)
{
textBox4.Text = textBox2.Lines[i];
}
textBox4.Text = s;
}
}
I need a better description of what you are doing but maybe this will help
//split apart segments
string[] split1 = textBox2.Text.Split(';');
foreach (string segment in split1)
{
//split sub-segment
string[] split2 = segment.Split(':');
//check if it's valid
if (split2.Count().Equals(2))
{
textBox3.Text += String.Format("{0}{1}", split2[0].Trim(), Environment.NewLine);
textBox4.Text += String.Format("{0}{1}", split2[1].Trim(), Environment.NewLine);
}
else
{
throw new ArgumentException("Invalid Segment");
}
}
i wrote a code for accessing webcam and on clicking, saving the picture to a folder.
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 AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Video;
using AForge.Video.DirectShow;
namespace cam
{
public partial class Form1 : Form
{
public static Bitmap _latestFrame;
public Form1()
{
InitializeComponent();
}
private FilterInfoCollection webcam;
private VideoCaptureDevice cam;
Bitmap bitmap;
private void Form1_Load(object sender, EventArgs e)
{
webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in webcam)
{
comboBox1.Items.Add(VideoCaptureDevice.Name);
}
comboBox1.SelectedIndex = 0;
}
private void button1_Click(object sender, EventArgs e)
{
cam = new VideoCaptureDevice(webcam[comboBox1.SelectedIndex].MonikerString);
cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
cam.Start();
}
void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
bitmap = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = bitmap;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.Image = bitmap;
}
private void button3_Click(object sender, EventArgs e)
{
if (cam.IsRunning)
{
cam.Stop();
}
}
private void button2_Click(object sender, EventArgs e)
{
Bitmap current = (Bitmap)_latestFrame.Clone();
string ActiveDir = AppDomain.CurrentDomain.BaseDirectory;
string filepath = System.IO.Path.Combine(ActiveDir, #"D://picture/");
if (!System.IO.Directory.Exists(filepath))
{
System.IO.DirectoryInfo OutputDir = System.IO.Directory.CreateDirectory(filepath);
string fileName = System.IO.Path.Combine(filepath, #"name.bmp");
if (!System.IO.File.Exists(fileName))
{
current.Save(fileName);
}
}
current.Dispose();
}
}
}
In the button2 I have written the code for saving the picture, on building the program, an null reference exception is shown for the given line(Bitmap current = (Bitmap)_latestFrame.Clone();)
As far as I can see in your code, the new image frame is copied to your member variable bitmap. The static member _latestFrame never seem to be assigned.
Therefore, in your button2_Click method, change the first line to:
Bitmap current = (Bitmap)bitmap.Clone();
Now, provided you have received at least one frame from the webcam when you click the button, the frame should be properly saved.
I also think you are overworking the filepath setting in the button2_Click method. To begin with, simply verify that the picture can be properly saved to the active directory by changing your button2_Click method to this:
private void button2_Click(object sender, EventArgs e)
{
Bitmap current = (Bitmap)bitmap.Clone();
string filepath = Environment.CurrentDirectory;
string fileName = System.IO.Path.Combine(filepath, #"name.bmp");
current.Save(fileName);
current.Dispose();
}
This will ensure that a new image will be written to the "current directory" every time you click on the Capture button.
I have tested your code with the above changes, and it works flawlessly.
i want to play video in c#. i searched related tutorial and i found this. i followed exactly the same but the video would not appear.
here is my code.
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 Microsoft.DirectX.AudioVideoPlayback;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
Video video;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// store the original size of the panel
int width = panel1.Width;
int height = panel1.Height;
// load the selected video file
//video = new Video("C:\\Users\\HDAdmin\\Desktop\\Example.avi");
video = new Video(openFileDialog1.FileName);
// set the panel as the video object’s owner
video.Owner = panel1;
// stop the video
video.Stop();
// resize the video to the size original size of the panel
panel1.Size = new Size(width, height);
try
{
video.Audio.Volume = 100;
}
catch { }
}
}
private void button2_Click(object sender, EventArgs e)
{
if (video.State != StateFlags.Running)
{
video.Play();
}
}
private void button3_Click(object sender, EventArgs e)
{
if (video.State == StateFlags.Running)
{
video.Pause();
}
}
private void button4_Click(object sender, EventArgs e)
{
if (video.State != StateFlags.Stopped)
{
video.Stop();
}
}
}
}
i even tried to put a path of the video like this:
video = new Video("C:\\Users\\HDAdmin\\Desktop\\Example.avi");
but both of it will show the error like picture below.
my question is, how i want to enable to view and play the video by using windows form application in c#?
p/s: i want to use Directx only and do not want to play the video in windows media player.