|
i use this code:
Image tmp1 = Image.FromFile(path);
Graphics g = Graphics.FromImage(tmp1);
g.DrawImage(tmp1, new Rectangle(new Point(0,0), new Size(40, 70)), 30, 40, 40, 70, GraphicsUnit.Pixel);
pictureBox1.Image = tmp1;
but it draw the perfect original tmp1 image without cutting...
|
|
|
|
|
I am not sure why, but problem is that you use same object as source and destination...
Image tmp1 = Image.FromFile("../../Bitmap1.jpg");
Image img = new Bitmap(100,100);
Rectangle srcRect = new Rectangle(0,0,50,50);
Rectangle destRect = new Rectangle(0,0,20,100);
Graphics g = Graphics.FromImage(img);
pictureBox1.Image = img;
g.DrawImage(tmp1, destRect, srcRect, GraphicsUnit.Pixel);
g.Dispose();
tmp1.Dispose();
David
|
|
|
|
|
|
i've loaded a png file.
now i want to cut a rect from it and draw in a specific Top-Right position of a picturebox.
What functions i heve to call?
|
|
|
|
|
Make a brush form this image.
|
|
|
|
|
i know there is image.fromRect or functions similar, but i don't remember.
|
|
|
|
|
No,in the Brush class you cna make Brush.FromImage ,try it.
|
|
|
|
|
Hope this helps
public void Clone_Example(PaintEventArgs e)
{
// Create a Bitmap object from a file.
Bitmap myBitmap = new Bitmap("Grapes.jpg");
// Clone a portion of the Bitmap object.
RectangleF cloneRect = new RectangleF(0, 0, 100, 100);
PixelFormat format = myBitmap.PixelFormat;
Bitmap cloneBitmap = myBitmap.Clone(cloneRect, format);
// Draw the cloned portion of the Bitmap object.
e.Graphics.DrawImage(cloneBitmap, 0, 0);
}
|
|
|
|
|
ok now if i want to draw cloneBitmap in a particular position of a pictureBox how can i do?
Becouse i've tryed to do this:
pictureBox1.Image = cloneBitmap;
and it draw nothing while pictureBox1.Image = myBitmap; yes
|
|
|
|
|
OK I've found the problem!
I load a png file so i can't execute the cutting.
I don't know why but if i load bitmap and i try to cut it it works!
Someone can tell me why?
How can i do about using png files?
|
|
|
|
|
hi there.
iam developing an application but i don't know how can i make my application upgraded by adding some new features to it ? how can this be done theoritically anybody here has an idea how can i make my application after finishing it to add new features by upgrading like accepting new dll files from my website of this application like any famous programs ??? any body here as an idea about that
Miss With The Best And Die Like The Rest
|
|
|
|
|
When I wrote my firs (and only ) "self updating" program, I use teh following method:
- I create a static string in teh code for the version number
- I create a folder in my website in the folder there is a textfile called version.txt contains only one line, the current version number, and int his folder also in the new verson of tehe .exe and a nother file called updater.exe
- when my app starts meka a web request, and read the version number from the version.txt and if it's not same as the number in the exe:
- download the updater.exe, and run it
- the updater.exe close the real app, and download the new app.exe from the web
- then start it, and close themselves
- now, the new version is on the machine, and run
Perhapes the app delete the updater.exe from the computer, vhen finishing the update
I know It's a crazy, nd maybe stupid way, but when I do this I haven't a better idea, and It's work fine
But the exper CP aunthors shud tell you a better way :->
|
|
|
|
|
You have to design your application to be "easily upgradable" at the first place Take a look at Razor Framework[^].
David
|
|
|
|
|
I am using image streams to set the images of my toolbar.
If I close the streams, I get generic GRI+ error. On the other hand
if I dont close them, the error is resolved.
Any ideas?
|
|
|
|
|
Straight from MSDN Image.FromStream docs:
Remarks<br />
You must keep the stream open for the lifetime of the Image object.
I created a Bitmap helper class that copied the bytes to MemoryStream and managed the Bitmap from there. Here are some of the methods of the class:
public void Load(Stream sm)
{
Clear();
int len = (int) sm.Length;
byte[] buf = new byte[len];
sm.Read(buf,0,len);
_ms = new MemoryStream(buf);
_bm = (Bitmap) Image.FromStream(_ms);
}
public void Load(string fileName)
{
FileStream fs = new FileStream(fileName,FileMode.Open,FileAccess.Read);
Load(fs);
fs.Close();
}
public void Load(object dbField)
{
Clear();
if (dbField != DBNull.Value)
{
byte[] buf = (byte[])dbField;
_ms = new MemoryStream(buf);
_bm = (Bitmap) Image.FromStream(_ms);
}
}
public void Clear()
{
if (_bm != null)
{
_bm.Dispose();
_bm = null;
}
if (_ms != null)
{
_ms.Close();
_ms = null;
}
}
public Bitmap Bitmap
{
get {return _bm;}
}
|
|
|
|
|
|
I've been poking around the web for a solution to this and perhaps I'm not looking in the right place, so I thought I'd post the question.
My C# Form prompts the user for a username, password, and domain. I'd like to verify that these values are the same as the currently logged in Windows user. I can get the Username and Domain name from the Environemt class, but I need to verify that the password given is correct as well.
Any help out there?
never mind I found it....
DirectoryEntry de = new DirectoryEntry("WinNT://"+Environment.MachineName+", computer",txtUsername.Text,txtPassword.Text);
try
{
Object o = de.NativeGuid;
this.DialogResult=DialogResult.OK;
}
catch(Exception)
{
this.DialogResult=DialogResult.Cancel;
}
finally
{
de.Close();
}
|
|
|
|
|
I don't think it's an easy think, because as I know windows make his own hash coding for the password and store it in a hidden system folder.
|
|
|
|
|
I don't care what the password is, I just want to validate it. The code snipet I included works....problem solved. Thanks for you reply though.
|
|
|
|
|
OK!
I understand, you only want to validate, but I think (till now) the password file is prtected by the OS.
Would you kind to send, or link the snipets for me, It's interested me.
Thanks
|
|
|
|
|
Look at the code in my original post....it works.
|
|
|
|
|
Hi all.
Casting problem here!
If I have the following code:
<br />
Type classType = typeof(MyDerivedClass);<br />
MyBaseClass o = Activator.CreateInstance(classType) as MyBaseClass;<br />
...<br />
o.SomeFunctionInDerivedClass();<br />
This all works fine and splendid. But if I have this code in a function, and I want to, at runtime, decide on the type of class being instantiated, how do I do the 'as' keyword explicit cast? I'm using 1.1 so can't use templates/whatever they are called.
TIA
Gizz
|
|
|
|
|
If the type of the class is decided at runtime, then you can't have code like
o.SomeFunctionInDerivedClass();
either. What you'd have to do is use reflection to invoke methods, something like
object obj = Activator.CreateInstance(passedType);
obj.GetType().InvokeMember("SomeFunctionInDerivedClass",...);
Of course, the type you instantiated might not have an "SomeFunctionInDerivedClass" method, it'll then result in an exception and you have to handle it. That's the price to pay for reflection, you lose compile time type safety.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
I'm trying to get an idea of where to start looking for info on doing this or if it's even possible:
I'm working with VistaDB and it doesn't support Unicode yet. They claim that text is stored as "Ansi" only. Let's say I have a Unicode string and want to store it into a text field in their database.
Is it conceivable that I can convert that string to something that will store in Ansi (may well be unreadable gibberish at that point, no problem) then de-convert it back to unicode upon retrieval?
I.E. take the 16 bit unicode characters from UTF-16, split them out into ANSI (which I'm guessing is good old single byte 8bit characters) save it and later retrieve it and reverse the process?
"A preoccupation with the next world pretty clearly signals an inability to cope credibly with this one."
|
|
|
|