保存我的二维码信息为整张图片

这里写图片描述

如图:要实现保存二维码包括后边白框的区域

《1》首先需要引入系统库
点击TARGET – Build Phases – Link Binary With Libraries
然后点击+
搜索到下图的库,并添加
这里写图片描述

《2》代码如下
//backView 为所定义的白色View

CGRect screenRect = [backView bounds];

    UIGraphicsBeginImageContext(screenRect.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [backView.layer renderInContext:ctx];

    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    ALAssetsLibrary * library = [ALAssetsLibrary new];
    NSData * data = UIImagePNGRepresentation(image);
    [library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
        if(error != NULL){
            [self.MBHU showErrorWithMessage:@"保存失败" duration:1.0f];

        }else{
            [self.MBHU showSuccessWithMessage:@"保存成功" duration:1.0f];
        }
    }];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将Java中的一张图片生成为二维码,可以使用ZXing库。以下是一个示例代码: ```java import java.awt.image.BufferedImage; import java.io.File; import java.util.HashMap; import java.util.Map; import javax.imageio.ImageIO; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.QRCodeWriter; public class ImageToQRCode { public static void main(String[] args) throws Exception { String imagePath = "path/to/image.jpg"; String qrCodePath = "path/to/qrcode.png"; String qrCodeText = "This is the text to be encoded into QR code."; // Read the image BufferedImage image = ImageIO.read(new File(imagePath)); // Encode the text into QR code QRCodeWriter qrCodeWriter = new QRCodeWriter(); Map<EncodeHintType, Object> hints = new HashMap<>(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); BitMatrix bitMatrix = qrCodeWriter.encode(qrCodeText, BarcodeFormat.QR_CODE, image.getWidth(), image.getHeight(), hints); // Convert the QR code into an image int width = bitMatrix.getWidth(); int height = bitMatrix.getHeight(); BufferedImage qrCodeImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { qrCodeImage.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); } } // Combine the image and the QR code BufferedImage combinedImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB); combinedImage.getGraphics().drawImage(image, 0, 0, null); combinedImage.getGraphics().drawImage(qrCodeImage, (image.getWidth() - width) / 2, (image.getHeight() - height) / 2, null); // Save the combined image ImageIO.write(combinedImage, "png", new File(qrCodePath)); } } ``` 这段代码将会读取指定路径下的图片,将指定文本编码为二维码,并将二维码插入到图片中央,最后将生成的图片保存为PNG格式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值