如何在Firebase Android中查询SQL IN子句(How to perfom query SQL IN clause in Firebase Android)
如何在Firebase Android中查询SQL IN子句? 我想在Firebase Recycler适配器中使用它来根据某些条件仅检索一些子项。 类似于以下声明:
SQL----> select * from posts where city in(10 cities comes here)
我需要Firebase查询才能在Firebase Recycler适配器中使用它。
How do I query SQL IN clause in Firebase Android? I want to use it in a Firebase Recycler adapter to retrieve only some children based on some condition. Something like the following statement:
SQL----> select * from posts where city in(10 cities comes here)
I need a Firebase query to use that in the Firebase Recycler adapter.
原文:https://stackoverflow.com/questions/40910884
最满意答案
FYI,我将Keremk的答案与我的原始大纲相结合,清理了打字错误,将其归纳为返回一系列颜色,并将整个事情进行编译。 结果如下:
+ (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)x andY:(int)y count:(int)count { NSMutableArray *result = [NSMutableArray arrayWithCapacity:count]; // First get the image into your data buffer CGImageRef imageRef = [image CGImage]; NSUInteger width = CGImageGetWidth(imageRef); NSUInteger height = CGImageGetHeight(imageRef); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); unsigned char *rawData = (unsigned char*) calloc(height * width * 4, sizeof(unsigned char)); NSUInteger bytesPerPixel = 4; NSUInteger bytesPerRow = bytesPerPixel * width; NSUInteger bitsPerComponent = 8; CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGColorSpaceRelease(colorSpace); CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); CGContextRelease(context); // Now your rawData contains the image data in the RGBA8888 pixel format. NSUInteger byteIndex = (bytesPerRow * y) + x * bytesPerPixel; for (int i = 0 ; i < count ; ++i) { CGFloat alpha = ((CGFloat) rawData[byteIndex + 3] ) / 255.0f; CGFloat red = ((CGFloat) rawData[byteIndex] ) / alpha; CGFloat green = ((CGFloat) rawData[byteIndex + 1] ) / alpha; CGFloat blue = ((CGFloat) rawData[byteIndex + 2] ) / alpha; byteIndex += bytesPerPixel; UIColor *acolor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; [result addObject:acolor]; } free(rawData); return result; }
FYI, I combined Keremk's answer with my original outline, cleaned-up the typos, generalized it to return an array of colors and got the whole thing to compile. Here is the result:
+ (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)x andY:(int)y count:(int)count { NSMutableArray *result = [NSMutableArray arrayWithCapacity:count]; // First get the image into your data buffer CGImageRef imageRef = [image CGImage]; NSUInteger width = CGImageGetWidth(imageRef); NSUInteger height = CGImageGetHeight(imageRef); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); unsigned char *rawData = (unsigned char*) calloc(height * width * 4, sizeof(unsigned char)); NSUInteger bytesPerPixel = 4; NSUInteger bytesPerRow = bytesPerPixel * width; NSUInteger bitsPerComponent = 8; CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGColorSpaceRelease(colorSpace); CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); CGContextRelease(context); // Now your rawData contains the image data in the RGBA8888 pixel format. NSUInteger byteIndex = (bytesPerRow * y) + x * bytesPerPixel; for (int i = 0 ; i < count ; ++i) { CGFloat alpha = ((CGFloat) rawData[byteIndex + 3] ) / 255.0f; CGFloat red = ((CGFloat) rawData[byteIndex] ) / alpha; CGFloat green = ((CGFloat) rawData[byteIndex + 1] ) / alpha; CGFloat blue = ((CGFloat) rawData[byteIndex + 2] ) / alpha; byteIndex += bytesPerPixel; UIColor *acolor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; [result addObject:acolor]; } free(rawData); return result; }
相关问答
更多-
FYI,我将Keremk的答案与我的原始大纲相结合,清理了打字错误,将其归纳为返回一系列颜色,并将整个事情进行编译。 结果如下: + (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)x andY:(int)y count:(int)count { NSMutableArray *result = [NSMutableArray arrayWithCapacity:count]; // First get the image into ...
-
我直接看到的一个问题是你正在使用X和Y原点的栅格单元格编号。 此配置中的栅格只是单个尺寸线。 您可以根据光栅图像的宽度计算第二个维度。 这可以解释为什么你有一条线。 另一件事:看起来你正在阅读图像的每个像素。 你不想跳过你想要绘制的椭圆宽度的像素吗? 接下来看起来很可疑的是我认为你应该在绘图之前创建你正在绘制的上下文。 另外,你不应该打电话: CGContextRef contextRef = UIGraphicsGetCurrentContext(); CGContextSaveGState(contex ...
-
如何从UIImage或CGImage获取基础像素数据?(How can I get the underlying pixel data from a UIImage or CGImage?)[2022-01-04]
获取原始数据 从Apple的技术问答QA1509开始,它表示通过从数据提供商处获取原始图像数据将获得原始图像数据。 CFDataRef CopyImagePixels(CGImageRef inImage) { return CGDataProviderCopyData(CGImageGetDataProvider(inImage)); } 需要不同的格式或色彩空间 如果要获得颜色匹配的数据并使用特定格式,可以使用类似于以下代码示例的内容: void ManipulateImagePi ... -
你在一个永无止境的循环中调用worker(): while ( true ) { imageData = worker(); boundary = Encoding.UTF8.GetBytes( "\r\n--myboundary\r\nContent-Type: image/jpeg\r\nContent-Length: " + ...
-
你不要告诉Cocoa(触摸或其他)突然开始画画。 它询问您的应用程序应该如何绘制某些视图,并在视图子类的drawRect方法中告诉它。 此时已经创建了图形上下文。 您的代码正在创建图形上下文并绘制到它,但此绘图不在屏幕上完成。 要在特定位置绘制特定图像,通常会将图像对象分配给某个视图(如上面代码中的精灵?我不熟悉cocos2d),它已经知道如何绘制图像。 然后你将该视图放在屏幕上(你注释掉了addChild调用吗?)。 您可以将必要的变换添加到视图对象中,这将被考虑在内。 简要地看一下cocos2d文档,C ...
-
通常,您希望-drawRect:尽可能简单。 将您的绘图代码从-drawRect:移动到创建并绘制您想要的整个图像的方法中。 Reduce -drawRect:仅将该图像合成到当前上下文中。 As a rule, you want -drawRect: to be as simple as possible. Move your drawing code from -drawRect: into a method that creates and draws the entire image you wan ...
-
Re:在swift中从UIImage / CGImage获取像素数据作为数组(Re: Get pixel data as array from UIImage/CGImage in swift)[2023-08-27]
您可能忘记了CGImageAlphaInfo参数。 对于彩色图像,如果假设bytesPerPixel为4,则需要在创建上下文时设置RGBA(或ARGB)。 以下是没有alpha通道的RGBA示例。 // RGBA format let ctx = CGBitmapContextCreate(&data, pixelsWide, pixelsHigh, 8, bitmapBytesPerRow, colorSpace, CGImageAlphaInfo.NoneSkipLast.rawValue ... -
这个方向对你有用吗? 我得到像这样的像素数据: UInt32 *pixels = CGBitmapContextGetData( ctx ); #define getRed(p) ((p) & 0x000000FF) #define getGreen(p) ((p) & 0x0000FF00) >> 8 #define getBlue(p) ((p) & 0x00FF0000) >> 16 // display RGB values from the 11th pixel NSLog(@"Red: %d, ...
-
我找到了解决问题的方法。 我不知道UIKit不是线程安全的。 似乎在与main不同的线程中执行该代码,不允许系统释放内存。 在主线程上,正确释放和管理内存。 I found the solution to my problem. I didn't know that UIKit is not thread safe. It appears that executing that code in a thread different from the main, does not allow the syst ...
-
更好的答案: 您需要将一个UIImage对象(而不是CGImage指针)真正设置为您声明为UIImage对象的属性。 原版的: 如果“ finalPhotoToSend ”是一个属性,你应该这样做: NSData *imageData = UIImageJPEGRepresentation(self.finalPhotoToSend, 0.7); 并不是: NSData *imageData = UIImageJPEGRepresentation(finalPhotoToSend, 0.7); Bett ...