我创建了一个使用套接字的应用程序,客户端在其中接收图像并将图像数据存储在Bitmap类中....
任何人都可以告诉我如何从这个Bitmap对象创建一个名为myimage.png或myimage.bmp的文件
String base64Code = dataInputStream.readUTF();
byte[] decodedString = null;
decodedString = Base64.decode(base64Code);
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0,decodedString.length);
Run Code Online (Sandbox Code Playgroud) 只是一个我无法找到任何细节的快速问题:我正在使用python win32api捕获我的计算机的屏幕截图.我想推出自己的图像压缩算法(为了好玩,我不希望专业级别的结果),但我很难理解我从位图本身获得的像素数据.这是相关代码:
width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)
hwin = win32gui.GetDesktopWindow()
hwindc = win32gui.GetWindowDC(hwin)
srcdc = win32ui.CreateDCFromHandle(hwindc)
memdc = srcdc.CreateCompatibleDC()
bmp = win32ui.CreateBitmap()
bmp.CreateCompatibleBitmap(srcdc, width, height)
memdc.SelectObject(bmp)
memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)
bmpinfo = bmp.GetInfo()
bmpInt = bmp.GetBitmapBits(False)
Run Code Online (Sandbox Code Playgroud)
GetBitmapBits(False)返回一个整数数组/元组.但我找不到有关bmpInt如何与像素数据相关的任何信息.输出如下所示:
123,1,-1,-13,-55,2,23,123 ...
Run Code Online (Sandbox Code Playgroud)
这些如何与每个像素的RGB值相对应?每3个像素一个像素?还是有alpha通道?另外,为什么有负数?供参考,这里是文档:http://docs.activestate.com/activepython/2.4/pywin32/PyCBitmap__GetBitmapBits_meth.html 那里没有解释......
我有一个关于Android中位图的问题:我有一个带有白色边距[大小未知]的位图.是否可以创建一个删除了所有白色边距的新位图(矩形)?
Bitmap bmp = Bitmap.createBitmap(width, bmpheigth, Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
canvas.setBitmap(bmp);
canvas.drawColor(Color.WHITE);
// draw here things!
Run Code Online (Sandbox Code Playgroud)
人们认为不知道绘画的地方.
有什么好办法呢?谢谢!
我正在使用以下答案中的代码来设置上传图像的缩略图.
这完美地工作并填充图像,保持纵横比等但如果我从我的手机上传图像,从这种方法保存的缩略图图像旋转ccw 90度.
你知道是什么原因造成的吗?使用AjaxFileUpload1.SaveAs(MapPath("〜/ catalog/images /"&imageFilename))(来自AJAX控件工具包)保存原始图像,并以正确的方向显示.
谢谢
我正在寻找的是一个以顺时针方式显示图像的视图.当进度为25%时,应显示前90度,当其100%时,应绘制全部360度.
它非常接近使用canvas.drawArc(),但此方法仅适用于Paint对象,而不适用于位图.
其他答案也只适用于全彩色: 如何在Android中制作圆形自定义进度条
我发现这是一个非常难的问题,我希望有人有解决方案.
我正在开发一个Android应用程序,它将图像从相机或设备照片库上传到远程站点.后者我工作正常,我可以选择并上传.但是,我无法拍摄完整尺寸的图片并上传.这是我的代码:
// From onCreate
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
Run Code Online (Sandbox Code Playgroud)
我有一个方法来处理Activity结果.这两个都处理从图库和相机中选择:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
String filepath = "";
Uri selectedImageUri;
if (resultCode == RESULT_OK) {
if (requestCode == CAMERA_PIC_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
// Gets real path of image so it can be uploaded
selectedImageUri = getImageUri(getApplicationContext(), photo);
}
else {
selectedImageUri = data.getData();
}
// Handle the upload ...
}
}
public Uri getImageUri(Context inContext, Bitmap inImage) {
String path …Run Code Online (Sandbox Code Playgroud) 我找到了很多圆角的样本代码.我需要的是圆形图像.我发现这个没问题,但输出不是完美的圆形.
ImageView im = (ImageView) findViewById(R.id.imag);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.white);
Bitmap circleBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP);
Paint paint = new Paint();
paint.setShader(shader);
Canvas c = new Canvas(circleBitmap);
c.drawCircle(bmp.getWidth() / 2, bmp.getHeight() / 2, bmp.getWidth() / 2, paint);
im.setImageBitmap(circleBitmap);
Run Code Online (Sandbox Code Playgroud) 我有一个Kinect传感器的视频输入,该传感器由存储为位图的图像托管.我的问题是如何将图像叠加.png到视频输入上.
视频输入显示如下图所示为位图源,我知道如何在位图上绘制一条线但是如何从资源中绘制图像呢?
KinectVideo.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96,
PixelFormats.Bgr32, null, colorData, colorFrame.Width * colorFrame.BytesPerPixel);
Run Code Online (Sandbox Code Playgroud)
下面是通过将图像放在视频源上来模拟我想要实现的目标:

更新了绘图方法的实现,我不认为这是正确的实现我在添加图像路径时得到无效的参数错误.DrawImage:
void myKinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (colorFrame == null) return;
byte[] colorData = new byte[colorFrame.PixelDataLength];
colorFrame.CopyPixelDataTo(colorData);
KinectVideo.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96,
PixelFormats.Bgr32, null, colorData, colorFrame.Width * colorFrame.BytesPerPixel);
Rect destRect2;
//drawing image overlay to video feed
var drawingVisual = new DrawingVisual();
var drawingContext = drawingVisual.RenderOpen();
drawingContext.DrawImage(BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, colorData, colorFrame.Width …Run Code Online (Sandbox Code Playgroud) 我试图从http响应中获取图像,但无法将流转换为位图.请让我知道,我在这里失踪了什么.
仅供参考 - 图像内容作为原始二进制文件及其jpeg图像接收.
程序如下:
在postExecute的AsyncTask中执行此操作
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(endpoint);
// Adding Headers ..
// Execute the request
HttpResponse response;
try {
response = httpclient.execute(httpget);
if (response.getStatusLine().getStatusCode() == 200) {
// Get hold of the response entity
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
return instream;
// instream.close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在postExecute的AsyncTask中执行此操作
if (null != instream) {
Bitmap bm = BitmapFactory.decodeStream(instream);
if(null …Run Code Online (Sandbox Code Playgroud) 我有一个Image Uri,使用以下方法检索:
public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
Run Code Online (Sandbox Code Playgroud)
这对于需要图像URI等的Intent来说非常有用(所以我确定URI是有效的).
但现在我想将此Image URI保存到SDCARD上的文件中.这更加困难,因为URI并没有真正指向SDCARD或应用程序上的文件.
我是否必须首先从URI创建位图,然后将位图保存在SDCARD上,或者是否有更快的方法(最好是不需要先转换为位图的方法).
(我已经看过这个答案了,但它找不到找到的文件 - /sf/answers/919378211/)