首页 \ 问答 \ 如何在Firebase Android中查询SQL IN子句(How to perfom query SQL IN clause in Firebase Android)

如何在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
更新时间:2023-05-29 13:05

最满意答案

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 ...
  • 获取原始数据 从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 ...
  • 您可能忘记了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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)