Hello,
been a while since I visited bytes.com, but I have an issue with GDIplus...
I'm currently developing on/for a Windows Server 2003 system and I'm running a Benchmark to find the fastest and most performent way of resizing a jpg file from MegaPixel format to 640 * 480 size.
Gdiplus currently offers the fastest way for me with a result of 3ms / resize.
I am however recieving random Access Violations exceptions and the small tool sometimes uses up to 2GB of ram when running.
I've had serious issues getting Gdiplus to work to the point it is now, but I have no clue whats causing the problem. It usually happens on the SetInterpolatio n function of a Graphic. -
// Prepare GDIplus
-
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
-
ULONG_PTR gdiplusToken;
-
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, 0);
-
-
// Prepare the the variables that we are going to need:
-
time_t startpoint, endpoint, point;
-
Progress->Min = 0;
-
Progress->Max = 999;
-
Progress->Position = 0;
-
double counter = 0;
-
-
-
// Tell the user what this benchmark entails
-
ShowMessage("This benchmark will compress 1 image 1000 times and write it to disk 1000 times using GDI+.");
-
-
// load the image from the disk
-
Gdiplus::Bitmap* original;
-
::LPWSTR name = "C:/test.jpg";
-
original->FromFile(name);
-
-
// Start the loop and set our start time:
-
startpoint = clock();
-
for(int i = 0; i < 1000; ++i)
-
{
-
// Set our start point
-
point = clock();
-
-
// Create a new bitmap
-
Gdiplus::Bitmap *resized = new Gdiplus::Bitmap(640, 480);
-
-
// Create a new Graphics
-
Gdiplus::Graphics *g;
-
g->FromImage(resized);
-
-
// Set the Interpolationmode
-
g->SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
-
-
// Redraw our image
-
g->DrawImage(original, 0, 0, 0, 0, original->GetWidth(), original->GetHeight(), Gdiplus::UnitPixel);
-
counter += difftime(clock(), point);
-
-
// Cleanup our mess
-
delete resized;
-
-
// Increment Progress bar and display cpu load
-
Progress->StepBy(1);
-
-
// process messages
-
Application->ProcessMessages();
-
}
-
// fetch our endtime
-
endpoint = clock();
-
-
// Display the result:
-
LOG->Items->Add("GDI+ took about " + FloatToStr(difftime(endpoint, startpoint) / 1000) + " seconds.");
-
LOG->Items->Add("GDI+ :: average copy time = " + FloatToStr(counter / 1000) + " ms.");
-
-
// delete pointer
-
delete original;
-
-
// Stop Gdiplus
-
Gdiplus::GdiplusShutdown(gdiplusToken);
-
Above code is the Benchmark2 function zhich resizes an image 1000 times to calculate the time.
I'm also developing with Borland in Rad Studio 2007
4 13991 RRick 463
Recognized Expert Contributor
First of all the pointer at line 33 is not initialized. This looks like its pointing to almost anywhere and I'm surprised it works at all.
The microsoft web site has some examples of resizing images. This might be a faster way to make the conversion. Take a look at this link: http://msdn.microsoft.com/en-us/libr...86(VS.85).aspx
cheers,
I've got a working version at the moment and using ScaleTransform to resize the images I need.
Currently needs up to 120ms to resize an image from 3Mpixel size to 640x480 with decent quality.
I'll take a peek at the link you provided as well.
RRick 463
Recognized Expert Contributor
Was line 33 part of the problem?
No, strangely enough that line worked perfectly, although I have changed it into something more safe.
The problem was that GDI+ was unable to find certain identifiers. Solved it by changing the order of #include statements.
So all works at the moment, now its time for optimalization.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Colin Young |
last post by:
I'm trying to rezive an image using the GetThumbnailImage method, and I'm
having some trouble with the GetThumbNailImageAbort delegate. It seems my
system doesn't think that
System.Drawing.Image.GetThumbNailImageAbort exists.
Any ideas? I think I've been staring at the computer for too long and I'm
missing something obvious because there's nothing in Google about other
people having this problem, and I know I've had this sort of code...
|
by: James A Taber |
last post by:
Problem resizing image.(JPG)
If i try to resize an img with horisontal=150 and vertical resolution=150
The quality of the target image is dramatically reduced. Source code is
provided below.
How can i solve this? What am i doing wrong?
Thanx in advance
-James A Taber
|
by: neverstill |
last post by:
hi-
So I wrote this nice little page that will allow the managers to add images
to the products table. Without too many details to confuse everything,
basically what I'm doing is:
getting an Image
from there I'm creating a new Bitmap(Image, int w, int h);
then I'm saving that bitmap various encoder quality values.
|
by: David W. Simmonds |
last post by:
I have a DataList control that has an Image control in the ItemTemplate. I
would like to resize the image that goes into that control. I have a series
of jpg files that are full size, full resolution (ie. large). I have a
database that contains references to the pictures. Currently I have to
resize the jpgs manually, and then point the ImageUrl property at that jpg
using databinding. This works fine. I would like to avoid the resizing step...
|
by: Brian |
last post by:
Using A2K I have an image control on a report and use code to set the
image.picture to the required jpg. 3 of the jpgs resize properly but
2 do not - they display much smaller than the image control. The
problem jpgs were originally created as line drawings in Word. They
were then copy and pasted to Paint where they were saved as jpg files.
Sizemode is set to stretch.(have tried clip and zoom but no better). I
cannot find any way to...
| |
by: roN |
last post by:
Hi,
if you go to http://www.dvdnowkiosks.com/new/faq.php you can see that if you
click on one of the FAQs, it's extending them and making the image on the
right-hand side being too short. Is there a possibility that i can get by
how many pixels it got extended and resize my image on the right-hand side?
Thanks for suggestions!
|
by: Saaima |
last post by:
Hi All
when I store a picture of size 800*600 pixels in database (SqlServer)
field Photo (Image) and load it into crystal report through query by dragging and dropping
the field on report it appears well but as its size is too large and when i resize it its
resolution become so wrong to can not see image. such as in Employee photo in Employee record
Actually i need a passport size photo on report. So i save a picture of this size and get...
|
by: gomzi |
last post by:
hi,
I would like to know as to which class I could use if I want to resize an image for a medium trust environment?
I am currently using the getthumbnailimage property of the system.drawing.image object to achieve the result, but unfortunately it doesn't work in a medium trust environment.
Any help would be appreciated.
Thanks,
gomzi.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |