|
Obviously, I know how to load an image from a memory stream ( which is what I have on hand in this instance ), and I know how to resize it. What I want to know is, if I have a memory stream that represents a 4092x4092 PNG, does any method exist where by I can create a 1024x1024 ( for example ) copy of this image without having to have enough memory to hold the full size image as part of the process ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
As in when you load it, you don't want to have to load the whole thing, just load a 1/16th of the data to arrive at a new image?
[This is going to sound like a dodgy VB inspired workaround]
I would read in X pixels where X is dependent on the new size of the image.
Then average these to arrive at one pixel.
This continues until the end of the line, then you could repeat this X times, to give a few lines from the top of the image.
Then you repeat the process downwards, to arrive at a single row shrunk from the first X rows of the image.
Then repeat until the end of the stream.
If it works, mail me, I like a surprise now and then.
Ninja (the Nerd)
Confused? You will be...
|
|
|
|
|
Yeah, that's the sort of approach I was hoping is possible, the issue is that the image is a PNG. Once I have pixels I can examine, I have a bitmap in memory and my purpose has already not been achieved ( I don't know how to decompress a png one line at a time ).
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
The easiest way i can think of to resize an image, is to use graphics.drawimage
You'll have to calculate the ratio between the old size, and the new size. Then use the draw method to draw from 0,0,500,500 for example, into a new bitmap to the rectangle 0,0,250,250 That should resize the image. Then save this small portion in to a temp file somewhere. Then, move onto the next portion.
Once you've finished with the large image, you can get rid of it. Then, create a new bitmap of the desired size, and start opening up your temp files, and rebuild the full image.
Of course it would be quicker to sacrifice memory, and just copy the image directly. But if you have 32-bit images with huge sizes like 4092*4092, then it is gonna take up alot of space isn't it... infact almost 50MB
-- modified at 7:25 Friday 26th October, 2007
Okay, as for the original image, the problem is the header information, and the way the data is stored. For a regular bitmap, you could read the header information, find the size (width, height) and bit-depth of the image, then just start reading off the bytes because there's no compression.
As for something more like a png, it may be difficult to do because of the way the information is stored, and well, i havn't come up with much.
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
Yeah, you got to my issue. I can't do it with a PNG.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi Christian,
I don't expect there is a general solution, resizing an image file without loading the
entire file that is. For a specific format, you could write your own file decoder.
The PNG format consists of a lot of "chuncks", identified by a type field. There will
be a header (IHDR), some more attributes, then a number of data chunks (IDAT).
I don't expect the IDAT chunks to synchronize with scanlines though.
To get what you want, I would split the input image in "bands" (an arbitrary number of
consecutive scanlines), then do width reduction on each band, assemble the results into
a new image (graphics-form-bitmpa and DrawImage), then do the vertical reduction on the
image level.
If you try to do non-integer vertical reduction on bands you are bound to get artefacts,
such as moire, where the bands touch.
With this approach the overall memory footprint would be reduced by a factor of almost 4,
your linear scale factor that is.
Remark: if your scale factor were an exact integer (it is very close to 4, maybe 1023*1023
would be OK?) I would consider a direct two-dimensional rescale avoiding the input image
footprint altogether.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Sounds like a sensible solution. Sadly I have 24 hours to impliment this and other changes, not sure I can work out the PNG format in that time ( I also have to support JPG ).
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
As you are well aware, JPEG is a more complex format. I only scratched the surface of
that one!
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I've got an application that needs to create vitual networking
in there, there are node get routing table in the fewtime
when routing table is convergence
but I've got diffcult, I hope give hepl!
Thanks a lot!
|
|
|
|
|
Looks to me like ths is your homework. What problems do you have ? Where are you stuck ? What have you already achieved ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I will do exercise to networking. I want to people help!
DD:" Programming dynamic routing && convergence of routing table"
thanks you!
|
|
|
|
|
you're not very expicit...
Visit my blog at http://dotnetforeveryone.blogspot.com
|
|
|
|
|
in a checkboxlist there are checkboxes that are previously checked.
when a user unchecks it or checks another item from the list an email should be fired(event)
please help!
alok2171
|
|
|
|
|
OnCheckChanged event ==> if (new state == unchecked) ==> sendEmail()
There's your layout...
Ninja (the Nerd)
Confused? You will be...
|
|
|
|
|
Hi,
I have created one exe file. File is on server. Now I want to run this exe on client Machine.
When ever my web application's webpage is open it will ask for run that exe.
How to do that ?
If I am writting window.open("EXE PATH"); in javascript. then at other side dialog box of open, save , cancel is coming. When I am trying to open it. Its giving error like "EXE name. has encountered a problemm and need to close....."
Whats problem here ?
Thanks,
Sun Rays
|
|
|
|
|
Thankfully, what you want to do, you can't do. Imagine how many viruses you'd have running wild on your PC, if you could.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: Thankfully, what you want to do, you can't do
Of course you can. You can have a hyperlink to an EXE file and the browser will ask if you want to "run/save" the file. This is the behaviour the OP described its just that his EXE is crashing as it runs.
|
|
|
|
|
Hi,
Thanks for your reply.
But I dont want to ask user to save or open the exe.
I just wanna run it on machine,
Thanks
Thanks,
Sun Rays
|
|
|
|
|
Sun Rays wrote: When ever my web application's webpage is open it will ask for run that exe.
Exactly. You can't ever start an application from the browser without the user having to allow it. Any solution means that there is user confirmation at some point.
Sun Rays wrote: Its giving error like "EXE name. has encountered a problemm and need to close....."
That means that your program is faulty, and has crashed.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
.NET exe? Assembly trusted?
|
|
|
|
|
Hi
I am working on a desktop application using C# and .NET 2.0.
In my DataSet I have two tables say table1 and table2. They have one to many relation (no rule is set like for update, delete or accepct/reject changes). When I drop a binding source for the parent table i.e table1 on the windows forms, I get another binding source for child i.e table2BindingSource1 after rebuilding the project. That is really helpful because when I set
//this.BindingNavigator1.BindingSource = table1BindingSource;
The self created BindingSource collaborates with the navigator itself and I need not to do any extra coding.
Now the problem is when I do
//this.BindingNavigator1.BindingSource.CancelEdit();
to cancel any changes made to DataSet in case user clicks Delete button one the Navigator.
This only works for the parent table i.e table1 and not for the child table or say for self created BindingSource.
I have tried
//this.BindingNavigator1.BindingSource[1]....//Here i cannot find any method to remove changes made to data set.
How can I apply this CancelEdit for both the tables in the DataSet ( for both BindingSources ).
Can anybody help me out? It is really urgent......
thnx in advance.
|
|
|
|
|
This is your third post on the same subject. as i replied to the email you sent to me i will try to help you when i find time, if it indeed is really urgent pay someone to do it. Or wait until your first post is answered.
If it' stuck, DO NOT pull harder!
|
|
|
|
|
well i m sorry. i was just increasing the chances of my problem being seen. i will be careful next time.
thnx
|
|
|
|
|
and decreasing others chances of having their problems seen.
but i'll stop ranting about it now.
i tried a few tests and didnt get any behaviour like you described, though i've never used the binding* stuff, so i guess my help is limited here. i prefer to code my own data layer and the logic in there.
If it' stuck, DO NOT pull harder!
|
|
|
|
|
Hi
I have a problem once again. The situation is
//this.BindingNavigator1.BindingSource.CancelEdit();
works to cancel AddNewItem()
but it does not work when to cancel a DeleteItem().
Do i need to do something else?
Please Help me out.
|
|
|
|