|
Hello,
I have the following code in a win app:
// create bitmap from file
Bitmap myBitmap = new Bitmap(textBox1.Text);
Graphics g = Graphics.FromImage(myBitmap);
g.RotateTransform(30); //rotate 30 degrees
// create a new bitmap from the Graphics object
Bitmap next = new Bitmap(myBitmap.Width, myBitmap.Height, g);
// save the new bitmap to disk
next.Save("c:/documents and settings/vortex/Desktop/file.jpg");
When this code is executed, an empty image file with the right dimensions is stored - just a blank (white) image... I tried without rotating, but nothing happened either.
I would appreciate if you could give me any hints about the problem.
Thank you in advance.
"Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
|
|
|
|
|
The constructore you used for your second Bitmap is wrong, its just use resolution of graphic object. You have to use Bitmap.Clone() method to create copy of your Bitmap .
Mazy
"I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein
|
|
|
|
|
It seems you understood the whole point wrongly...
My intentions are to load a bitmap, manipulate it (e.g. Rotate it), and finally save it to another file...
I thought the steps I described ( Bitmap->Graphics->Bitmap->file) could do it, but there was something wrong in that code.
I strictly followed the MSDN documentation, but still I was unable to achieve this...
"Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
|
|
|
|
|
Vladimir Georgiev wrote:
// create a new bitmap from the Graphics object
Bitmap next = new Bitmap(myBitmap.Width, myBitmap.Height, g);
Dont do that! Just save "myBitmap"
top secret
|
|
|
|
|
Saving myBitmap does not save the rotated bitmap:
// file is a 24-bit .bmp file
Bitmap myBitmap = new Bitmap(textBox1.Text);
Graphics g = Graphics.FromImage(myBitmap);
g.RotateTransform(30);
myBitmap.Save("c:/documents and settings/vortex/Desktop/file123.bmp");
My main purpose is to open a bitmap, get some pixels from it, calculate the rotation degree based on those pixels, rotate and save the bitmap.
MSDN says that you could create a Graphics object from a bitmap, and vice-versa as well... But it does not work...
Any help is highly appreciated.
"Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
|
|
|
|
|
Vladimir Georgiev wrote:
g.RotateTransform(30);
I think you are reading the function wrong. This just adjusts your "perspective" from a drawing point of view. IOW anything drawn after that will be "tilted".
Thats said do this:
Bitmap myBitmap = new Bitmap(textBox1.Text);
Bitmap newb = myBitmap.Clone() as Bitmap;
Graphics g = Graphics.FromImage(newb);
g.RotateTransform(30);
g.DrawImage(myBitmap);
newb.Save("c:/documents and settings/vortex/Desktop/file123.bmp");
top secret
|
|
|
|
|
For all you grid programmers out there.
I'm working on a very simple grid solution and I have a question. I've seen some commercial products (Syncfusion) that have the ability to customize cells with customer cell models and renderers. One of the cells you can create is a custom control cell. The catch here is that the grid uses only one instance of the control to render all the cells that use that cell type.
I just need to know how to use a single instance of a control, reconfigure it for every cell with new cell data, and paint in different area of the grid control.
|
|
|
|
|
AK wrote:
I just need to know how to use a single instance of a control, reconfigure it for every cell with new cell data, and paint in different area of the grid control.
Why on earth do you wanna "copy" there stupid design? Do it just like owner drawn menus, combobox's and type convertors. Using a control as a singleton in this situation is absurd , and most likely not even contained in the grid, and it methods are purely used for rendering. You dont need a control for that, just a static method in a class will suffice.
top secret
|
|
|
|
|
By the way, I've done quite a bit of grid before. Using a simple custom cell drawing is nothing new to me. I understand that I dont need a control to get the cell to pain properly. The reason I want to have a control is because I need a real control to interact with when the cell is focused.
I was hoping that someone knew how to "abuse" the painting code of the control to get the control to paint itself into a certain area of my grid without having to actually create a million instances of the control and aligning them to form a grid.
|
|
|
|
|
Actually you extend the datagridColumn class. Once there you can override paint methods for drawing, add controls and use GetValueAtRow and SetValueAtRow.
www.syncfusion.com has a faq thats excellent for this
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I got it figured out. Thanks for trying guys.
A clue for others that need to do something similar. Use native methods. 1. Get WindowDC 2. Create compat bitmap 3. select the object 4. Send WM_PRINT message to window specifying the memory DC as the device context
|
|
|
|
|
I want to remove a row from my database based on the instance of a title.
For example if i enter win32newb as the title it will filter the database to only include that row and delete it. Here is what i have in my code but it doesn't work. It throws an exception saying the current status is closed.
private void removebutton_Click(object sender, System.EventArgs e)
{
string strSQL = "DELETE * FROM Movie WHERE Title = ";
strSQL += searchbox.Text;
oleDbDeleteCommand1.CommandText = strSQL; //add the string to deletecommand
oleDbDataAdapter1.DeleteCommand = oleDbDeleteCommand1;
oleDbDeleteCommand1.Connection = oleDbConnection1;
oleDbDeleteCommand1.ExecuteNonQuery();
}
If you know of an easier method I'm open for suggestions. Anything that works pretty much. Thanks. Also, how would i make it where if the title that is entered doesn't exist it would not execute cause wouldn't that throw an exeception also if the title doesn't exist?
Thanks in again
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
win32newb wrote:
oleDbDeleteCommand1.Connection = oleDbConnection1
Best is to open and close the connection just before and after the "executenonquery".
win32newb wrote:
Also, how would i make it where if the title that is entered doesn't exist it would not execute cause wouldn't that throw an exeception also if the title doesn't exist?
Use a try/catch
top secret
|
|
|
|
|
thanks for the reply. I have a question maybe you or someone else can help with. Either my sql statement is not correct or something. I keep getting an exception because the catch keeps showing up.
I have a database with a table called Movie and it has fields Information and Title.
I have a test value in there called tony.
thanks for the help.
try
{
string strSQL = "DELETE * FROM Movie WHERE Title = ";
strSQL += searchbox.Text;
oleDbDeleteCommand1.CommandText = strSQL;
oleDbDataAdapter1.DeleteCommand = oleDbDeleteCommand1;
oleDbDeleteCommand1.Connection = oleDbConnection1;
oleDbDeleteCommand1.Connection.Open();
oleDbDeleteCommand1.ExecuteNonQuery();
oleDbDeleteCommand1.Connection.Close();
}
catch
{
MessageBox.Show("Not found");
}
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
win32newb wrote:
catch
{
MessageBox.Show("Not found");
}
replace that with:
catch (Exception ex)
{
MessageBox.Show(ex.Tostring());
}
You will get a MUCH better error condition, and if you dont know what to do with it, I'm sure many a person on CP will be able to help
top secret
|
|
|
|
|
thanks i was wondering how to use that. i'm very new to this c# amazes me i konw this much haha.
anyway i got it working.
try
{
string strSQL = "DELETE FROM Movie WHERE Title = '" + searchbox.Text + "'";
oleDbDeleteCommand1.CommandText = strSQL;
oleDbDataAdapter1.DeleteCommand = oleDbDeleteCommand1;
oleDbDeleteCommand1.Connection = oleDbConnection1;
oleDbDeleteCommand1.Connection.Open();
oleDbDeleteCommand1.ExecuteNonQuery();
oleDbDeleteCommand1.Connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Not found");
MessageBox.Show(ex.ToString());
}
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Dear Sir,
Ihope that this mail finds you in good shape. Well, the thing is that I am really very depressed and dishearted these days. I am a student doing my BS in Computer Science and next week I've to submit my c# project.
The onle problem I'm facing is that
!! HOW DO WE RUN a FLASH MOVIE in a C#SHARP APPLICATION?
I've tried everything. it gives an error.
Object Reference Not Set To an Instance of an Object.
Any Solutions,
Please send them to me
Truly Yours,
Imad
Imad
|
|
|
|
|
Just reference the FlashActiceX component.
top secret
|
|
|
|
|
The thing is that, I have already imported a Com Control by the name of Shockwave Flash Objects. but as soon as I embed and run this control in my C# Windows Application the .NET Framework Crashes.
Please help me out What should I do?
itsimad@hotmail.com
Imad
Imad
|
|
|
|
|
I am trying to create a binary file but the binarywriter doesnt work and its a pdf so I believe it has to be true binary with no unicode style delimiters. Do I need to write c++ code in my assembly or does c# have a way?
Nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Ista wrote:
I am trying to create a binary file but the binarywriter doesnt work and its a pdf so I believe it has to be true binary with no unicode style delimiters.
What are your trying to write to a file? What is PDF, I thought u are writing a file. Why unicode appear in a binary file?
Ista wrote:
Do I need to write c++ code in my assembly or does c# have a way?
I think you need to look for Dorothy, the lion and the tin man, perhaps they can tell you.
top secret
|
|
|
|
|
leppie wrote:
I think you need to look for Dorothy, the lion and the tin man, perhaps they can tell you.
A little rough, isn't it?
- Nick Parker My Blog | My Articles
|
|
|
|
|
Nick Parker wrote:
A little rough, isn't it?
Not rough enough it appears!
top secret
|
|
|
|
|
I think dorothy would be of more assistance to you.
pdf is just text written to a binary file. The BinaryWriter writes in unicode which is standard in .net.
And when you write a file in .net it leaves unicode delimiters without special formatting.
Its really a simple question if you read it.
I need to create a binary file. How do you do that in c#. As of current I think c++ is the only way.
And yes the lion is someone with at least an advanced background with an understanding of files which hasn't read my question yet.
Nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|