|
hi,
Is there a way to use BitBlt in order to find if
a specific BMP file is inside another ?
for example:
If I have Bitmap1.Bmp which is a small file
and Bitmap2.Bmp which is bigger,
can i find out if the picture inside Bitmap1 is
also inside Bitmap2 ?
Thanks in advance.
|
|
|
|
|
No - that is not even remotely what BitBlt does. You'd have to examine the bits of the bigger file, to see if you can find the bits of the smaller file inside it.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Currently I am doing that by tring to find a line of pixels which are the top row of the smaller file
inside the bigger file and if i find it i compare the rest pixel lines.
i was told there is a simpler way to do that.
if anyone knows of such way, please write it down.
Thanks.
|
|
|
|
|
Kobi_Z wrote: i was told there is a simpler way to do that.
I've been told lots of things too. It's possible that you could use BitBlt operations to merge two identical bitmaps and end up with one that's all black or all white, but you want to find a bitmap in a SECTION of another, which kills even that idea. You're stuck. Read my image processing articles for ideas on how to most quickly compare images. You will need to use C#, VB only writes slow imaging code.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
imho an efficienty pattern findign algorithm would be your best choice. using bitblt is like using the worst pattern finding solution ever
ofcourse you might want to aviod using GetPixel(). Heres a class, use this (unfortunately i cant give proper credit to the author):
-Load your bitmap;
-Create a fast bitmap.
-copy your loaded bitmap into fast bitmap (instanicate a graphics over it and use drawimage)
-you have a simple array of bites in the fast bitmap (bits). expose it and use with an efficient pattern finder.
public class FastBitmapEditor
{
public int Height;
public int Width;
public Bitmap bitmap;
byte[] bits;
GCHandle handle;
int stride;
int pixelFormatSize;
public FastBitmapEditor(int width, int height)
{
Width = width;
Height = height;
PixelFormat format = PixelFormat.Format32bppArgb;
pixelFormatSize = Image.GetPixelFormatSize(format) / 8;
stride = width * pixelFormatSize;
bits = new byte[stride * height];
handle = GCHandle.Alloc(bits, GCHandleType.Pinned);
IntPtr pointer = Marshal.UnsafeAddrOfPinnedArrayElement(bits, 0);
bitmap = new Bitmap(width, height, stride, format, pointer);
}
public Color GetPixel(int x, int y)
{
int blue = bits[(y * Width + x) * 4];
int green = bits[(y * Width + x) * 4 + 1];
int red = bits[(y * Width + x) * 4 + 2];
int alpha = bits[(y * Width + x) * 4 + 3];
return Color.FromArgb(alpha, red, green, blue);
}
}
|
|
|
|
|
Hello !
Is there any kind of algorithm that will calculate how many rectangles can if in one big rectangle ?
I have following problem: have big rectangle, and then many smaller rectangles. I need to fit as much rectangles as it is possible in the big one.
Can anyone help ?
Btw, I was trying to make something myselft, but I only came out with recursive solution, and I think that it will be too slow (especially when you have maaaaany rectangles).
Thanks
|
|
|
|
|
You might get a better answer in the Algorithms forum. But I would personally iterate from 0 to srcRect.Width, and iterate inside that from 0 to srcRect.Height. If the two iteration variables aren't equal, then add it to the list. That'll account for different sizes. You could loop again, through each item in the list to take different positions and the same size into account.
The problem I can think of is that this would be extremely slow.
|
|
|
|
|
hehe, that's kind of what I've thought of Thanks anyway
|
|
|
|
|
I can't offer you a ready made solution but I figured out a little function that may at least help you out: Round a number to a multiple of another number[^]
It would only give you a one-dimensional solution, but someone posted a reply to my article, saying that they used it in a grid calculation.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thanks for reply, I'll look into that
|
|
|
|
|
we had to write a cut optimisation software once. I can't give you any detailed code but i can remember that you have to sort your small rectangles by size and the try to fit in the biggest piece first.
You may find something useful if you google for 'cut optimisation'.
Tosch
|
|
|
|
|
Yea, that's what I'm writing ... Cut optimization software Thanks for suggestion for google search, I'll try it
|
|
|
|
|
|
Thanks, I'll read it
|
|
|
|
|
Hi all.
in my app i have to load one or two million of strings from the database to an array.
after loading i close the database connection.
i run a FOR loop and load the array
but memory reaches 125 MB
how to make it low?
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
Don't load so much data into memory.
What are you trying to achieve that you need so much data loading into memory from a database?
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
My main motive is to save the data in the database and then on loading the application ALL the data from the database is loaded into an array of string datatype.
well it is really essential to load all the data, so i'll have to load it.
what i am looking for is a method to lower the memory utilization.
i tried to minimize the window and then restore it. This solves the memory problem but i want to use it as the last available option.
can you(or anyone) tell me how to lower the memory(RAM) utilazation?
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
Have you tryed to trim strings before load them in the array?
|
|
|
|
|
if you mean using the Trim() function, there is no need because there are no
spaces(leading or trailing).
thanks anyway for the suggestion.
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
TheMrProgrammer wrote: well it is really essential to load all the data, so i'll have to load it.
I am not sure why you need to do this. Are you doing this to make further data fetching to be from memory and do you think it is going to be faster than querying database for required data? If you need frequent data retrieval, array won't be the right data structure as it takes linear time for search.
TheMrProgrammer wrote: what i am looking for is a method to lower the memory utilization.
Do you have 2 million unique strings? Strings are interned by the CLR and same strings can share the memory. Have you profiled your application? Use CLR profiler and find out which area is using more memory.
So hard to tell more without knowing details about your application.
|
|
|
|
|
Yes I need frequent data retrieval.
can you tell me waht will be the right data structure to do so.
Thanks
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
You don't need to worry about it. What you did by minimizing the app and restoring it tells me that you only looked in TaskManager for the memory statistic. Don't. What you're seeing the memory the .NET CLR has RESERVED for your application, not how much your app is actually using. Use Performance Monitor instead to see what your app is really using.
You do not need to worry about the extra memory being reserved. The .NET Memory Manager keeps extra memory in the pool to allocate new objects your app wants as fast as possible. WIthout this, the Memory Manager has to request more memory from Windows and add it to the Managed Pool, which takes time. So, yeah, you can reduce this extra pool, but you're only hurting your apps performance by doing so.
Now, if Windows needs that memory back, the Memory Manager will be more than happy to return any extra memory it can back to Windows, without you doing anything.
|
|
|
|
|
hey thanks fer tha info
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
TheMrProgrammer wrote: how to make it low?
Don't load 2 million strings!
Try to find a logical way to subdivide the dataset and process it a bit at a time.
Without knowing what it is that you need to do with the data it is difficult to give more detailed advice.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I don't see other ways than that already suggested you, but you can check if it is possible to elaborate strings directly in the database. I don't know if it's possible, and if yes, how to do that.
|
|
|
|