How can i simply used progress view in my app - ios

I am trying to save image to the photos album from my app using the following code:
-(void)download:(UIButton *)downloadbtn{
j=320*downloadbtn.tag;
selectedIndex=downloadbtn.tag;
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:[live_god_img objectAtIndex:selectedIndex]]];
UIImage*img=[UIImage imageWithData:data];
UIImageWriteToSavedPhotosAlbum(img, self, nil, nil);
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:#"Success..!" message:#"Image Saved to the Photos" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
When the image is saved to the photos album, an alert view will be shown, but I would like to show a progress view while image is being saved to the album. I do not know how to use UIProgressView. How do I do it?

Go through this tutorial first
You can try like this in your method.
- (IBAction)startProgress:(id)sender
{
progressValue = 0.0f;
[self increaseProgressValue];
}
-(void)increaseProgressValue
{
if(progressView.progress<1)
{
progressValue = progressValue+0.1;
progressView.progress = progressValue;
[self performSelector:#selector(increaseProgressValue) withObject:self afterDelay:0.2];
}
}

Related

How to take snapshot of app running on simulator?

I used this code to take the snapshot of my app running on simulator, the quality of the snap is not good, Any idea?
-(IBAction)btnSave:(id)sender
{
UIGraphicsBeginImageContextWithOptions(Self.View.bounds.size,Self.View.opaque,10.0f);
[Self.View.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
/* Render the screen shot at custom resolution */
CGRect cropRect = CGRectMake(0,0,320,500);
UIGraphicsBeginImageContextWithOptions(cropRect.size,BrochureSave.opaque,10.0f);
[screenshot drawInRect:cropRect];
UIImage * customScreenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
/* Save to the photo album */
// UIImageWriteToSavedPhotosAlbum(customScreenShot , nil, nil, nil);
[self.library saveImage:customScreenShot toAlbum:#"Cemara roll" withCompletionBlock:^(NSError *error) {
if (error!=nil)
{
NSLog(#"Big error: %#",[error description]);
}
else
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Message" message:#"Image Save Cemara roll" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}];
}
Try changing 10.0f to 0.0f in UIGraphicsBeginImageContextWithOptions:
here:
UIGraphicsBeginImageContextWithOptions(Self.View.bounds.size,Self.View.opaque,0.0f);

UIImagePickerController add text to image

I'm trying to capture an image or video using the camera in iOS and add some text to a black bar overlayed at the bottom of the image.
I'm trying to get the text from a user input and save the image with the text and rectangle at the bottom of the image:
How would I go about this?
I currently have this:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
// A photo was taken/selected!
self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
// Save the image!
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
}
}
else {
// A video was taken/selected!
self.videoFilePath = (__bridge NSString *)([[info objectForKey:UIImagePickerControllerMediaURL] path]);
if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
// Save the video!
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.videoFilePath)) {
UISaveVideoAtPathToSavedPhotosAlbum(self.videoFilePath, nil, nil, nil);
}
}
}
[self dismissViewControllerAnimated:YES completion:nil]; }
What would be the best way of going about this?
You can add a UIView over the UIImageView with black (with alpha to be 0.5) background and on this UIView you can add a UILabel with your text.
I'd say have the user do an input using a UIAlertView
here's a sample
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Title Here"
message:#"message"
delegate:self
cancelButtonTitle:#"Cancel" // or nil
otherButtonTitles:#"Ok",
nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
that shows that an alert will appear with a text box in it. Since we set self to delegate, you have to call that delegate as such
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:#"Ok"]) {
NSString *alertText = [alertView textFieldAtIndex:0].text;
// create UILabel here and set the text as advised in answer above
// example with global UILabel *overlayLabel;
self.overlayLabel.text = alertText;
// self.overlayLabel.font = [UIFont ...];
}
}
This is essentially what apple does. Go to the music app, and hit the "new playlist" and you'll see it in action
hope this helps!

How to save image using AVCaptureDevice

I'm using Apple's GLCameraRipple example code in my project and I was wondering if there is a way to take a pic/video? Project can be found at https://developer.apple.com/library/ios/samplecode/GLCameraRipple/Introduction/Intro.html
First of all, ensure that you have included AssetLibrary framework, because we need that to access the photo library. Assuming that you have set up the capture AVCaptureSession, AVCaptureDevice, and AVCaptureStillImageOutput (stillImage) correctly, now you can create a button or simply call the below function to save an image.
-(void)captureMultipleTimes
{
AVCaptureConnection *connection = [stillImage connectionWithMediaType:AVMediaTypeVideo];
typedef void(^MyBufBlock)(CMSampleBufferRef, NSError*);
MyBufBlock h = ^(CMSampleBufferRef buf, NSError *err){
NSData *data = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:buf];
[self setToSaveImage:[UIImage imageWithData:data]];
dispatch_async(dispatch_get_main_queue(), ^{
if(saveLabel == NULL){
[self setSaveLabel:[[UILabel alloc] initWithFrame:CGRectMake(0,self.view.bounds.size.height/2, self.view.bounds.size.width, 50)]];
[saveLabel setText:#"Saving.."];
[saveLabel setTextColor:[captureBt titleColorForState:UIControlStateNormal]];
[self.view addSubview:saveLabel];
} else
saveLabel.hidden = NO;
UIImageWriteToSavedPhotosAlbum(toSaveImage, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
});
};
[stillImage captureStillImageAsynchronouslyFromConnection:connection completionHandler:h];
}
You also need to implement the image:didFinishSavingWithError:contextInfo: method as the completion function of saving image. One example is as follows:
-(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if(error != NULL){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error!" message:#"Image could not be saved" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
else{
[saveLabel setHidden:YES];
}
}
The functions above will display "Saving.." label on the screen once you trigger the captureMultipleTimes function. It simply means that it is currently saving the video input as an image and store it into the photo lib. Once it has finished saving, the saving label will be hidden from the screen. Hope this helps!

How can I dismiss the image picker after didFinishSavingWithError?

All I want to do is after the alert is shown that the picture was or wasn't saved the picker should be dismissed, but I can't manage to find out how.
I present the image control like this :
[self presentModalViewController:imagePicker animated:YES];
I know i need to dismissmodalviewcontroller, because i do it for the cancel case, but I don't know where to place it so that after the image is saves it exists.
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"Image saved to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
You will have to create the instance of UIImagePickerController locally and in alertview delegate method, simply dismiss it.
it is depends on how you present imagepickercontroller if you have used peserntmodelviewcontrolleranimated: then use dismissModalViewControllerAnimated:

iOS : How to save current image from my current UIView to photo album? I'm stuck with UIImageWriteToSavedPhotosAlbum

I have my current image that can swipe back and forward. All the image are inside a folder called pages. So when I am in the current view, I have an IBAction to save that current image to photo album. How to implement that task ? I have study this but I don't know how to start and i'm stuck.
M file :
I define UIImage.h
void UIImageWriteToSavedPhotosAlbum (
UIImage *image,
);
- (IBAction)saveMe{
[UIImageWriteToSavedPhotosAlbum];
}
My Amendment code:
-(IBAction) saveToPhotoAlbum{
}
- (void) imageViewController:(UIImageView *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = //i have 6 current UIImageview on my current main view. How do I get stated?
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
[picker release];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
if (error)
alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
else
alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"Image saved to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
draw uiview to context
UIGraphicsBeginImageContext(size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
and use UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo); for save to album

Resources