Need example of how to create/manipulate image pixel data with iPhone SDK

Looking for a simple example or link to a tutorial.

Say I have a bunch of values stored in an array. I would like to create an image and update the image data from my array. Assume the array values are intensity data and will be updating a grayscale image. Assume the array values are between 0 and 255 -- or that I will convert it to that range.

This is not for purposes of animation. Rather the image would be updated based on user interaction. This is something I know how to do well in Java, but am very new to iPhone programming. I've googled some information about CGImage and UIImage -- but am confused as to where to start.

Any help would be appreciated.

-------------Problems Reply------------

I have sample code from one of my apps that takes data stored as an array of unsigned char and turns it into a UIImage:

// unsigned char *bitmap; // This is the bitmap data you already have.
// int width, height; // bitmap length should equal width * height

// Create a bitmap context with the image data
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
CGContextRef context = CGBitmapContextCreate(bitmap, width, height, 8, width, colorspace, kCGImageAlphaNone);
CGImageRef cgImage = nil;
if (context != nil) {
cgImage = CGBitmapContextCreateImage (context);

// Release the cgImage when done

If your colorspace is RGB and you need to account alpha value pass kCGImageAlphaPremultipliedLast as last parameter to CGBitmapContextCreate function.

Don't use kCGImageAlphaLast, this will not work because bitmap contexts do not support alpha that isn't premultiplied.

The books I referenced in this SO answer both contain sample code and demonstrations of image manipulations and updates via user interaction.

Category:iphone Views:0 Time:2010-05-04
Tags: image iphone

Related post

  • Beginner-Question: Hey to create + open a second view? (iphone sdk) 2010-08-18

    at the moment I try myself on iphone develpment. I read a lot of howtos and a complete book, to find myself in ObjC. I can create my first app, hello world, get actions on buttons and so on. Now I have my View (Created on New Project -> View Based

  • UITableViewCell : UIImageView in ContentView creates problem by overlapping images in iPhone SDK 2011-01-19

    In my iPhone app, I am using a tableView and have added the imageView as ContentView in my tableViewcell. At the click of button I am changing the tableView Contents. So every time I click a button it should show the corresponding image in tableViewC

  • .NET : Create custom control like UItableView in iPhone SDK 2011-12-28

    i want to create a custom control (like UITableView in iPhone) in .Net using c sharp so user can scroll using mouse or keyboard navigation keys. I also want to create event when user click on any row. Currently the possible control is Datagridview wh

  • Create Bitmap from a byte array of pixel data 2011-07-21

    This question is about how to read/write, allocate and manage the pixel data of a Bitmap. Here is an example of how to allocate a byte array (managed memory) for pixel data and creating a Bitmap using it: Size size = new Size(800, 600); PixelFormat p

  • error on creating an Excel file using open XML SDK in .net web application 2011-07-28

    I am developing a report in excel format from my .net web application. I am using Open XML SDK to create the excel spreadsheet. The code is working fine when I run it on Visual Studio. But when I publish the application and host it on the IIS server

  • How to use 'find' to search for files created on a specific date? 2008-10-01

    How do I use the UNIX tool 'find' to search for files created on a specific date? --------------Solutions------------- As pointed out by Max, you can't, but checking files modified or accessed is not all that hard. I wrote a tutorial about this, as l

  • How do you create hybrid Xcode projects for Mac & iPhone? 2009-01-14

    I'm working on a project which shall contain two targets. One for building a Framework to use in Mac development and another to create a static library to use in iPhone development. In the common code it's no problem to #ifdef between the platforms,

  • How do I create a Cocoa touch template using the iPhone SDK? 2009-01-28

    I downloaded the free iphone sdk. Now when I try to create a new project I am not given the option to create a cocoa touch template. I only have the option to create a Mac OS X template. Does anyone know why this would occur and how to fix it? Edit:

  • How to create multiple buttons dynamically and handle their separate events? + iPhone SDK 2009-03-20

    Now I am creating a IPhone App. I need to create multiple buttons dynamically and handle their corresponding events separately. Can each button events behave separately, or can I send a variable or an object to a method and depending upon that value

  • How to create bubbble message box similar to iPhone buildin SMS app? 2009-06-08

    How to create bubbble message box similar to iPhone buildin SMS app? I'm trying to create a table cells with a bubble message box, similar to the iPhone SMS app or iChat. Anybody have example code I can refer to? --------------Solutions-------------

  • Creating a range of dates in Python 2009-06-14

    I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this? import datetime a = numdays = 100 dateList = [] for x

  • Create Unique String Iphone SDK 3.0 2009-08-22

    I wanted to create an unique string with length not more than 15 characters in objective C (or with the help of Iphone SDK 3.0). I need this for mysql table. I know mysql auto increment will do for primary key but I really need to send the unique key

  • How can I create a big, red UIButton with the iPhone SDK? 2009-09-15

    Using the iPhone SDK, how would I go about creating a red "delete" button similar to the one used when deleting contacts on the iPhone? --------------Solutions------------- You first start with a stretchable image: Then you make a button with the str

  • Google Calendar API: can i retrieve entries changed/created after a specified date? 2010-01-23

    Can i retrieve entries changed/created after a specified date? This is regardless of the event date - only by "modified date". I.e. if i modify an old even i want to be able to retrieve it using a query (without knowing its id) --------------Solution

  • Help for create search bar for my table view [ iPhone SDK ] 2010-01-24

    hi iam new to iphone sdk and i want create a search bar for my table view ... for creating my cells i use .plist . can you help me step by step how can i mange it . here is my sample code : [for everyone wants help me quickly]:

  • How to create this MongoMapper custom data type? 2010-03-21

    I'm trying to create a custom MongoMapper data type in RoR 2.3.5 called Translatable: class Translatable < String def initialize(translation, culture="en") end def languages end def has_translation(culture)? end def self.to_mongo(value) end def se

  • Create folder for todays date 2010-05-06

    I have a folder named as 2010. In this I want a folder for each month like "Jan10", "Feb10"....."Dec10" In each month folder I want to create folder for "Todays date" I have create a shortcut for that 2010 folder with Target as C:\WINDOWS\explorer.ex

  • Creating Lotus Notes documents with specific created/modified/last accessed dates for testing 2010-05-26

    I'm currently writing an application that moves Notes documents between databases based on the amount of days that have elapsed from the creation/modified/last accessed dates. I would just like to get ideas on a simple and convenient way to create do

  • how do i create and save a data file in a folder of my choice 2010-07-04

    how do i create and save a data file in a folder of my choice in C++ program? --------------Solutions------------- See this for an example of what you are asking: Input/Output with files This should help guide you in the right direction. http://www.c

Copyright (C), All Rights Reserved.

processed in 0.197 (s). 11 q(s)