Kotlin QR Kod Kütüphanesi

Kotlin ile QR Kod Oluşturun

Kotlin geliştiricileri Android QR kod oluşturma ve tarama için ZXing kullanabilir. Jetpack Compose ve geleneksel Android Views ile sorunsuz çalışır.

Kurulum

Gradle kullanarak Android projenize ZXing ekleyin.

Gradle (Android)
implementation("com.google.zxing:core:3.5.3")
Gradle (with image)
implementation("com.google.zxing:core:3.5.3")
implementation("com.google.zxing:javase:3.5.3")

Kotlin ve ZXing ile QR Kod Oluşturun

Android için Kotlin'de ZXing kullanan kod örnekleri.

Generate QR Code Bitmap (Android)
import android.graphics.Bitmap
import com.google.zxing.BarcodeFormat
import com.google.zxing.MultiFormatWriter

fun generateQRCode(data: String, size: Int = 300): Bitmap {
    val matrix = MultiFormatWriter().encode(
        data, BarcodeFormat.QR_CODE, size, size
    )

    return Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565).apply {
        for (x in 0 until size) {
            for (y in 0 until size) {
                setPixel(x, y, if (matrix[x, y]) 0xFF1A2B3C.toInt() else 0xFFFFFFFF.toInt())
            }
        }
    }
}

// Usage
val qrBitmap = generateQRCode("https://qrcode.fun")
Jetpack Compose QR Code
@Composable
fun QRCodeImage(
    data: String,
    modifier: Modifier = Modifier,
    size: Int = 300
) {
    val bitmap = remember(data) { generateQRCode(data, size) }

    Image(
        bitmap = bitmap.asImageBitmap(),
        contentDescription = "QR Code",
        modifier = modifier.size(200.dp)
    )
}

// Usage in a Composable
@Composable
fun MyScreen() {
    QRCodeImage(data = "https://qrcode.fun")
}
QRCode.fun API

Kotlin'de API ile QR Kod Oluşturun

Stilize QR kodlar için Kotlin'den OkHttp veya Ktor kullanarak QRCode.fun API'sini çağırın.

Kotlin API Entegrasyonu
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject

suspend fun generateQRCodeViaAPI(data: String): String {
    val client = OkHttpClient()
    val json = JSONObject().apply {
        put("data", data)
        put("width", 300)
        put("height", 300)
        put("type", "png")
        put("margin", 10)
        put("dotsOptions", JSONObject().apply {
            put("color", "#1A2B3C")
            put("type", "rounded")
        })
        put("cornersSquareOptions", JSONObject().apply {
            put("color", "#8564C3")
            put("type", "extra-rounded")
        })
        put("backgroundOptions", JSONObject().apply {
            put("color", "#FFFFFF")
        })
    }

    val request = Request.Builder()
        .url("https://qrcode.fun/api/generate-qr-styled")
        .post(json.toString().toRequestBody("application/json".toMediaType()))
        .build()

    val response = client.newCall(request).execute()
    val result = JSONObject(response.body?.string() ?: "")
    return result.getString("data") // base64 PNG data URL
}

Canlı QR Kod Önizleme

Şimdi Kotlin ile bir QR kod oluşturmayı deneyin.

QR önizleme

ZXing vs API

Kotlin'de ZXing kullanma ile QRCode.fun API karşılaştırması.

ÖzellikZXing KütüphanesiQRCode.fun API
Kurulum karmaşıklığıGradle bağımlılığı + Bitmap oluşturmaOkHttp ile tek HTTP isteği
ÖzelleştirmeBoyut, hata düzeltme, Bitmap ile renklerTam stil: renkler, şekiller, logolar
Çevrimdışı destekEvetİnternet gerekli
BakımGradle bağımlılığı güncellemeHer zaman güncel
Çıktı formatlarıBitmap (Android)PNG, SVG

Kotlin QR Kod Kullanım Alanları

Kotlin uygulamalarında QR kodlar için yaygın senaryolar.

Android Uygulamaları

Bağlantı, kişi, Wi-Fi kimlik bilgileri ve ödeme bilgisi paylaşmak için Android uygulamalarında QR kod oluşturun ve görüntüleyin.

Jetpack Compose

Modern Android arayüzleri için özel stil ve animasyonlarla birleştirilebilir QR kod bileşenleri oluşturun.

Kotlin Multiplatform

QRCode.fun API ile Kotlin Multiplatform kullanarak Android, iOS ve masaüstü arasında QR kod oluşturma mantığını paylaşın.

Backend Hizmetleri

Biletler, faturalar ve kimlik doğrulama akışları için Ktor veya Spring Boot Kotlin hizmetlerinde QR kod oluşturun.

Sıkça Sorulan Sorular

Kotlin ile QR kod oluşturma hakkında yaygın sorular.

Android için ZXing (zxing:core) standart seçimdir. Kotlin Multiplatform veya sunucu tarafı için platformlar arası tutarlılık sağlayan QRCode.fun API'sini düşünün.

Kotlin ile QR kod oluşturmaya başlayın

Ücretsiz oluşturucumuzu kullanın veya API'yi Kotlin ve Android uygulamalarınıza entegre edin.