Results 1 to 2 of 2

Thread: Application crash when saving the image

  1. #1
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Application crash when saving the image

    Hi there. I keep receiving application crash when saving an image (line 44). But the problem is that it appears every now and then. May you have a look at the snippet? Thank you so much.

    Qt Code:
    1. void MainWindow::algorithm(QString image_name)
    2. {
    3.  
    4. int counter = 0;
    5.  
    6. QImage initial_image_tmp(image_name);
    7. int height_of_image = initial_image_tmp.height();
    8. initial_image_tmp.~QImage();
    9.  
    10. double NDN = 889000;//should be defined
    11. double height = 830000;//should be defined
    12. //int height_of_image = 2384;
    13. int delta_r = 240; // should be defined
    14. //----------------------------------------//
    15.  
    16. double NDK = NDN + delta_r * height_of_image;// estimate far slant distance
    17. double delta_R = NDK - NDN; // estimate pixel slant range step
    18.  
    19. std::vector<double> slant_initial_vec;// define initial slant range vector
    20.  
    21. double near_horiz_distance, far_horiz_distance, L_spheric;//define horizontal distances
    22.  
    23. slant2range(NDN, height, near_horiz_distance);// slant to range distance convertion (near)
    24. slant2range(NDK, height, far_horiz_distance);// slant to range distance convertion(far)
    25.  
    26. L_spheric = far_horiz_distance - near_horiz_distance;//define arc length which
    27. //corresponds to slant range
    28.  
    29. double size_tmp = L_spheric / delta_r;//define step at horiaontal range
    30. int size_of_output_array = (int)ceil(size_tmp);//compute size of output array (new image height)
    31.  
    32. for (int i = 0; i < height_of_image; i++) slant_initial_vec.push_back(NDN + delta_r * i);//fill in initial slant vector
    33.  
    34. std::vector<double> slant_vec;//horiaontal distances vector
    35.  
    36. for (int i = 0; i < size_of_output_array; i++)//fill in resampled slant vector
    37. {
    38. double tmp_horiz = near_horiz_distance + i * delta_r;
    39. double tmp_slant;
    40. range2slant(tmp_horiz, height, tmp_slant);
    41.  
    42. //-----------------------------------------//
    43. int counter = 100 * i /size_of_output_array;
    44. emit signal_update(counter);
    45. //-----------------------------------------//
    46.  
    47. slant_vec.push_back(tmp_slant);
    48. }
    49.  
    50. counter = 0;
    51.  
    52. std::vector<int> indexes_lower, indexes_higher;//define indexes and delta vectors
    53. std::vector<double> delta_s;
    54.  
    55. for (int i = 0; i < size_of_output_array; i++)
    56. {
    57. double out_slant_range, in_slant_range;
    58.  
    59. out_slant_range = slant_vec[i];
    60. std::vector<double>::iterator range_iterator =
    61. std::lower_bound
    62. (slant_initial_vec.begin(),
    63. slant_initial_vec.end(),
    64. out_slant_range);
    65. in_slant_range = *range_iterator;
    66.  
    67. int val = (int)(range_iterator - slant_initial_vec.begin());
    68. delta_s.push_back((out_slant_range - in_slant_range)/delta_r);
    69. indexes_lower.push_back(val);
    70. if (val >=height_of_image) indexes_higher.push_back(val);
    71. else indexes_higher.push_back(val + 1);
    72.  
    73. int counter = 100 * i /size_of_output_array;
    74. emit signal_update(counter);
    75. }
    76.  
    77. counter = 0;
    78.  
    79. //----start processing-----------------------------//
    80. QImage initial_image(image_name);
    81. QString bmp_name = image_name + ".bmp";
    82. QImage initial_bmp = initial_image.copy(0,0, initial_image.width(), initial_image.height());
    83. initial_bmp.save(bmp_name);
    84.  
    85. int initial_width = initial_image.width();
    86. int initial_height = initial_image.height();
    87.  
    88. initial_image.~QImage();
    89. initial_bmp.~QImage();
    90.  
    91. QImage image_resampled(initial_width, size_of_output_array, QImage::Format_ARGB32);
    92. image_resampled.fill(0);
    93. QString name_of_output_jpg = image_name + "_resampled.jpg";
    94. std::vector<double>
    95. input_green_vector,
    96. input_red_vector,
    97. input_blue_vector;
    98.  
    99. //--------------------------//
    100.  
    101. QImage tmp_bmp_image(bmp_name);
    102.  
    103. //--------------------------//
    104.  
    105. QRgb output_rgb_value;
    106.  
    107. for (int j = 0;
    108. j < initial_width;
    109. j++)
    110. {
    111. get_current_column(//bmp_name,
    112. tmp_bmp_image,
    113. j,
    114. input_red_vector,
    115. input_green_vector,
    116. input_blue_vector);
    117.  
    118. for (int i = 0; i < size_of_output_array; i++)
    119. {
    120. double val_green = input_green_vector[indexes_lower[i]] *
    121. (1- abs(delta_s[i])) +
    122. input_green_vector[indexes_higher[i]] * abs(delta_s[i]);
    123.  
    124. double val_red = input_red_vector[indexes_lower[i]] *
    125. (1- abs(delta_s[i])) +
    126. input_red_vector[indexes_higher[i]] * abs(delta_s[i]);
    127.  
    128. double val_blue = input_blue_vector[indexes_lower[i]] *
    129. (1- abs(delta_s[i])) +
    130. input_blue_vector[indexes_higher[i]] * abs(delta_s[i]);
    131.  
    132. //output_green_vector.push_back(val_green);
    133. //output_red_vector.push_back(val_red);
    134. //output_blue_vector.push_back(val_blue);
    135.  
    136. output_rgb_value = qRgb(val_red, val_green, val_blue);
    137.  
    138. image_resampled.setPixel(j, i, output_rgb_value);
    139. }
    140. int counter = 100 * j /initial_width;
    141. emit signal_update(counter);
    142. }
    143.  
    144. image_resampled.save(name_of_output_jpg);//save the image
    145.  
    146. emit end_of_calculating();
    147.  
    148. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Application crash when saving the image

    Solved. I deleted all explicitly used destructors and it worked just fine.

Similar Threads

  1. Replies: 2
    Last Post: 21st August 2009, 23:09
  2. Problem saving JPG image
    By avis_phoenix in forum Newbie
    Replies: 1
    Last Post: 31st July 2009, 15:38
  3. Saving qwt plot as image
    By giusepped in forum Qwt
    Replies: 13
    Last Post: 14th July 2009, 07:39
  4. Regarding saving of image in QTOPIA sdk
    By prajna in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 22nd April 2009, 06:45
  5. Saving already opened image ...
    By Godlike in forum Newbie
    Replies: 14
    Last Post: 28th March 2006, 21:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.