|
I have an image of a classroom. I want to get the position(coordinate) of every desk in it(the color of the desk is different from that of the background).
Are there any good and simple arithmetic to deal with this problem? It doesn't have to be very precise.
Thanks!
|
|
|
|
|
Hi,
I am creating one bitmap object, say of size 500 by 100. Using this object im
creating one Graphics obect and using that im drawing some rectangles and so. After that when i save the bitmap object, i will get all the rectangles. But problem is, if drawn rectangles from graphics objects are of greater width than of bitmap object, Graphical object display it correctly but bitmap object will clip the extra part of image. How to solve this?
Expecting favourable reply.............
Shivaprasad
|
|
|
|
|
What is the problem, really? If you draw a rectangle that is larger than the area that you are drawing on, it will be clipped. Everything works that way. If you draw a rectangle on the screen that is larger than your screen resolution, it will be clipped. It won't be drawing pixels in mid air beside your monitor.
There are only two possible ways to avoid the clipping:
:: Draw smaller rectangles.
:: Create a bigger Bitmap object to draw on.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Directly coming to the point, can I resize bitmap object at runtime?
By,
Shivaprasad
|
|
|
|
|
puttaraj wrote: can I resize bitmap object at runtime?
No. You have to create a new bitmap and copy the data.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Perhaps the FixedSize() method below will do what you're looking for (I decided to include the other methods in case you find something useful in them too).
For instance:
int fixedWidth = sourceImageObj.Width + 20;
int fixedHeight = sourceImageObj.Height;
Image newImageObj = ImageWork.FixedSize(sourceImageObj, fixedWidth, fixedHeight, backgroundColor);
would return an image object of size ('fixedWidth' * 'fixedHeight') with the original image proportionally scaled to the new size (and centered, with ten extra pixels to either side) and with the "extra" bits set to the value of 'backgroundColor.'
#region Class: ImageWork
public class ImageWork
{
public static System.Drawing.Image ClipImage(
System.Drawing.Image sourceImage,
System.Drawing.Rectangle sourceRect,
int targetWidth, int targetHeight)
{
System.Drawing.Rectangle targetRect = new
System.Drawing.Rectangle(0, 0, targetWidth, targetHeight);
return ClipImage(sourceImage, sourceRect,
targetWidth, targetHeight, targetRect,
System.Drawing.Color.Empty);
}
public static System.Drawing.Image ClipImage(
System.Drawing.Image sourceImage,
System.Drawing.Rectangle sourceRect,
int targetWidth, int targetHeight,
System.Drawing.Color bkgColor)
{
System.Drawing.Rectangle targetRect = new
System.Drawing.Rectangle(0, 0, targetWidth, targetHeight);
return ClipImage(sourceImage, sourceRect,
targetWidth, targetHeight, targetRect,
bkgColor);
}
public static System.Drawing.Image ClipImage(
System.Drawing.Image sourceImage,
System.Drawing.Rectangle sourceRect,
int targetWidth, int targetHeight,
System.Drawing.Rectangle targetRect,
System.Drawing.Color bkgColor)
{
System.Drawing.Bitmap returnImage = new
System.Drawing.Bitmap(
targetWidth, targetHeight,
System.Drawing.Imaging.PixelFormat.Format32bppRgb);
returnImage.SetResolution(
sourceImage.HorizontalResolution,
sourceImage.VerticalResolution);
System.Drawing.Graphics grImage =
System.Drawing.Graphics.FromImage(returnImage);
grImage.Clear(bkgColor);
grImage.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grImage.DrawImage(sourceImage,
targetRect,
sourceRect,
System.Drawing.GraphicsUnit.Pixel);
grImage.Dispose();
return returnImage;
}
public static System.Drawing.Image FixedSize(
System.Drawing.Image sourceImage,
int fixedWidth, int fixedHeight,
System.Drawing.Color bkgColor)
{
System.Drawing.Rectangle sourceRect = new System.Drawing.Rectangle
(0, 0, sourceImage.Width, sourceImage.Height);
System.Drawing.Rectangle targetRect = FixedSize_ResizeRectangle
(sourceImage.Width, sourceImage.Height, fixedWidth, fixedHeight);
return ClipImage(sourceImage, sourceRect,
fixedWidth, fixedHeight, targetRect, bkgColor);
}
public static System.Drawing.Image FixedSize_EmptyImage(
int fixedWidth, int fixedHeight,
System.Drawing.Color bkgColor)
{
return FixedSize(new System.Drawing.Bitmap(1, 1),
fixedWidth, fixedHeight, bkgColor);
}
public static System.Drawing.Rectangle FixedSize_ResizeRectangle(
int sourceWidth, int sourceHeight,
int fixedWidth, int fixedHeight
)
{
int targetMapOffsetX = 0;
int targetMapOffsetY = 0;
int targetMapWidth = 0;
int targetMapHeight = 0;
float dummyMapRatio = 0f;
FixedSize_ResizeRatios(
sourceWidth, sourceHeight,
fixedWidth, fixedHeight,
ref targetMapOffsetX, ref targetMapOffsetY,
ref targetMapWidth, ref targetMapHeight,
ref dummyMapRatio);
return new System.Drawing.Rectangle(
targetMapOffsetX, targetMapOffsetY,
targetMapWidth, targetMapHeight);
}
public static void FixedSize_ResizeRatios(
int sourceWidth, int sourceHeight,
int fixedWidth, int fixedHeight,
ref int targetMapOffsetX, ref int targetMapOffsetY,
ref int targetMapWidth, ref int targetMapHeight,
ref float targetMapRatio
)
{
targetMapOffsetX = 0;
targetMapOffsetY = 0;
targetMapWidth = 0;
targetMapHeight = 0;
targetMapRatio = 0f;
float targetMapRatioWidth = ((float)fixedWidth/(float)sourceWidth);
float targetMapRatioHeight =
((float)fixedHeight/(float)sourceHeight);
if (targetMapRatioHeight < targetMapRatioWidth)
{
targetMapRatio = targetMapRatioHeight;
targetMapOffsetX = System.Convert.ToInt16(
(fixedWidth - (sourceWidth * targetMapRatio))/2);
}
else
{
targetMapRatio = targetMapRatioWidth;
targetMapOffsetY = System.Convert.ToInt16(
(fixedHeight - (sourceHeight * targetMapRatio))/2);
}
targetMapWidth = (int)(sourceWidth * targetMapRatio);
targetMapHeight = (int)(sourceHeight * targetMapRatio);
}
}
#endregion
|
|
|
|
|
In an applicatin which programatically compiles a C# project, i am facing a problem in adding Resources like images. i read about EmbeddedResources method of class Compiler Parameter and tried to add the resources using it, but couldnt get the desired result. Can any one tell me how to add resources for ciompiling C# project???
Thanx in advance
|
|
|
|
|
Ever get this to work?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Hi Folks
I enabled audit logging on a particual folder. The transactions happening on that folder will be logged in Security event logger. I want to generate an excel report with the details (User name, File Opened/Deleted/Created, DataTime).
Thanks in Advance
Regards
Hari
|
|
|
|
|
hi all,
i have to assign {1,2,3} to bye object ....
and also (str.length-1) to a byte type object in c sharp....
Plz tell me how to do it....its urgent
Thanks and regards
Ahmad
ahmad.osama1984@gmail.com
|
|
|
|
|
Perhaps you should try to attend your classes, then perhaps you would at least know what to ask for...
Osama123 wrote: i have to assign {1,2,3} to bye object ....
A byte is not an object, it's a value type.
The data that you say that you have to assign to something seems to be the data part of a literal declaration of an array. It seems like you saying that you are trying to put an array into a single byte, but as that is impossible, what is it that you are trying to do?
Osama123 wrote: and also (str.length-1) to a byte type object in c sharp....
What is "str "? Is that an instance of a class that you have created? It could have been a string, an array or a list, but there is no length property for either of those, the name of the property is Length .
It sounds like what you are after is a simple variable assignment, but that is too easy to ask about in a forum, even for a beginner. What is it that you are trying to accomplish?
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Hi,
How can I create Array with index type of String?
so I statement like this :
String myName = myArray["tommy"];
//result: myName = "tommy bunny"
thx
|
|
|
|
|
Hello Tomy,
You could do something like that:
System.Collections.Hashtable hStrings = new Hashtable();
public YoureConstructor()
{
hStrings.Add("tommy", "tommy bunny");
hStrings.Add("mary", "mary bunny");
hStrings.Add("honey", "honey bunny");
}
private string GetTextOutOfHashtable(string key)
{
if(hStrings.ContainsKey(key))
{
return hStrings[key].ToString();
}
else
{
return "";
}
}
private void SomeMethod()
{
string mytext = GetTextOutOfHashtable("tommy");
}
In this case a Hashtable is used to hold youre text.
Hope that helps!
All the best,
Martin
-- modified at 2:50 Friday 15th December, 2006
|
|
|
|
|
so, I just have to make on Object oh Hashtable.
ok, thx
|
|
|
|
|
Hello,
That's what came in my mind at first.
I'm not sure if it's the best solution for youre problem, but it will work.
All the best,
Martin
|
|
|
|
|
In case you're using Framework 2.0 you should use the generic Dictionary instead of HashTable as it provides the same functionality and additionally makes your code type-safe.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
|
I have a C#/OpenGL screensaver I've been working on. First I tried CsGL, now I have it working with the Tao library. I've always been a fan of Taoism, so hopefully I'll have better luck this time. I had one problem where it would freeze after rendering a few frames, but wouldn't let me catch an exception or anything. I would love it if anyone has heard of this problem, please let me know what caused it. Also, please try the screensaver and see if it works for you. There's a page for it here:
http://www.smoothjazzy.com/prog_screensaver.htm[^]
I really need to get this working so any help would be appreciated. I can send source code but I wouldn't know which part to start with... BTW, the problem is not occurring now - not for me at least
"Quality Software since 1983!" http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!
|
|
|
|
|
Hi, Im kinda new here.
I was just wondering if there was a way to watch outgoing connections (ie if program a wants to connect to 239.349.12.34 port 3309 then I could watch all data it sends and recieves) is it possible?
|
|
|
|
|
Hi,
I have problem with my DataSet ebhabiour.
In my program, I created a public static myDataSetObj which holds all the tables in my active database in MySQL.
I place that DataSet in a class named clsGlobal. inside clsGlobal, I also make some public static procedures, procedure X to read all tables from MySQL database, procedure Y to read all tables found and insert the tables into DataSet.
Procedure X and Y are executed in MainFormObj.onLoad.
After that, I pressed ProductButton in MainFormObj to display ProductFormObj. Inside ProductFormObj, there is a public DataGrid and an UpdateButton.
In ProductButton click event, I instruct that DataGrid.DataSource in ProductFormObj is pointed to clsGlobal.MyDataSetObj.Tables["product_table"];
When ProductFormObj launches, I can see that the DataGrid displays nicely the content of table "product_table".
Then, in UpdateButton click event, I place this code:
if(clsGlobal.MyDataSetObj.Tables["product_table"].getChanges() != null){
MessageBox.show("Data Changed");
}
else{
MessageBox.show("DATA NOT CHANGED");
}
The problem is, when I change the content of DataGrid and press UpdateButton, Message "DATA NOT CHANGED" keeps displaying. This is not right?? because the content of "product_table" has changed.
BUT, when I closes the ProductFormObj and opened it again, my new value in DataGrid still exist and this time a directly pressed UpdateButton (without editing data in DataGrid) the message "Data Changed" appear!
In the other hand, I also have another project that works with similar system as abvove. But much simpler in code and structure.
Well, many thx for any helps.
|
|
|
|
|
Well, I just solved it. I change the TOOLSTRIPBUTTON to BUTTON. same code.
and it works!!
What is this...
BUG ????
|
|
|
|
|
Hi,
I have a problem when using BackgroundWorker in MDI child Form.
Each MDI child in my application has its own BackgroundWorker, which is use for downsampling image. The backgroundworker in MDI child will auto start after the Child Form created.
The problem I found is, when I open more than one MDI child(that means mulitple downsampling process is running at the same time), but some process of MDI child will be stopped.
I don't know why it will stop. Is there any limitation of BackgroundWorker?
Can anyone know this issue? How can I solve it?
Thanks a lot.
|
|
|
|
|
How many threads are you trying to run? Too many can just slow things down.
"Quality Software since 1983!" http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!
|
|
|
|
|
I just try to open 2 child Form.
Both of them are starting the downsample process.
slow down problem we can understand, and is acceptable . But one thread suddenly stop, it makes us feel a big problem.
Btw, each child Form, just starting one BackgroundWorker.
I really don't know why it will stop? Did I get something wrong?
|
|
|
|
|
There's a lot that can go wrong with multiple threads. How are they invoked? Are they started by the main form or something else? Do they have any shared object? Send code...
"Quality Software since 1983!" http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!
|
|
|
|
|