Colorizing a constantly changing image - how to release this properly?

Hello- I have done some searching on google and various forums but can't find a good answer for this. Hoping someone here can help. I'm assuming there has got to be a simple solution that I'm overlooking, but I've spent countless hours messing around with this and always get back to the same results....
I am using a custom UIView to take a snapshot of the current view and tint it with a color.
The tricky part is that the image changes every half second, whereas most people trying to do this out there are using static images from what I've seen.
The code performs the task correctly except that it continually allocates until memory runs out.
I have tried creating the custom UIView programmatically then as a property that I released, then I tried using IB ( and various combinations) in an attempt to stop the allocating... can't seem to stop it. Currently defined in IB and declared as a property.. released in -dealloc....
I have also tried using a separate image property and drawing or setting background to that in the custom view but to no avail.
If I comment out the line where I change the background image, no memory problems.....
Here's what I'm currently doing in the superview... the blendView object is sized and laid out in IB:
(code has been simplified for example purposes, and I've left in some commented out code showing other things I've tried)
TintView.h:
#import <UIKit/UIKit.h>
@class BlendView;
@interface TintView : UIView {
IBOutlet BlendView *blendView;
@property (nonatomic,retain) IBOutlet BlendView *blendView;
TintView.m
#import <QuartzCore/QuartzCore.h>
@implementation TintView
@synthesize blendView;
- (void) blendTheView { // gets called every half second as the image gets updated
blendView.hidden = YES; //hide blendView so we can make a new one
blendView.theColor = [UIColor colorRed];
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
blendView.backgroundColor = [UIColor colorWithPatternImage:UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
blendView.hidden = NO;
- (void)dealloc {
[blendView release];
[super dealloc];
And here's the definition of the class:
BlendView.h:
#import <UIKit/UIKit.h>
@interface BlendView : UIView {
UIColor *theColor;
@property (nonatomic, readwrite, retain) UIColor *theColor;
@end
BlendView.m:
#import "BlendView.h"
#import "TintView.h"
@implementation BlendView
@synthesize theColor;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
theColor = [UIColor redColor];
return self;
- (void)drawRect:(CGRect)rect {
//self.backgroundColor = [UIColor colorWithPatternImage:theImage]; // works, but allocs infinitely. just like when assigned from super view
//[theImage drawInRect:rect]; // makes a distorted image (too short and too wide) - also doesn't update the image each time
//CG Method:: :::: (works, but more code than the UI method)
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetBlendMode (context, kCGBlendModeMultiply);
CGContextSetFillColor(context, CGColorGetComponents(theColor.CGColor));
CGContextFillRect (context, rect);
CGContextRestoreGState(context);
// UI Method:: ::: (seems to work just as good as the CG method above)
[theColor set];
UIRectFillUsingBlendMode(self.bounds, kCGBlendModeMultiply);
- (void)dealloc {
[super dealloc];
@end

Well, after countless hours of experimenting with allocs and releases I have determined that there must be a hidden alloc that you just can't do anything about whenever you set a UIView's background color to a pattern image.. even if you release the UIView..... oh well....
Funny thing is, upon re-visiting some earlier code you'll see commented out, I got it to work with no problems.
If anyone is curious, I went back to declaring a UIImage property, "theImage" in my BlendView class
I pass the snapshot to the image property and in the -drawRect method I went back to using the line:
[theImage drawInRect:rect];
I don't know why it was distorting and remaining static for updates when I first tried this line out, but it is now working perfectly with no extra allocs

Similar Messages

  • HT201269 In Iphone5 while Mail is reviewed and transfered to folder, for next mail folder list position changes. How to fix this error

    In Iphone5 while Mail is reviewed and transfered to folder, for next mail folder list position changes. How to fix this error

    In Iphone5 while Mail is reviewed and transfered to folder, for next mail folder list position changes. How to fix this error

  • Constantly changing image on iChat - and the word 'stamina' appears?

    I just moved my G4 to another room. Now when I iChat with a friend, he/she sees the word 'stamina' on my screen and then the image constantly changes - to a blue border, to the purple theater curtains etc etc.
    I am completely baffled. Can anyone tell me how to get iChat to work normally please?

    Hi Bronxal,
    1) I have a Graphics Pad which makes Writing in some apps easier.
    2) The Sig was written and then coloured and shadowed in Photoshop Elements 2
    3) further tweaks to remove any background artifacts and get it as shown.
    4) Uploaded to a site such as Flickr or PhotoBucket.
    5) HTML Code to post it here.
    The code is the Image tag <img src="URL of pic">
    7:47 PM Wednesday; January 17, 2007

  • I have a MacBook Pro. I was gone for 30 days and when I got back it tells me that my startup disk is full. I have a 500 GB drive and it shows that I have about 500 MB available. It constantly changes.  How do I fix this?

    I have a MacBook Pro that is telling me my startup disk is full. I left for 30 days and when I came back to use it, it tells me that the disk was full out of 500 GB. I don't have that much on it and it was perfectly fine when I left.  I Verified the disk through disk utility and it told me it had issues so then I repaired it and it said everything is fine. It still says the hard drive is full. How do I fix this problem. Any help is greatly appreciated.

    Have a read here Where did my Disk Space go?
    Stefan

  • After installing OS X ML, Photoshop CS4 crashes constantly, any clue how to fix this or why it is happening?

    I downloaded and installed OS X Mountain Lion last night and everything was working normally. I started working in Photoshop CS4 this morning (the first time after installing ML) and when I try to drag a layer to create a new layer, or when I try to move a layer to another PS document, it shows the beach ball of death and then crashes. It has crashed on other occasions, not just doing these actions. Before installing ML I haven't really ever had a problem with PS crashing. I reinstalled PS earlier today to see if that would help but it still crashes. Any ideas on why this is happening or how I can fix it?
    Thanks for any replies, in advance.

    While CS4 is getting a bit old in the tooth now, Adobe says there are no known issues as of the 25th !
    Adobe CS apps & Mountain Lion: No known issues
    http://blogs.adobe.com/jnack/2012/07/adobe-cs-apps-mountain-lion-no-known-issues .html
    BUT that comment thread there is a bit long ->
    If you encounter any issues, please report them on our bug reporting form.
    OR:
    FAQ: I found a bug. How do I write a useful bug report? Or send bug files to Adobe?
    http://forums.adobe.com/message/4209010#4209010

  • My iPod touch camera is black and then when it takes a photo color shows does anyone know how to fix this

    I have been going to settings and everything and tons of youtube videos and my ipod is bend new which I'm getting at the edge

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up           
    - Restore to factory settings/new iOS device.
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar          

  • How to release document

    Dear All,
    I am very new to SAP-PLM.
    In DMS, i have created one document  but its status shows "Not Released".
    How to release this document?
    My second question is,
    I have created 2 versions of documents,
    how to list all  versions for document?
    Thanks

    Hello,
    If you do any changes for your DIR then system will ask for status change of your DIR.
    In transaction CV04N you can keen DIR number to provide list of virsions of it.
    -Thanks,
    Ajay

  • How to release a collective production order in CO05N with MSPT?

    The issue was: I want to release a collective order by co05n, e.g. the structure of this collective production order 10000 like this:
    10000----20000
    30000---40000
                                 ---50000
    if order 50000 with material shortage, keep the customizing OPJK  release order=3, how to release this collective
    order. If it is not possible in standard, can the parallel order 40000 be released??
    Thank you, all.
    Edited by: Stephen Wang on Apr 15, 2010 3:12 PM

    Dear,
    In Transaction CO05N, you execute a collective release. For one of the orders, the availability check determines missing part although it has been set in Customizing of the availability check (OPJK) that a release can be executed for missing part per user decision. Therefore, a dialog box is processed on which options a.) 'Release order', b.) 'Missing parts list' and c.) 'Cancel' are displayed.
    If you first branch to the missing parts list and then press 'Cancel' on the dialog box there it self
    Else you can do this with these options,
    1)Use T Code COHVOMRELEASE here select order as you want and release accordingly.
    2) Use Transaction SE38 to create the variants for program PPIO_ENTRY and schedule it through SM36 or use standard variant as SAP&RELEASE if want in background.
    3) use BAPI BAPI_PRODORD_RELEASE
    Please try and come back.
    Regards,
    R.Brahmankar

  • How to Release jstring (C++ dll calls Java)

    I'm trying to call a method from a Dll (written in C++) to Java. Pseudo might look like this
    String cstr = "abcdefghijklmnopqrstuvwxyz";
    jstring jstr = NewStringUTF(cstr);
    CallJavaMethod(classid, methodid, jstr);
    // so problem is how to release this jstr because it is causing memory leaksI've tried DeleteLocalRef and ReleaseStringUTFChars(jstr, cstr) but they don't work and Memory keeps on increasing.
    Can anybody suggest a solution plz

    ...but they don't work and Memory keeps on increasing.
    Can anybody suggest a solution.Looking at the rest of your code too?
    You might also want to examine the assumption that you are making when you say "Memory keeps on increasing". Java can keep allocating memory from the OS and never give it back. That has nothing to do with a memory leak (either in C or java.) So unless you have already excercised your application without JNI or you are using a profiling tool then you might want examine if 'increasing memory' is the same as 'memory leak'.

  • Why do link addresses change, and how frequently does it happen?

    I have several files on my Creative Cloud account which I share with clients with the links provided on the site by posting the link on my website.  Those links keep breaking because the link to the file changes.  How frequently does this happen?  So I know when I need to go through and change them all over again.

    Moving this discussion to the File Hosting, Syncing, and Collaboration forum.

  • How to change Image color like Channel mixer

    Hello everybody
    I have this problem can anyone help me:
    I want to change Channel mixer color,
    for example, change original Image color to B&W.
    My code:
    docRef.channels[0].color.rgb.red = 30;
    docRef.channels[0].color.rgb.green = 59;
    docRef.channels[0].color.rgb.blue = 11;
    docRef.channels[1].color.rgb.red = 30;
    docRef.channels[1].color.rgb.green = 59;
    docRef.channels[1].color.rgb.blue = 11;
    docRef.channels[2].color.rgb.red = 30;
    docRef.channels[2].color.rgb.green = 59;
    docRef.channels[2].color.rgb.blue = 11;
    But not working in scripting, seems a mistake.
    How should I correct this code? Thank you for your help.

    Hi Michael,
    I try changed 12 parameters in array of num in my js,
    doc.layers[0].mixChannels([[30,59,11,0],[30,59,11,0],[30,59,11,0]],false);
    doc.layers[0].mixChannels([[30,59,11,0]],true); ------  this way is better than ↑
    doc.layers[0].mixChannels([[60,30,10,0],[30,10,60,0],[10,60,30,0]],false);
    doc.layers[0].mixChannels([[39,77,19,0],[35,69,17,0],[27,53,13,0]],false);
    They would show new color as I wantted,
    I forgot ' When monochrome = true, the maximum number of channel value specifications is 1. '
    Thank you for your recommendation.

  • How to Change the color of the black image

    Hi,
    I have created a black image. But want to insert some text and chnage the color of the same. I am trying to do it, by usign various classes of javax.imageio.*, java.awt.image. But, I have not the required output till now. I am showing my code below. The image I created is totally black.
    Any suggestion greatly appreciated.
    File f = new File("C:/tomcat5.5.15/apache-tomcat-5.5.16/webapps/plugintest/03974701.jpg");
    BufferedImage image = ImageIO.read(f);
    int height = image.getHeight();
    int width = image.getWidth();
    int type = image.getType();
    ColorModel cm = image.getColorModel();
    System.out.println("Width of the Image is "+width);
    System.out.println("Height of the Image is "+height);
    System.out.println("type of the Image is "+type);
    BufferedImage image1 = new BufferedImage(width,height,type);
    //image1.setRGB(45,45,rgb);
    File f1 = new File("blank.jpg");
    RenderedImage ri = image1;
    ImageIO.write(ri,"jpg",f1);

    Color c = new Color(0, 0, 0);
    Graphics g = image1.getGraphics();
    g.setColor(c);Thanks for your suggestion I added these lines to the
    code(code is shown above), but the there is no change
    in the color of the jpg image saved in the file. Am I
    missing something.Yes.
    a) Do you know what color 0,0,0 is? Hint: not mauve
    b) When you call set color that sets the drawing colour. But you aren't drawing anything. You can draw things with the methods of Graphics and Graphics2D. I suggest starting with fillRect
    http://java.sun.com/developer/Books/Graphics/
    Thanks

  • HT2513 my iCal calendar that I created with the color green keeps changing to purple.  no matter how many times I change it to green, it turns it back to purple.  Of course this only happens with iCloud and not "from my Mac".  Any ideas?

    my iCal calendar that I created with the color green keeps changing to purple.  no matter how many times I change it to green, it turns it back to purple.  Of course this only happens with iCloud and not "from my Mac".  Any ideas on how to correct this?  This seems like a trivial error, but it's super annoying.

    I called Apple and they said that they know about this problem.  It's a problem with iCloud which their Engineers know about.  (there was a new iCloud release, hence...)  No ETA for a fix yet.  I asked that this be escalated so Engineering doesn't put it at the bottom of their fix list.  I talked to a Senior Advisor and mentioned to them to have QA check their regression tests as this has happened before to me (the problem just didn't take this long to resolve).  I like to use green too for important stuff, so I've resorted to creating a new calendar using the normal calendar green for events going forward.  They could have picked another color besides green to have this problem with and I wouldn't have been so upset.  ;-)

  • ID CS3 - Cannot change image color (imported using "Place")

    Hello. I'm using ID CS3, Windows XP, SP3.
    I am new to ID CS3, coming from PageMaker 6.5, and when I converted one of our brochures, everything looked great. In fact, we have some images that are tif's (I think this means it's a bitmap). The images are black and white (they are apples). Our print process is Black and a Spot Color, so the apple images are the spot color.
    The converted PageMaker6.5 apples are great, they are the spot color, and when I change the spot color, they change too. If I add a new apple image through the Place command, even the exact same file, it imports as black and white, not with the spot color. In PageMaker6.5, this is how it worked, and then I would select the image and then select the spot color. In CS3, when I select the image, and select the color, it either colors the stroke or fill. Obviously I don't want the stroke, and the fill doesn't affect the apple, only the white behind the apple, so I end up with a still black apple on a colored background in the rest of the frame.
    What I want is:
    Background: Paper or None
    Apple: Spot Color (at this point, any color would be fine)
    I have tried applying styles, object/character/paragraph, I have tried the Object->Image Color Setting as found on Adobe help area, except this option is grayed out. I have tried Place, and while selecting the file, selecting "Show Import Options" but it grays out all options when the pop-up box appears. I can't figure out what else to do.
    Also, I can't change the PageMaker6.5 apples to any other color, they are stuck on spot color.
    The problem seems to be I am not targeting the black part of the image itself, yet I can not figure out how to do so. The images are made in Photoshop 6. Thank you for any help you can give (I also have an import jpg file, which has the exact problem of any color changes are to the white background (fill) or the stroke. But again I am unable to change the black part of the image).

    Thanks, in an odd way it worked...
    I dragged like you said. The entire frame became the Spot Color (meaning I could no longer see anything but a large solid block of Green). So I went to Edit->Undo, and it undid the large solid block of green, leaving the previously black image now green, exactly what I wanted. While I don't understand why the Undo command fixed it, I'm happy with the results.
    Thanks.
    Edit - I did it again to another apple, this time it worked perfectly without the undo command. The first time, my cursor became a hand. The second time, it stayed an arrow with a small block under it. Regardless of what happened the first time, thanks again.

  • Why do the colors in my RGB image change when uploading to the web?

    I'm editing my image within Photoshop & have worked with it being RGB from the very start. I place the saved image in Dropbox so I can access it from my phone to place on all my social media accounts. Once I got  to upload the image on the web to my social accounts the colors completely change becoming dull & drab, it looks nothing like the image I saved. Been racking my brain on how to fix this but haven't had a solution that worked yet. Suggestions?

    Hi Danippo13,
    check out this video which explains very well the difference between different color profiles Visualizing Color Profiles on Vimeo and remember that the web uses "standard RGB - 72 dpi".
    I will recommend this setting  in Edit Menu> Color Settings

Maybe you are looking for