Is there any way to avoid a huge memory spike when using CGContextDrawImage for a high resolution image?

Hi,
I'm trying to fix the orientation of an UIImage in my app (iPad 2, iOS 7). I'm using the method described here: https://gist.github.com/alex-cellcity/1531596, but a huge memory spike appears when CGContextDrawImage is called. The image size I'm trying to fix is 2848x4288.
Anybody knows any algorithm to avoid this huge spike?
Thanks,
Roberto.

While I never done iOS code it appears that the code you link to basically does the following:
takes a large image A
generates a transformation matrix by doing rotation in 90 degree increments and by mirroring
creates a large image B
draws image A into B using the transformation matrix
releases memory for image A
goes on using image B
This results in a memory peak as you have two large images in RAM, until image A gets deallocated, which can't be done until B has been drawn.
I can see two possible solutions to this, both which probably require you to explicitly modify individual pixels:
1) Try to simplify the solution - if 180 degree rotation and mirroring is enough to solve your image issues, then a simple in-place (same bitmap) pixel swap could be done.
2) Find more memory -  if you need 90, 270 or arbitrary degrees of rotation as well, you could instead keep either image A or B on disc.
Keep image A on disc: read pixels from disc and place appropriately in image B. This may require you to first load image A and write it back to disc as ARGB data (one byte for each color) for easy access.
Keep image B on disc: get pixel from image A and place it at the right location in image (file) B - this will require pre-creating a file of the correct size for Bs ARGB data and then moving the insertion point for writing around. When done dealloc image A and load image B.
Keep image A and B on disc: combine using disc for image A and B - this will minimize RAM usage but will probably be the slowest solution and will increases disc (SSD/flash) load and wear.

Similar Messages

  • Is there any way to avoid stop/start of tomcat when a java file is modified

    Hi all,
    we are developing a tool where we use java files for mediation layer and jsp files for presentation layer. so whenever i do a change in any of my java source i need to stop/start the tomcat in order to get the latest change.
    is there any way to avoid this kind of stop/start.... i want the changes to get reflected immediately after i compile the file.

    hai ,
    i wrote a sample test.jsp and TestJava.java file and i tried callin api getValue() in TestJava.java from test.jsp.then i did some modifications to this api i.e., i changed the return type from String to int . then compiled n also touched the file but the changes didn't get reflected instead i got the followin error.
    Location: /support/jsp/test.jsp
    Internal Servlet Error:
    javax.servlet.ServletException: com.adventnet.itm.common.TestJava: method getValue()I not found
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:508)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
         at org.apache.tomcat.core.Handler.service(Handler.java:287)
         at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:806)
         at org.apache.tomcat.core.ContextManager.service(ContextManager.java:752)
         at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
         at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
         at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
         at java.lang.Thread.run(Thread.java:475)
    Root cause:
    java.lang.NoSuchMethodError: com.adventnet.itm.common.TestJava: method getValue()I not found
         at jsp._0002fjsp_0002ftest_0002ejsptest_jsp_3._jspService(_0002fjsp_0002ftest_0002ejsptest_jsp_3.java:63)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
         at org.apache.tomcat.core.Handler.service(Handler.java:287)
         at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:806)
         at org.apache.tomcat.core.ContextManager.service(ContextManager.java:752)
         at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
         at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
         at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
         at java.lang.Thread.run(Thread.java:475)
    kindly help me ASAP.......
    Tanxxx in advance,
    Ani

  • Is there any way to activate the keep identity setting when using a Transfer SQL Server Object Task?

    Is there any way to add the "Keep Identity" option to the tables selected for transfer in a Transfer SQL Server Object Task?  It seems that would be very useful, yet I can't find an easily available setting for it.  I would prefer to
    accomplish this within the Transfer SQL Server Object Task since it can copy any new fields added to the source tables, as opposed to having to rebuild a custom Data Flow Task any time a table structure is altered.  I thought setting "CopyPrimaryKeys"
    to True would do the trick, but I found that only ensures that the column settings are transferred; when the transfer happens, the destination id column is populated based on the specified seed and increment value, not what's actually in the source table. 
    I'd like to point out that replication isn't really an option here. This is a package that runs a few times a day to keep some data on our website up to date with data in our protected corporate environment.

    IIRW there is FastLoadKeepIdentity specifies
    whether to keep an identity in OLEDB destination 
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Create an iPod or iphone version - is there any way to avoid duplicate files OR automating a new name for the new file?

    hi,
    I have two devices for my videos. An ipod classic and an Ipad. I would prefer to keep the highest resolution possible but also will be travelling and it will be useful to have a large archive with me.
    I have found that many of the videos I have are "incompatible" with my ipod classic and am in the process of using the "create an ipod or iphone version" but this results in a duplicate file in my itunes library that is identical in everyway (except size and this can be bigger or smaller).
    When you buy a HD video off itunes, you get both versions but only one file populates in the itunes libary.
    Is there anyway that when itunes "creates the ipod or iphone version", it can do automatically merge these two files so you only see one file in your library? And then it will automatically sync the appropriate file with the appropriate device?
    Or is there a way to have itunes "create the ipod or iphone version" and have it automatically label it with the name "XXX (ipod version"?
    I am finding it very annoying to manually change all the titles on all the files being created.
    thanks, margaret

    When you open a Word document with Pages you get a translated-to-Pages file & the original Word document is unchanged. There are programs that will save over the original file such as LibreOffice. Pages will not.

  • Is there any way to put a book on itunes and sell it for a higher price than the pricing tiers?

    I am selling my medical textbooks on paper for around $90-100.  When I was in the process of loading the epubs into itunes connect, the pricing tier maxed out at 39.99.  I sell other books in my field selling on itunes for around $180, which is similar to the paper versions.  Is there a way around the pricing tiers.  I have no problem with creating a new title if necessary.
    Thanks

    Correction to first post
    I am selling my medical textbooks on paper for around $90-100. When I was in the process of loading the epubs into itunes connect, the pricing tier maxed out at 39.99. I see other books in my field selling on itunes for around $180, which is similar to the paper versions. Is there a way around the pricing tiers. I have no problem with creating a new title if necessary.
    Thanks

  • HT4137 Will doing this erase old text messages?  If so, is there any way to avoid losing them?

    I just looked read iOS: How to back up your data and set up as a new device.  I've been having a few bugs, but do not want to lose my old text messages.  Will setting up as a new device and then syncing erase old text messages?  If so, is there any way to avoid losing them?

    You will not lose text message, if you back up your phone correctly and then restore from that backup.  If your going to restore your phone as new and not from backup, then your text will not be there until you decide to restore from that backup.
    If you don't want to lose the message, take a look in the app store to see if you can transfer to your computer.

  • I just planned to install windows 7 on my MBP Mid-2012 using VMware Fusion,so i am bit panic about viruses and malware's affecting through vmware,is there any way to avoid from this??

    i just planned to install windows 7 on my MBP Mid-2012 using VMware Fusion,so i am bit panic about viruses and malware's affecting through vmware,is there any way to avoid from this??

    usamasheikh wrote:
    virus protection in vmware or on my running OS X 10.8.2??plz help me out
    First, you can install Microsoft's Security Essentials in the Win 7 VM and keep it up-to-date. Second, you can turn off Sharing in Fusion's System Settings to keep the VM environment separate from your Mac. Third, you can look into Sophos Anti-Virus http://www.sophos.com/en-us/products/free-tools/sophos-antivirus-for-mac-home-ed ition/download.aspx for the Mac host.

  • HT1766 When I have iCloud Backup ON, the battery runs down on my iphone really quickly.  Is there any way of avoiding this ?  Thanks

    When I have iCloud Backup ON, the battery runs down on my iphone really really quickly.  Is there any way of avoiding this.  I want to backup my iphone but don't want to be recharging all day.  Many thanks

    Are you sure the iCloud backup is causing this?  Unless you initiate an iCloud backup manually, it will only back up once per day when the phone is connected to your charger and wi-fi and has the screen locked.  It shouldn't otherwise be consuming any power.

  • Is there any way programmatically to disable the screen shot capture using Home   power button in the iPad device?

    Hi Team,
    Is there any way programmatically to disable the screen shot capture using Home + power button in the iPad device.We need to avoid the screen capture option due to security reason.
    thanks ,
    Bala

    Hi Peace, Clyde,
      Thanks for information. Using the API  UIApplicationUserDidTakeScreenhotNotification (iOS7)  send the notification after the screenshot taken.  Using this api is it possible to block the screen shot caputure option.
    Thanks and Regards,
    Bala

  • Is there any way to export IT Resource data from OIM using the export tool?

    Hello,
    we are trying to migrate an OIM development environment to a preproduction environment and we need to migrate more than 400 IT Resources. We have exported some IT Resources and when we imported them in the preproduction environment their data was not migrated. Is there any way to export IT Resource data from OIM using the export tool? Or is there any other way to do this without doing it by hand?
    Thank you for your help
    Kind Regards

    Well , OIM doesnot provide any such facility to export ITResource data along with ITResource .
    Directly updating the DB could be an option ..
    Thanks

  • Is there any way to get rid of this stupid feature in iTunes for Windows? You've subscribed to a podcast but have more than five unplayed episodes. iTunes will stop automatically downloading newer episodes.

    s there any way to get rid of this stupid feature in iTunes for Windows?
    You've subscribed to a podcast but have more than five unplayed episodes. iTunes will stop automatically downloading newer episodes. You may get the following message: 
    iTunes has stopped updating this podcast because you have not listened to any episodes recently. Would you like to resume updating this podcast?
    You can click Yes to continue downloading additional episodes. Or you can just listen to any part of any episode and a new episode will download at the next update.

    I believe that feature was added in order to reduce wasted costs to the Podcaster.
    Podcasts incur costs - that have to be paid for, by someone. That cost will be the cost of hosting the Podcast on a server somewhere and more crucially (with regard to your point), the cost of the Podcast being downloaded to your computer. Every download costs the Podcaster money (typically, charged by bytes downloaded).
    If that Podcaster pays for the whole thing personally, obviously they want to keep down any unnecessary cost to themselves. If the Podcaster is earning money for his or her Podcast (typically from advertising within the programme) then obviously, the advertiser only wants to pay for advertisements heard by listeners. So a download, not heard by the downloader, is waste of the Podcaster's money or no payment from the advertiser.
    My own experience is that I only have to resume downloading once per programme. I'm usually several episodes behind on two different Podcasts that I follow, but I do not recall having to repeat the resume Podcast after that first time.

  • My Old macbook pro that i bought in 2009. I have broke my screen and havent used it for a while, and now i have found out that i can use a monitor , but i have forgot my password is there any way i can make a new password? Thank you for reading this.

    My Old macbook pro that i bought in 2009. I have broke my screen and havent used it for a while, and now i have found out that i can use a monitor , but i have forgot my password is there any way i can make a new password? Thank you for reading this.

    Have you read for possible solutions over in the "More Like This" thread over here?-----------------------> 
     

  • Is there any way I can have a box sent to my house for my broken iPhone...with out calling?

    Is there any way I can have a box sent to my house for my broken iPhone...with out calling? Preferably online.

    You could try your nearest Genius Bar; in order to decide whether or not a repair/replacement is necessary, a human being would have to troubleshoot and assess the situation by talking to you.

  • HT1665 Hello. Is there any way of finding a list of accessories which hold "made for iPhone" certification?

    Hello. There are a lot of new accessories available for iPhone 5 and iPhone 4 / 4S. Is there any way of finding a list of accessories which hold "made for iPhone" certification? I do not want to buy any accesories which may be harmful for my iPhone.

    Here is the start of the setup:
    Click on the Wi-Fi Options button and provide the needed info:
    Click on the OK button. Now check the Internet Sharing box to turn it all on. If the port box you checked is no longer checked, then uncheck Internet Sharing, check the port box again, then check the Internet Sharing box again.

  • Is there any way i can read Amharic or Geez fonts using my iPhone?

    is there any way i can read Amharic or Geez fonts using my iPhone?

    No, but you can ask apple to add this via
    Http://www.apple.com/feedback

Maybe you are looking for