我在eclipse中使用了更新的willowgarage opencv库.我想将mat变量转换为灰度,我已经尝试了我在网上找到的所有内容,但它们并没有为我工作.
这是我的代码
package com.deneme.deneme;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView img=(ImageView) findViewById(R.id.pic);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.p26);
Mat imgToProcess=Utils.bitmapToMat(bmp);
//******
//right here I need to convert this imgToProcess to grayscale for future opencv processes
//******
Bitmap bmpOut = Bitmap.createBitmap(imgToProcess.cols(), imgToProcess.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(imgToProcess, bmpOut);
img.setImageBitmap(bmpOut);
} …Run Code Online (Sandbox Code Playgroud) 我正在寻找如何使用GDI(而不是GDI +)将32位位图转换为灰度的简单解决方案.是否有可能通过更改位图的托盘或其他东西?
当然Delphi中有很多像这样的例子,但是我正在寻找一个WinAPI函数,它可以在没有迭代的情况下完成这个.
我想用代码创建大型Bitmap
LargeBmp := TBitmap.Create;
try
LargeBmp.Width := 1000; // fine
LargeBmp.Height := 15000; // XP - EOutOfResources, Not enough memory, Win 7 - works fine
...
finally
FreeAndNil(LargeBmp);
end;
Run Code Online (Sandbox Code Playgroud)
此代码EOutOfResources在Windows XP上引发了"内存不足" 的异常,但在Windows 7中运行正常.
怎么了?为什么内存不足?它只有60 MB.
我想从文件加载一个大的位图图像,运行一个操作单个像素的函数,然后重新保存位图.
文件格式可以是PNG或BMP,操作函数很简单,例如:
if r=200,g=200,b=200 then +20 on all values, else -100 on all values
Run Code Online (Sandbox Code Playgroud)
技巧是能够加载位图并能够逐行读取每个像素
Java中是否有可以处理此I/O的标准库机制?
(位图需要几百万像素,我需要能够处理数百万像素)
我正在制作一个应用程序我最近3天无法解决一个问题google尽可能多.我在画布上制作一个圆圈并想要裁剪图像那部分并在缩放模式下显示该图像.我的第一步就像在屏幕上这样: - 
在这个我选择区域.我使用的代码就是这个.
private float x, y;
private boolean zooming = false;
private Paint mPaint;
private Matrix mmatrix;
private Shader mShader;
private Bitmap mBitmap;
private List<Point> mpoints;
private List<MyPoints> mpointlist;
private Path mpath;
private Canvas mcanvas;
private Bitmap mresult_bitmap, resultingImage,finalbitmap;
private Context mcontext;
private boolean bfirstpoint = false;
private Point mfirstpoint = null;
private Point mlastpoint = null;
public CircularZoomView(Context context) {
super(context);
mcontext = context;
mpath = new Path();
mpoints = new ArrayList<Point>();
setBackgroundResource(R.drawable.testing);
mPaint = new Paint();
mresult_bitmap …Run Code Online (Sandbox Code Playgroud) 我使用的是android 4.0.4,内核3.0.8+
BitmapFactory.decodeFile经常返回一个空位图.
请注意,如果位图工厂无法加载位图,我会立即再次尝试,最多4次,这通常有效(!)
有很多人抱怨这个.大多数问题的答案涉及位图的放置位置,或者刷新的输入流/ http连接的性质等等.我已经排除了这些 - 实际上,我已经将我的问题减少到了一个如此荒谬简单的Android应用程序,它可以被称为测试用例.
我的应用程序有一个活动,其中包含一个按钮,当按下该按钮时,会启动一个循环通过外部文件目录的线程,尝试将其中的所有内容加载到位图中.我不使用位图,或保留它,或任何东西,我只是加载并忘记:
public class MainActivity extends Activity {
private static final String TAG = "bmpbash";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onGo(View view) {
view.setVisibility(View.GONE);
start();
}
/**
* Start the thread.
*/
public void start() {
Runnable r = new Runnable() …Run Code Online (Sandbox Code Playgroud) 我目前正在直接绘制提供给我的视图的onDraw方法的Canvas对象.这个画布是硬件加速的.特别是,我使用RadialGradient着色器和OVERLAY PorterDuff模式绘制多个圆圈.但是,当我尝试将相同的绘制过程应用于我手动创建的画布时,我得不到相同的结果.我相信这是因为为位图创建的canvas对象不是硬件加速的.
对于视图,代码看起来像这样:
public class MyView extends View {
private Paint mPaint;
private List<Shader> mShaders;
public MyView(Context context) {
super(context);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.DITHER_FLAG);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.OVERLAY));
mShaders = new ArrayList<Shader>(); // assume x, y, r, and color vals are defined.
mShaders.add(new RadialGradient(x1, y1, r1, c11, c12, Shader.TileMode.CLAMP));
mShaders.add(new RadialGradient(x2, y2, r2, c21, c22, Shader.TileMode.CLAMP));
}
@Override
protected void onDraw(Canvas canvas) {
mPaint.setShader(mShaders.get(0));
canvas.drawCircle(x1, y1, r1, mPaint);
mPaint.setShader(mShaders.get(1));
canvas.drawCircle(x2, y2, r2, mPaint);
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,一切都很顺利.圆圈在硬件加速画布上按预期绘制.
但是,如果我这样做:
...
Bitmap bitmap = Bitmap.createBitmap(w, …Run Code Online (Sandbox Code Playgroud) 我想做的是从磁盘加载图像并从中创建一个BitmapSource.
图像为14043px x 9933px,为b/w(1bpp).但我碰到了一个OutOfMemoryException因为以下代码消耗大约800 MB RAM.
以下代码生成ImageSource特定文件的维度.
我这样做是为了看看我是否可以在不使用磁盘上的实际文件的情况下使其工作.
public System.Windows.Media.ImageSource getImageSource(){
int width = 14043;
int height = 9933;
List<System.Windows.Media.Color> colors = new List<System.Windows.Media.Color>();
colors.Add(System.Windows.Media.Colors.Black);
colors.Add(System.Windows.Media.Colors.White);
BitmapPalette palette = new BitmapPalette(colors);
System.Windows.Media.PixelFormat pf = System.Windows.Media.PixelFormats.Indexed1;
int stride = width / pf.BitsPerPixel;
byte[] pixels = new byte[height * stride];
for (int i = 0; i < height * stride; ++i)
{
if (i < height * stride / 2)
{
pixels[i] = 0x00;
}
else …Run Code Online (Sandbox Code Playgroud) 我有一个基于opencv用C++编写的图像处理功能.在我的wpf应用程序中,我使用AForge库来访问网络摄像头并在UI上更新它.这是处理新帧的功能.
void UI_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
try
{
System.Drawing.Bitmap bitmapFrame = (Bitmap)eventArgs.Frame.Clone();
MemoryStream ms = new MemoryStream();
bitmapFrame.Save(ms, ImageFormat.Bmp);
ms.Seek(0, SeekOrigin.Begin);
BitmapImage bitmapImageFrame = new BitmapImage();
bitmapImageFrame.BeginInit();
bitmapImageFrame.StreamSource = ms;
bitmapImageFrame.EndInit();
bitmapImageFrame.Freeze();
CurrentFrame = bitmapImageFrame;
}
catch (Exception ex)
{
Debug.WriteLine("fatal::" + ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的c ++代码:
void FaceTracker(unsigned char* imageBuffer, int width, int height){
Mat frame(Size(width, height), CV_8UC4, imageBuffer, Mat::AUTO_STEP);
Mat gray;
cvtColor(frame, gray, COLOR_BGR2GRAY);
//do more operations
}
Run Code Online (Sandbox Code Playgroud)
我有两个选择.我已经找到了一个用于将数据复制BitmapImage到IntPtr缓冲区的代码CopyPixels.我测试了它,它工作正常.但我也读过我可以简单地使用句柄传递给Bitmap GetHBitmap.但这不适合我.我读了这个 …
我想使用构建器样式大图(而不是使用自定义视图)在我的通知中显示图像.图像即将被裁剪.如何根据屏幕比例显示不同设备的正确图像?
我已经搜索过,我已经知道我们需要根据屏幕宽度缩放图像来显示通知,但是我无法实现这一点,并且对ppi,dpi和为图像提供的所有其他格式感到困惑.请任何人都可以根据屏幕大小向我提供转换位图的代码,以便在不同的设备上以适当的格式显示?