虽然我已经编程了大约11年(主要是VB6,过去6个月C#),但它是第一次真正提出问题:)我已经找到了我的所有答案来自teh interwebz但是这个问题我无法解决自己.您的网站是最有帮助的地方之一,我得到了最好的答案!
我将展示我正在使用的代码(相关内容的摘录).问题是当使用RotateFlip方法时,内存会迅速增加到~200M,然后在一段时间后由GC收集.调用它的主要方法每秒迭代大约30次,因此这里的性能至关重要.我尝试使用图形矩阵变换,但这有时会失败并显示非翻转图像.应用程序本身基于使用网络摄像头,隐藏预览,获取回调图片并在图片框中显示.然后它覆盖了另一个类上的矩形.这是使用回调而不是预览窗口的原因.
Capture.cs类:
internal Bitmap LiveImage;
int ISampleGrabberCB.BufferCB(double bufferSize, IntPtr pBuffer, int bufferLen)
{
LiveImage = new Bitmap(_width, _height, _stride, PixelFormat.Format24bppRgb, pBuffer);
if (ExpImg) // local bool, used rarely when the picture saving is triggered
{
LiveImage.RotateFlip(RotateFlipType.RotateNoneFlipY);
var a = LiveImage.Clone(new Rectangle(Currect.Left, Currect.Top, Currect.Width, Currect.Height),
LiveImage.PixelFormat);
using (a)
a.Save("ocr.bmp", ImageFormat.Bmp);
}
else // dmnit, rotateflip leaks like h*ll but matrix transform doesn't sometimes flip :S
{
LiveImage.RotateFlip(RotateFlipType.RotateNoneFlipY);
/*using (var g = Graphics.FromImage(LiveImage))
{
g.Transform = _mtx;
g.DrawImage(LiveImage, 0, 0); …Run Code Online (Sandbox Code Playgroud) 我的程序是用 C# 编写的,并在低级别上使用位图进行操作。一切工作正常,但有时(非常罕见,但稳定)会发生异常“通用 GDI+ 异常”,并且很难重现这种情况。
函数 LockBits() 和 UnLockBits() 发生异常。它包含错误代码“-2147467259”。在 GDI+ 语言中,它是方法 GdipBitmapLockBits 并返回代码 7 或 1。
什么样的原因可能会造成这样的情况呢?
任何答案都非常感激。
我正在尝试逐像素显示位图图像(这明确意味着有一些延迟)。
为此,我使用两个“for 循环”,但它只打印单行像素......
我的代码:
Button start = (Button) findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(getBaseContext(), "Printing...", Toast.LENGTH_SHORT).show();
iImageArray = new int[bMap.getWidth()* bMap.getHeight()]; //initializing the array for the image size
bMap.getPixels(iImageArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight()); //copy pixel data from the Bitmap into the 'intArray' array
//Canvas canvas = new Canvas (bMap);
//replace the red pixels with yellow ones
for (int i=0; i < bMap.getHeight(); i++) {
for(int j=0; j<bMap.getWidth(); j++) {
iImageArray[j] = 0xFFFFFFFF;
} …Run Code Online (Sandbox Code Playgroud) 我有一个imageview
<ImageView
android:id="@+id/imgCaptured"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/captured_image" />
Run Code Online (Sandbox Code Playgroud)
我从相机捕获图像,将该图像转换为位图.
Bitmap thumbnail;
thumbnail = MediaStore.Images.Media.getBitmap(getActivity()
.getContentResolver(), imageUri);
Run Code Online (Sandbox Code Playgroud)
当我在上面的imageview中显示它之前得到这个位图的分辨率,比如
Log.i("ImageWidth = " + thumbnail.getWidth(), "ImageHeight = "
+ thumbnail.getHeight());
Run Code Online (Sandbox Code Playgroud)
它归还了我 ImageWidth = 2592 ImageHeight = 1936
在此之后我在上面的imageview中显示了这个位图,imgCaptured.setImageBitmap(thumbnail); 然后我将我的imageview的大小视为
Log.i("ImageView Width = " + imgCaptured.getWidth(),
"ImageView Height = " + imgCaptured.getHeight());
Run Code Online (Sandbox Code Playgroud)
这让我回头 ImageView Width = 480 ImageView Height = 720
现在我的问题是
在我的imageview中显示后,如何获得该位图的大小.我知道这可以通过使用它来完成
image.buildDrawingCache();
Bitmap bmap = image.getDrawingCache();
Run Code Online (Sandbox Code Playgroud)
但这会创建一个大小等于imageview的新位图.
我还想知道,在imageview中显示后,图像会自动调整大小.如果是,那么有没有办法在imageview中显示图像而不调整图像大小.
编辑
实际上我已经拍摄了2592x1936的图像.我在imageView中显示了这个图像,对此图像做了一些其他操作.现在我想以相同的2592x1936分辨率保存此图像.可能吗?
提前致谢.
我有以下代码来创建位图:
//raw data
PBYTE firstPixel = (PBYTE)((PBYTE)AnsiBdbRecord) + sizeof(WINBIO_BDB_ANSI_381_RECORD);
// declare other bmp structures
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER info;
RGBQUAD rq[256];
// create the grayscale palette
for (int i = 0; i<256; i++)
{
rq[i].rgbBlue = i;
rq[i].rgbGreen = i;
rq[i].rgbRed = i;
rq[i].rgbReserved = 0;
}
//RGBQUAD bl = { 0,0,0,0 }; //black color
//RGBQUAD wh = { 0xff,0xff,0xff,0xff }; // white color
// andinitialize them to zero
memset(&bmfh, 0, sizeof(BITMAPFILEHEADER));
memset(&info, 0, sizeof(BITMAPINFOHEADER));
// fill the fileheader with data …Run Code Online (Sandbox Code Playgroud) 我在画布上画了一些东西,我想将此图作为 jpeg 图像保存在我的存储中。我使用以下方法,它将图像sign.jpg保存在我的目录中,但它保存空白黑色图像,没有在其上绘制任何内容,其大小为14.49kb。
这是方法
public Bitmap savebit(){
Bitmap saveBitmap = Bitmap.createBitmap(this.getWidth(), this.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(saveBitmap);
canvas.setBitmap(saveBitmap);
this.draw(canvas);
File file = new File(Environment.getExternalStorageDirectory() + "/sign.jpg");
try {
saveBitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(file));
} catch (Exception e) {
e.printStackTrace();
}
return saveBitmap;
}
Run Code Online (Sandbox Code Playgroud) 我的项目是
\n\n我对 1) 和 3) 没有问题,但我可以 \xe2\x80\x99t 找到一种将文本添加到位图图形上下文的方法。我花了很多时间阅读一些帖子,但没有成功。\n文档(https://developer.apple.com/reference/coregraphics/cgcontext/1586505-showtextatpoint)说我应该考虑核心文本,但我\n不知道如何应该使用 Core Text 将一些文本添加到我的\n位图上下文中。我还读到 NSString 的绘制实例方法允许\n在当前图形上下文中写入文本,但据我所知当前\n图形上下文与我的位图图形上下文无关?
\n\n需要明确的是,我对在屏幕上绘制文本不感兴趣,我感兴趣的是在位图中绘制文本并将该位图保存在文件中。
\n\nlet colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()\n// Create the bitmap graphic context\nvar gc = CGContext(data: nil, width: 400, height: 400, bitsPerComponent: 8, bytesPerRow: 0,\n space: colorSpace, bitmapInfo: CGImageAlphaInfo.noneSkipFirst.rawValue)\n\n// draw an image (croppedCGImage is a CGImage instance)\nvar rect = CGRect(x: 0, y:0, width:200, height: 200)\ngc?.draw(croppedCGImage, in: rect)\n\n// draw some text ????\n// how to do that …Run Code Online (Sandbox Code Playgroud) 首先问一个问题:在ImageReader知道我总是将捕获转换为 的情况下,初始化和使用camera2 api 的最有效方法是什么Bitmap?
我正在尝试 Android Camera2 示例,一切都运行得很好。然而,出于我的目的,我总是需要对捕获的静态图像执行一些后期处理,为此我需要一个Bitmap对象。目前我正在使用来自(我正在解释)的BitmapFactory.decodeByteArray(...)字节。ImageReader.acquireNextImage().getPlanes()[0].getBuffer()虽然这可以接受,但我仍然觉得应该有一种方法可以提高性能。捕获的内容被编码ImageFormat.Jpeg,需要再次解码才能得到Bitmap,这似乎是多余的。理想情况下,我会获取它们PixelFormat.RGB_888并使用将其复制到位图Bitmap.copyPixelsFromBuffer(...),但使用该格式初始化似乎并不ImageReader具有可靠的设备支持。YUV_420_888可能是另一种选择,但环顾四周,似乎需要跳过一些环节才能解码为Bitmap. 有推荐的方法吗?
我正在使用 Flutter 创建一个新应用程序,并希望在初始启动屏幕上添加自定义图像。
图像出现在初始屏幕上,但在大约半秒钟内它似乎被拉伸,看起来不太好。
我一直在寻找,但一直在努力寻找有同样问题的人。
有任何想法吗?
我曾尝试使用 mipmap 提供可变大小的图像,但产生相同的结果。
launch_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/green" />
<item>
<bitmap
android:gravity="center_horizontal"
android:src="@drawable/ic_logo"
android:tileMode="disabled"/>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
样式文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<color name="green">#b7dd05</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flutter_app">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or …Run Code Online (Sandbox Code Playgroud) 我必须使用 Java将com.google.mlkit.vision.common.InputImage转换为 android 中的等效位图图像。现在我正在使用以下代码。
// iImage is an object of InputImage
Bitmap bmap = Bitmap.createBitmap(iImage.getWidth(), iImage.getHeight(), Bitmap.Config.RGB_565);
bmap.copyPixelsFromBuffer(iImage.getByteBuffer());
Run Code Online (Sandbox Code Playgroud)
上面的代码没有将 InputImage 转换为 Bitmap。任何人都可以建议我将 InputImage 转换为 Bitmap 的有效方法。