Create QR code in iphone - iphone

I have seen some example codes, these code are creating QR codes froms Text (below is the code).can we generate QR codes from other data also (like Image)?
NSString *code = #"1001012023034";
Barcode *barcode = [[Barcode alloc] init];
self.view.backgroundColor = [UIColor whiteColor];
[barcode setupQRCode:code];
self.imageView.image = barcode.qRBarcode;
My question is if we use Image instead of string data then is it possible?

Yes, It's Possible. There are two Best Libraries available :
1) For Encoding : QR-Code-Encoder-for-Objective-C
2) For Decoding : ZBar bar code reader
GoodLuck.

QR codes are pretty limited in terms of data storage, limited to a few kb - see http://en.wikipedia.org/wiki/QR_code#Storage for storage sizes. As such, you won't be able to put an image in there. What you CAN do, however, is upload the image somewhere and encode a link to that image instead.

Related

Convert image data to binary text for vcard

I need to include an image in a vcard file. The image is supposed to be in binary format. I create the image data as follows:
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:#"Pic1"], 1.0);
I have unsuccessfully tried encoding using the following 2 methods:
vcardString = [vcardString stringByAppendingFormat:#"PHOTO;ENCODING=b;TYPE=JPEG:%#\n", [imageData base64EncodedString]];
AND
vcardString = [vcardString stringByAppendingFormat:#"PHOTO;ENCODING=b;TYPE=JPEG:%#\n", [imageData description]];
Any advice on how to get the image data properly encoded to binary would be appreciated. Thanks
According to this blog entry I found (which points to this spec), it looks like the second form of what you're trying to do should work.
Change your ENCODING=b to ENCODING=BASE64 and see if that makes the difference.
OS X v10.11 and iOS 9 introduces CNContactVCardSerialization which greatly simplifies embedding images in a VCard.

iOS support for Canon RAW format?

I know the iPad can read Canon RAW (.CR2) files when used with the Camera Kit but is any of that file format reading accessible to an iOS developer? Or are we just limited to things supported in the UIImage Class Reference document?
(https://developer.apple.com/documentation/uikit/uiimage)
For something like this, Apple's image APIs are not going to be sufficient for what you need. However, there are a few third party APIs that should work with the iPhone. Libraw is a good one that I found that has a C interface. Since Objective-C is a strict superset of C, you will probably be able to use it in your iOS application.
From what I see in their docs, you might be able to write a CR2 image as a TIFF, then decode it as a UIImage like this:
NSString * cr2Path = #"path/to/cr2/file";
NSString * tiffPath = [NSTemporaryDirectory stringByAppendingPathComponent:#"x.tiff"];
libraw_data_t * cr2Data = libraw_init(0);
libraw_open_file(cr2Data, [cr2Path UTF8String]);
libraw_unpack(cr2Data);
// setup encoding params
cr2Data->params.output_tiff = 1;
cr2Data->params.use_camera_wb = 1;
// encode and write as tiff
libraw_dcraw_process(cr2Data);
libraw_dcraw_ppm_tiff_writer(cr2Data, [tiffPath UTF8String]);
libraw_recycle(cr2Data); // free the memory
// load the UIImage
UIImage * myImage = [[UIImage alloc] initWithContentsOfFile:tiffPath];
// use myImage here ...
[myImage release];
From what I have seen, it looks like you will be able to download it here and then add the src files from the src/, libraw/, dcraw/, and internal/ directories to your Xcode project. Hopefully you will not run into any weird linking/compiling issues.

Base64Encoded string in ios not decoding properly on server side using php

I am converting image to NSdata using UIImageJPEGRepresentation(image, 1.0) and then encoding it to base64 using base64 helper class
NSString *imageOne = [self encodeBase64WithData:[imageDict objectForKey:#"ImageOne"]];
and finally sending it to server using post method as json parameter and in server side using php method to decode it.
/* encode & write data (binary) */
$ifp = fopen($imageNameWithPath, "wb" );
fwrite($ifp, base64_decode($base64ImageString));
fclose($ifp);
After decoding it, I am saving the file as jpeg image and the file is created with proper size and extension but problem is that when I open it, I get the DIMENSION OF IMAGE as 0X0 ..(problem is here)
Server side script is correct as our android developer is also sending base64string and the image is saved as jpeg with proper size and dimension.
This problem is only from iphone side when sending to server for decoding. I have decoded the image using my base64 helper class and it works fine on my iPhone device.
UIImageView *viewImage = [[UIImageView alloc] initWithImage:[UIImage imageWithData: [self decodeBase64WithString:[registerDataDict objectForKey:#"imageOne"]]]];
[self.view addSubview:viewImage];
Is the process followed by me correct on the device or do I need to change something? Help would be appreciated.
There are variants on the extra chars used to get to the 65 needed for base64 encoding (26 uppercase + 26 lowercase + 10 digits = 62), and different encoders may use a different subset. PHP is expecting them to be ['+', '/', '='], your application may be using something like ['-', '_', '='].
Once you figure out what the mapping is you can use str_replace before the decode in php.
See the wikipedia page on base64 or the php documentation for base64_decode for more info.
I'm successfully using this with several OAuth providers: Base64Transcoder.c It's a C class, you can easily turn it into a Objective-C class if you like.
I'm encoding like this:
char base64Result[32];
size_t theResultLength = 32;
[Base64Transcoder base64EncodeData:digest digestLength:CC_SHA1_DIGEST_LENGTH base64Result:base64Result resultLength:&theResultLength];
NSData *theData = [NSData dataWithBytes:base64Result length:theResultLength];
NSString *base64EncodedResult = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding];
Hmm well, I turned the C function base64EncodeData of the original class into an Objective-C method but you get the idea.

Image to Text (iPhone)

How can I get the texts presented on an image ?
Description : "I am developing one application which needs to get the text presented on an Image and show the text in an another view after putting the texts in to some frames."
EDIT : From this I'm getting some Values and also the ".png" but the characters I am getting is like ASCII value or something.
UIImage*img=[UIImage imageNamed:#"btn_reset.png"];
NSData *dataObj = UIImagePNGRepresentation(img);
NSString*str= [[NSString alloc] initWithData:dataObj encoding:NSASCIIStringEncoding];
printf("Image is %s",[str UTF8String]);
Any tutorial/link/solution would be very helpful.
Thank You !
I couldn't understand the question clearly, but I think you are referring to OCR.
One of the main open-source lib for this is: Tesseract
Some one has ported this lib for ios. You can get the code from: https://github.com/rcarlsen/Pocket-OCR/
you might get solution from following link:
Is there any iphone Class that converts images to text format?
If you just want to print the string
UIImage*img=[UIImage imageNamed:#"btn_reset.png"];
NSData *dataObj = UIImagePNGRepresentation(img);
NSString*str= [[NSString alloc] initWithData:dataObj encoding:NSASCIIStringEncoding];
NSLog("Image is %#",str);
If you still dont get it change the encoding

Using .png files instead of using .ico files in windows programs

hi I have a collection of nice .png files....
meanwhile, I'm developing a win-based software and need some .ico files as icons for toolbar buttons and ....
Is there any way to use .png file as an icon ? or what?
Thank you
As a workaround you can use IrfanView to convert your *.png file to *.ico file (or any other image to ico) & use it.
http://www.irfanview.com/main_download_engl.htm
You can simply convert the images to ico files online Ico Convert.
If you are using .NET this is not a real problem for you, because afaik PNG support is already build in. You are probably talking about native C/C++ development with GDI/win32?
To my knowledge you will not accomplish this by simply using GDI. There are a couple of options where you can set ONE color as transparent then load a simple BMP/JPEG and do some BITMAP tricks however using ICO/GIF will be far easier for this.
What you are probably looking for is a working GDI+ example which will use a PNG with alpha channel? This is just an excerpt and I left out the whole mess loading external functions from a DLL part, but maybe this will help you:
static GpImage *background = NULL;
GDIPLOADIMAGEFROMSTREAM GdipLoadImageFromStream;
GDIPLUSSTARTUP GdiplusStartup;
GDIPPLUSSHUTDOWN GdiplusShutdown;
GDIPCREATEFROMHDC GdipCreateFromHDC;
GDIPDELETEGRAPHICS GdipDeleteGraphics;
GDIPDRAWIMAGEI GdipDrawImageI;
GDIPDRAWIMAGERECTI GdipDrawImageRectI;
GDIPLUS_STARTUP_INPUT GdiplusStartupInput;
void LoadPNG(GpImage **image, int resource, HMODULE hInstance)
{
HRSRC resrc;
LPSTREAM lpstr;
HGLOBAL hPng;
LPVOID fByte;
GpImage *img = NULL;
resrc = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(resource), TEXT("PNG"));
hPng = LoadResource(GetModuleHandle(NULL), resrc);
fByte = LockResource(hPng);
lpstr = SHCreateMemStream(fByte, 200000);
GdipLoadImageFromStream(lpstr, &img);
*image = img;
}
void CreateBack(HWND hWnd)
{
HDC memDC = NULL;
HDC hdc = NULL;
RECT rect;
DeleteObject(curBack);
GetClientRect(hWnd, &rect);
hdc = GetDC(hWnd);
memDC = CreateCompatibleDC(hdc);
curBack = CreateCompatibleBitmap(hdc, rect.right, 44);
SelectObject(memDC, curBack);
/* gdiplus - background*/ {
int e = 0;
GpGraphics *g;
GdipCreateFromHDC(memDC, &g);
GdipDrawImageRectI(g, background, e, 0, 971, 44);
GdipDeleteGraphics(g);
}
DeleteObject(memDC);
ReleaseDC(hWnd, hdc);
}
Just a quick note: This GDI+ stuff is really CPU/memory intensive for a couple of reasons. Although fun I did abandoned this approach in favor of gdi and simple BMPs.
If you're loading the images from a resource file, then no, you can't use PNGs, you have to use ICOs. Fortunately, there are a number of tools that can convert PNGs into ICOs, including ImageMagick (great for automation), and MSPaint as a lowest common denominator.
If you're loading image files at runtime, then you can load any type of image format you want (e.g. use libpng for loading PNGs), but you still have to convert them to icons internally before you can do interesting things with them, such as setting them as a window's icon. Once you've decoded the image data, it's not terribly difficult to convert it to the proper format, but it's not trivial, it just involves a lot of data mangling and strange structs and function calls from the Win32 API.