473,804 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GDIplus :: Resizing an Image

Airslash
221 New Member
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.

Expand|Select|Wrap|Line Numbers
  1.     // Prepare GDIplus
  2.     Gdiplus::GdiplusStartupInput gdiplusStartupInput;
  3.     ULONG_PTR gdiplusToken;
  4.     Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, 0);
  5.  
  6.     // Prepare the the variables that we are going to need:
  7.     time_t startpoint, endpoint, point;
  8.     Progress->Min = 0;
  9.     Progress->Max = 999;
  10.     Progress->Position = 0;
  11.     double counter = 0;
  12.  
  13.  
  14.     // Tell the user what this benchmark entails
  15.     ShowMessage("This benchmark will compress 1 image 1000 times and write it to disk 1000 times using GDI+.");
  16.  
  17.     // load the image from the disk
  18.     Gdiplus::Bitmap* original;
  19.     ::LPWSTR name = "C:/test.jpg";
  20.     original->FromFile(name);
  21.  
  22.     // Start the loop and set our start time:
  23.     startpoint = clock();
  24.     for(int i = 0; i < 1000; ++i)
  25.     {
  26.         // Set our start point
  27.         point = clock();
  28.  
  29.         // Create a new bitmap
  30.         Gdiplus::Bitmap *resized = new Gdiplus::Bitmap(640, 480);
  31.  
  32.         // Create a new Graphics
  33.         Gdiplus::Graphics *g;
  34.         g->FromImage(resized);
  35.  
  36.         // Set the Interpolationmode
  37.         g->SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
  38.  
  39.         // Redraw our image
  40.         g->DrawImage(original, 0, 0, 0, 0, original->GetWidth(), original->GetHeight(), Gdiplus::UnitPixel);
  41.         counter += difftime(clock(), point);
  42.  
  43.         // Cleanup our mess
  44.         delete resized;
  45.  
  46.         // Increment Progress bar and display cpu load
  47.         Progress->StepBy(1);
  48.  
  49.         // process messages
  50.         Application->ProcessMessages();
  51.     }
  52.     // fetch our endtime
  53.     endpoint = clock();
  54.  
  55.     // Display the result:
  56.     LOG->Items->Add("GDI+ took about " + FloatToStr(difftime(endpoint, startpoint) / 1000) + " seconds.");
  57.     LOG->Items->Add("GDI+ :: average copy time = " + FloatToStr(counter / 1000) + " ms.");
  58.  
  59.     // delete pointer
  60.     delete original;
  61.  
  62.     // Stop Gdiplus
  63.     Gdiplus::GdiplusShutdown(gdiplusToken);
  64.  
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
Dec 7 '09 #1
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
Dec 8 '09 #2
Airslash
221 New Member
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.
Dec 8 '09 #3
RRick
463 Recognized Expert Contributor
Was line 33 part of the problem?
Dec 8 '09 #4
Airslash
221 New Member
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.
Dec 8 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
4411
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...
4
3273
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
6
1931
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.
10
4165
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...
1
9515
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...
3
1319
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!
0
2221
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...
1
1226
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.
0
9714
marktang
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...
0
10599
Oralloy
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...
0
10346
jinu1996
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...
1
10347
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,...
0
9173
agi2029
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...
0
6863
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();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.